git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@gmail.com>
To: "Karl Hasselström" <kha@treskal.com>
Cc: git@vger.kernel.org
Subject: Re: [StGit PATCH] Check for local changes with "goto"
Date: Fri, 30 Jan 2009 14:01:20 +0000	[thread overview]
Message-ID: <b0943d9e0901300601j27ab6ebdq4b38a9f7c0cbe261@mail.gmail.com> (raw)
In-Reply-To: <20090129034512.GD24344@diana.vm.bytemark.co.uk>

2009/1/29 Karl Hasselström <kha@treskal.com>:
> On 2009-01-28 23:13:05 +0000, Catalin Marinas wrote:
>> +        # Check for not clean index
>> +        if check_clean and iw and not iw.index.is_clean():
>> +            self.__halt('Repository not clean. Use "refresh" or '
>> +                        '"status --reset"')
>
> ... this, which doesn't do what I think you think it does.
>
> Index.is_clean() calls "git update-index --refresh", which checks for
> changes in the worktree relative to the index. It's bad design to have
> it in Index rather than IndexAndWorktree, but that's my fault, not
> yours. ;-) But the point that breaks your patch is that it doesn't
> check for changes between index and HEAD -- try it and see.
>
> The fix I'd suggest is to move the existing is_clean() method to
> IndexAndWorktree, and call it maybe worktree_clean(). And create a
> method in Index() called is_clean(tree) that checks whether the index
> is clean with respect to the given Tree (I think this method should
> just call "git diff-index --quiet --cached <tree>".). Then call both
> of these methods.

What about this (only pasting the relevant hunks, though they may be
wrapped by the web interface):

diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index e2b4266..7e1b9dd 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -706,9 +706,15 @@ class Index(RunWithEnv):
                     ).output_one_line())
         except run.RunException:
             raise MergeException('Conflicting merge')
-    def is_clean(self):
+    def is_clean(self, tree = None):
+        """Check whether the index is clean relative to the given tree."""
+        if tree:
+            sha1 = tree.sha1
+        else:
+            sha1 = 'HEAD'
         try:
-            self.run(['git', 'update-index', '--refresh']).discard_output()
+            self.run(['git', 'diff-index', '--quiet', '--cached', sha1]
+                    ).discard_output()
         except run.RunException:
             return False
         else:
@@ -858,6 +864,15 @@ class IndexAndWorktree(RunWithEnvCwd):
         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 and no updates or
+        merges are needed."""
+        try:
+            self.run(['git', 'update-index', '--refresh']).discard_output()
+        except run.RunException:
+            return False
+        else:
+            return True

 class Branch(object):
     """Represents a Git branch."""
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 54de127..8abf296 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -183,13 +183,22 @@ class StackTransaction(object):
             self.__checkout(self.__stack.head.data.tree, iw,
                             allow_bad_head = True)
     def run(self, iw = None, set_head = True, allow_bad_head = False,
-            print_current_patch = True):
+            print_current_patch = True, check_clean = False):
         """Execute the transaction. Will either succeed, or fail (with an
         exception) and do nothing."""
         self.__check_consistency()
         log.log_external_mods(self.__stack)
         new_head = self.head

+        # Check for not clean index and worktree
+        if check_clean and iw:
+            if not iw.worktree_clean():
+                self.__halt('Repository not clean. Use "refresh" or '
+                            '"status --reset"')
+            elif not iw.index.is_clean()):
+                self.__halt('Index and HEAD different. Use "repair" to '
+                            'recover additional commits')
+
         # Set branch head.
         if set_head:
             if iw:


Thanks.

-- 
Catalin

  reply	other threads:[~2009-01-30 14:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-28 23:13 [StGit PATCH] Check for local changes with "goto" Catalin Marinas
2009-01-29  3:45 ` Karl Hasselström
2009-01-30 14:01   ` Catalin Marinas [this message]
2009-01-30 15:26     ` Karl Hasselström
2009-01-30 17:36       ` Catalin Marinas
2009-02-06 14:46         ` Catalin Marinas
2009-02-06 15:31           ` Karl Hasselström
2009-02-06 18:39             ` Catalin Marinas
  -- strict thread matches above, loose matches on Subject: below --
2009-02-10 14:11 Catalin Marinas
2009-02-11  9:05 ` Karl Hasselström
2009-01-14 22:59 Catalin Marinas
2009-01-15  8:37 ` Karl Hasselström
2009-01-15 22:24   ` Catalin Marinas

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=b0943d9e0901300601j27ab6ebdq4b38a9f7c0cbe261@mail.gmail.com \
    --to=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kha@treskal.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).