Add --keep option to pop
authorCatalin Marinas <catalin.marinas@gmail.com>
Sun, 10 Sep 2006 13:58:54 +0000 (14:58 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Sun, 10 Sep 2006 13:58:54 +0000 (14:58 +0100)
This option allows popping patches without affecting the working directory.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/common.py
stgit/commands/pop.py
stgit/git.py
stgit/stack.py

index b8ea3bb..a073b29 100644 (file)
@@ -194,7 +194,7 @@ def push_patches(patches, check_merged = False):
             else:
                 print 'done'
 
-def pop_patches(patches):
+def pop_patches(patches, keep = False):
     """Pop the patches in the list from the stack. It is assumed that
     the patches are listed in the stack reverse order.
     """
@@ -205,7 +205,7 @@ def pop_patches(patches):
         print 'Popping "%s" - "%s" patches...' % (patches[0], p),
     sys.stdout.flush()
 
-    crt_series.pop_patch(p)
+    crt_series.pop_patch(p, keep)
 
     print 'done'
 
index 23aeeb3..7c260a6 100644 (file)
@@ -36,7 +36,10 @@ options = [make_option('-a', '--all',
                        help = 'pop all the applied patches',
                        action = 'store_true'),
            make_option('-n', '--number', type = 'int',
-                       help = 'pop the specified number of patches')]
+                       help = 'pop the specified number of patches'),
+           make_option('--keep',
+                       help = 'keep the current working directory',
+                       action = 'store_true')]
 
 
 def func(parser, options, args):
@@ -45,9 +48,10 @@ def func(parser, options, args):
     if len(args) > 1:
         parser.error('incorrect number of arguments')
 
-    check_local_changes()
-    check_conflicts()
-    check_head_top_equal()
+    if not options.keep:
+        check_local_changes()
+        check_conflicts()
+        check_head_top_equal()
 
     applied = crt_series.get_applied()
     if not applied:
@@ -74,6 +78,6 @@ def func(parser, options, args):
     if patches == []:
         raise CmdException, 'No patches to pop'
 
-    pop_patches(patches)
+    pop_patches(patches, options.keep)
 
     print_crt_patch()
index 2399996..907c82d 100644 (file)
@@ -644,12 +644,13 @@ def checkout(files = None, tree_id = None, force = False):
     if __run(checkout_cmd, files) != 0:
         raise GitException, 'Failed git-checkout-index'
 
-def switch(tree_id):
+def switch(tree_id, keep = False):
     """Switch the tree to the given id
     """
-    refresh_index()
-    if __run('git-read-tree -u -m', [get_head(), tree_id]) != 0:
-        raise GitException, 'git-read-tree failed (local changes maybe?)'
+    if not keep:
+        refresh_index()
+        if __run('git-read-tree -u -m', [get_head(), tree_id]) != 0:
+            raise GitException, 'git-read-tree failed (local changes maybe?)'
 
     __set_head(tree_id)
 
index 618182c..c1071b5 100644 (file)
@@ -925,7 +925,7 @@ class Series:
         self.pop_patch(name)
         return patch.restore_old_boundaries()
 
-    def pop_patch(self, name):
+    def pop_patch(self, name, keep = False):
         """Pops the top patch from the stack
         """
         applied = self.get_applied()
@@ -934,7 +934,7 @@ class Series:
 
         patch = Patch(name, self.__patch_dir, self.__refs_dir)
 
-        git.switch(patch.get_bottom())
+        git.switch(patch.get_bottom(), keep)
 
         # save the new applied list
         idx = applied.index(name) + 1