From a639e7bbf3a6396254af76062ee88c22e4373340 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Karl=20Hasselstr=C3=B6m?= Date: Sun, 27 Jan 2008 07:48:02 +0100 Subject: [PATCH] Don't clean away patches with conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If we have conflicts, it means that the topmost patch is empty because of those conflicts (since StGit explicitly makes a conflicting patch empty), so don't let "stg clean" touch it. Signed-off-by: Karl Hasselström --- stgit/commands/clean.py | 7 +++++++ stgit/lib/git.py | 8 ++++++++ t/t2500-clean.sh | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/stgit/commands/clean.py b/stgit/commands/clean.py index a0a0dca..889c1dc 100644 --- a/stgit/commands/clean.py +++ b/stgit/commands/clean.py @@ -40,6 +40,13 @@ def _clean(stack, clean_applied, clean_unapplied): 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() diff --git a/stgit/lib/git.py b/stgit/lib/git.py index 2af1844..6cd7450 100644 --- a/stgit/lib/git.py +++ b/stgit/lib/git.py @@ -353,6 +353,14 @@ class Index(RunWithEnv): 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): diff --git a/t/t2500-clean.sh b/t/t2500-clean.sh index b38d868..ad8f892 100755 --- a/t/t2500-clean.sh +++ b/t/t2500-clean.sh @@ -35,7 +35,7 @@ test_expect_success 'Create a conflict' ' ! 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))" = "" ] -- 2.11.0