From: Catalin Marinas Date: Sun, 10 Sep 2006 13:58:54 +0000 (+0100) Subject: Add --keep option to pop X-Git-Tag: v0.14.3~467 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/f46f4413587c2941a555aa6014c3e306bbd67fd6 Add --keep option to pop This option allows popping patches without affecting the working directory. Signed-off-by: Catalin Marinas --- diff --git a/stgit/commands/common.py b/stgit/commands/common.py index b8ea3bb..a073b29 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -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' diff --git a/stgit/commands/pop.py b/stgit/commands/pop.py index 23aeeb3..7c260a6 100644 --- a/stgit/commands/pop.py +++ b/stgit/commands/pop.py @@ -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() diff --git a/stgit/git.py b/stgit/git.py index 2399996..907c82d 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -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) diff --git a/stgit/stack.py b/stgit/stack.py index 618182c..c1071b5 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -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