All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH 2/2] Don't clean away patches with conflicts
Date: Tue, 29 Jan 2008 04:12:44 +0100	[thread overview]
Message-ID: <20080129031118.1095.79802.stgit@yoghurt> (raw)
In-Reply-To: <20080129030752.1095.27968.stgit@yoghurt>

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 <kha@treskal.com>

---

I considered fixing this by way of a check in the shared
new-infrastructure code, but came to the conclusion that the check
really does belong in "stg clean".

 stgit/commands/clean.py |    7 +++++++
 stgit/lib/git.py        |    8 ++++++++
 t/t2500-clean.sh        |    2 +-
 3 files changed, 16 insertions(+), 1 deletions(-)


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))" = "" ]

  parent reply	other threads:[~2008-01-29  3:13 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-29  2:58 kha/safe and kha/experimental updated Karl Hasselström
2008-01-29  3:02 ` [StGit PATCH 0/5] Various cleanups Karl Hasselström
2008-01-29  3:02   ` [StGit PATCH 1/5] Create index and worktree objects just once Karl Hasselström
2008-01-29  3:03   ` [StGit PATCH 2/5] Wrap excessively long line Karl Hasselström
2008-01-29  3:03   ` [StGit PATCH 3/5] Eliminate temp variable that's used just once Karl Hasselström
2008-01-29  3:04   ` [StGit PATCH 4/5] Simplify editor selection logic Karl Hasselström
2008-01-29 20:09     ` Peter Oberndorfer
2008-01-30  7:28       ` Karl Hasselström
2008-01-30 14:55         ` Jay Soffian
2008-01-30 17:57           ` Karl Hasselström
2008-01-29  3:06   ` [StGit PATCH 5/5] Let the caller supply the diff text to diffstat() Karl Hasselström
2008-01-29  3:10 ` [StGit PATCH 0/2] "stg clean" test+bugfix Karl Hasselström
2008-01-29  3:11   ` [StGit PATCH 1/2] Add test to ensure that "stg clean" preserves conflicting patches Karl Hasselström
2008-01-29  3:12   ` Karl Hasselström [this message]
2008-01-29  3:15 ` [StGit PATCH 0/4] Rewrite "stg edit" to use new infrastructure Karl Hasselström
2008-01-29  3:15   ` [StGit PATCH 1/4] Teach new infrastructure about the default author and committer Karl Hasselström
2008-01-29  3:15   ` [StGit PATCH 2/4] Teach new infrastructure to apply patches Karl Hasselström
2008-01-29  3:16   ` [StGit PATCH 3/4] Teach new infrastructure to diff two trees Karl Hasselström
2008-01-29 14:40     ` David Kågedal
2008-01-29 15:57       ` Karl Hasselström
2008-01-29  3:17   ` [StGit PATCH 4/4] Convert "stg edit" to the new infrastructure Karl Hasselström
2008-02-01  7:49   ` [StGit PATCH 0/3] "stg edit" fixups Karl Hasselström
2008-02-01  7:50     ` [StGit PATCH 1/3] Parse the date instead of treating it as an opaque string Karl Hasselström
2008-02-01  7:50     ` [StGit PATCH 2/3] Convert "stg edit" to the new infrastructure Karl Hasselström
2008-02-01  7:50     ` [StGit PATCH 3/3] It's possible to edit unapplied patches now Karl Hasselström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080129031118.1095.79802.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.