Specifically, if the push failed because of a merge conflict, the
patch should be applied but empty; and if it fails for any other
reason (such as a too-dirty worktree), the patch should not be
applied.
This fixes the data loss bug tested for by t3000.
Signed-off-by: Karl Hasselström <kha@treskal.com>
class MergeException(exception.StgException):
pass
class MergeException(exception.StgException):
pass
+class MergeConflictException(MergeException):
+ pass
+
class Index(RunWithEnv):
def __init__(self, repository, filename):
self.__repository = repository
class Index(RunWithEnv):
def __init__(self, repository, filename):
self.__repository = repository
assert isinstance(ours, Tree)
assert isinstance(theirs, Tree)
try:
assert isinstance(ours, Tree)
assert isinstance(theirs, Tree)
try:
- self.run(['git', 'merge-recursive', base.sha1, '--', ours.sha1,
- theirs.sha1],
- env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
- 'GITHEAD_%s' % ours.sha1: 'current',
- 'GITHEAD_%s' % theirs.sha1: 'patched'}
- ).cwd(self.__worktree.directory).discard_output()
+ r = self.run(['git', 'merge-recursive', base.sha1, '--', ours.sha1,
+ theirs.sha1],
+ env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
+ 'GITHEAD_%s' % ours.sha1: 'current',
+ 'GITHEAD_%s' % theirs.sha1: 'patched'}
+ ).cwd(self.__worktree.directory)
+ r.discard_output()
except run.RunException, e:
except run.RunException, e:
- raise MergeException('Index/worktree dirty')
+ 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):
def changed_files(self):
return self.run(['git', 'diff-files', '--name-only']).output_lines()
def update_index(self, files):
tree = iw.index.write_tree()
self.__current_tree = tree
s = ' (modified)'
tree = iw.index.write_tree()
self.__current_tree = tree
s = ' (modified)'
- except git.MergeException:
+ except git.MergeConflictException:
tree = ours
merge_conflict = True
s = ' (conflict)'
tree = ours
merge_conflict = True
s = ' (conflict)'
+ except git.MergeException, e:
+ self.__halt(str(e))
cd = cd.set_tree(tree)
self.patches[pn] = self.__stack.repository.commit(cd)
del self.unapplied[self.unapplied.index(pn)]
cd = cd.set_tree(tree)
self.patches[pn] = self.__stack.repository.commit(cd)
del self.unapplied[self.unapplied.index(pn)]
-test_expect_failure 'Push with dirty worktree' '
+test_expect_success 'Push with dirty worktree' '
echo 4 > a &&
[ "$(echo $(stg applied))" = "p1" ] &&
[ "$(echo $(stg unapplied))" = "p2" ] &&
echo 4 > a &&
[ "$(echo $(stg applied))" = "p1" ] &&
[ "$(echo $(stg unapplied))" = "p2" ] &&