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, 6 Feb 2009 14:46:19 +0000	[thread overview]
Message-ID: <b0943d9e0902060646hd779681x821e74d9a155d97b@mail.gmail.com> (raw)
In-Reply-To: <b0943d9e0901300936t4a6e0a37x1968a6949fb7bdda@mail.gmail.com>

2009/1/30 Catalin Marinas <catalin.marinas@gmail.com>:
> Now, should we add the check_clean argument to Transaction.__init__()
> rather than run() as we do for the allow_bad_head case?

It looks like this may be a better option. The previous patch fails if
"goto" pushes a patch with standard git-apply followed by another
patch with a three-way merge. When Transaction.run() is called, even
if the patch pushing succeeded, the function complains about local
changes because of the "iw.index.is_clean(self.stack.head)" check.

It is also a bit weird to push/pop patches and only complain at the
end of local changes. Below is an updated patch which does the
checking in Transaction.__init__ (only the relevant parts of the
patch):

diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index e2b4266..07079b8 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -706,9 +706,11 @@ class Index(RunWithEnv):
                     ).output_one_line())
         except run.RunException:
             raise MergeException('Conflicting merge')
-    def is_clean(self):
+    def is_clean(self, tree):
+        """Check whether the index is clean relative to the given treeish."""
         try:
-            self.run(['git', 'update-index', '--refresh']).discard_output()
+            self.run(['git', 'diff-index', '--quiet', '--cached', tree.sha1]
+                    ).discard_output()
         except run.RunException:
             return False
         else:
@@ -858,6 +860,14 @@ 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 to index."""
+        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..e1bd38d 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -75,7 +75,8 @@ class StackTransaction(object):
       your refs and index+worktree, or fail without having done
       anything."""
     def __init__(self, stack, msg, discard_changes = False,
-                 allow_conflicts = False, allow_bad_head = False):
+                 allow_conflicts = False, allow_bad_head = False,
+                 check_clean = False):
         """Create a new L{StackTransaction}.

         @param discard_changes: Discard any changes in index+worktree
@@ -102,6 +103,8 @@ class StackTransaction(object):
         self.__temp_index = self.temp_index_tree = None
         if not allow_bad_head:
             self.__assert_head_top_equal()
+        if check_clean:
+            self.__assert_index_worktree_clean()
     stack = property(lambda self: self.__stack)
     patches = property(lambda self: self.__patches)
     def __set_applied(self, val):
@@ -147,6 +150,12 @@ class StackTransaction(object):
                 'This can happen if you modify a branch with git.',
                 '"stg repair --help" explains more about what to do next.')
             self.__abort()
+    def __assert_index_worktree_clean(self):
+        iw = self.__stack.repository.default_iw
+        if not iw.worktree_clean() or \
+           not iw.index.is_clean(self.stack.head):
+            self.__halt('Repository not clean. Use "refresh" or '
+                        '"status --reset"')
     def __checkout(self, tree, iw, allow_bad_head):
         if not allow_bad_head:
             self.__assert_head_top_equal()


-- 
Catalin

  reply	other threads:[~2009-02-06 14:47 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
2009-01-30 15:26     ` Karl Hasselström
2009-01-30 17:36       ` Catalin Marinas
2009-02-06 14:46         ` Catalin Marinas [this message]
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=b0943d9e0902060646hd779681x821e74d9a155d97b@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).