- if r.exitcode == 1:
- raise MergeConflictException()
- else:
- raise MergeException('Index/worktree dirty')
- def changed_files(self):
- return self.run(['git', 'diff-files', '--name-only']).output_lines()
- def update_index(self, files):
- self.run(['git', 'update-index', '--remove', '-z', '--stdin']
- ).input_nulterm(files).discard_output()
+ raise MergeException('Index/worktree dirty')
+ def changed_files(self, tree, pathlimits = []):
+ """Return the set of files in the worktree that have changed with
+ respect to C{tree}. The listing is optionally restricted to
+ those files that match any of the path limiters given.
+
+ The path limiters are relative to the current working
+ directory; the returned file names are relative to the
+ repository root."""
+ assert isinstance(tree, Tree)
+ return set(self.run_in_cwd(
+ ['git', 'diff-index', tree.sha1, '--name-only', '-z', '--']
+ + list(pathlimits)).raw_output().split('\0')[:-1])
+ def update_index(self, paths):
+ """Update the index with files from the worktree. C{paths} is an
+ iterable of paths relative to the root of the repository."""
+ cmd = ['git', 'update-index', '--remove']
+ self.run(cmd + ['-z', '--stdin']
+ ).input_nulterm(paths).discard_output()
+ def worktree_clean(self):
+ """Check whether the worktree is clean relative to index."""
+ try:
+ self.run(['git', 'update-index', '--refresh']).discard_output()
+ except run.RunException:
+ return False
+ else:
+ return True