Re: [StGit PATCH] Check for local changes with "goto"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/1/30 Karl Hasselström <kha@xxxxxxxxxxx>:
> On 2009-01-30 14:01:20 +0000, Catalin Marinas wrote:
>
>> @@ -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:
>
> OK (though I personally would have allowed only Tree objects, with no
> defaulting to the current HEAD).

Done.

See below for an update. I added an __assert_index_worktree_clean()
function in Transaction.

Now, should we add the check_clean argument to Transaction.__init__()
rather than run() as we do for the allow_bad_head case? The check
would need to be done in run() where we have an iw. Just a thought,
I'm not convinced it is better.


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..c961222 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -147,6 +147,11 @@ 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):
+        if not iw.worktree_clean() or \
+           not iw.index.is_clean(self.stack.head.data.tree):
+            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()
@@ -183,13 +188,17 @@ 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 clean index and worktree
+        if check_clean and iw:
+            self.__assert_index_worktree_clean(iw)
+
         # Set branch head.
         if set_head:
             if iw:


-- 
Catalin
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux