trans = transaction.StackTransaction(stack, 'stg clean')
def del_patch(pn):
if pn in stack.patchorder.applied:
+ if pn == stack.patchorder.applied[-1]:
+ # We're about to clean away the topmost patch. Don't
+ # do that if we have conflicts, since that means the
+ # patch is only empty because the conflicts have made
+ # us dump its contents into the index and worktree.
+ if stack.repository.default_index.conflicts():
+ return False
return clean_applied and trans.patches[pn].data.is_nochange()
elif pn in stack.patchorder.unapplied:
return clean_unapplied and trans.patches[pn].data.is_nochange()
def delete(self):
if os.path.isfile(self.__filename):
os.remove(self.__filename)
+ def conflicts(self):
+ """The set of conflicting paths."""
+ paths = set()
+ for line in self.run(['git', 'ls-files', '-z', '--unmerged']
+ ).raw_output().split('\0')[:-1]:
+ stat, path = line.split('\t', 1)
+ paths.add(path)
+ return paths
class Worktree(object):
def __init__(self, directory):
! stg push
'
-test_expect_failure 'Make sure conflicting patches are preserved' '
+test_expect_success 'Make sure conflicting patches are preserved' '
stg clean &&
[ "$(echo $(stg applied))" = "p0 p2 p1" ] &&
[ "$(echo $(stg unapplied))" = "" ]