aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStepan Koltsov <stepan.koltsov@jetbrains.com>2012-01-17 22:51:19 +0400
committerCatalin Marinas <catalin.marinas@gmail.com>2012-01-18 10:52:14 +0000
commit60c49d0be075292ffadffd21069f23d01a7c5ac1 (patch)
tree7eeaedc9bc9eb25417e1060354e1f65cb1418724
parent982de08a1bce1c2e600eda7a50155418eecfb95a (diff)
downloadstgit-60c49d0be075292ffadffd21069f23d01a7c5ac1.tar.gz
stg delete --top
shortcut for: stg delete `stg top` Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
-rw-r--r--stgit/commands/delete.py14
-rwxr-xr-xt/t1600-delete-one.sh14
2 files changed, 25 insertions, 3 deletions
diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py
index b656a87..84a057e 100644
--- a/stgit/commands/delete.py
+++ b/stgit/commands/delete.py
@@ -38,7 +38,9 @@ options = [
worktree. This can be useful e.g. if you want to split a patch
into several smaller pieces."""),
opt('-b', '--branch', args = [argparse.stg_branches],
- short = 'Use BRANCH instead of the default branch')]
+ short = 'Use BRANCH instead of the default branch'),
+ opt('-t', '--top', action = 'store_true',
+ short = 'Delete top patch'),]
directory = common.DirectoryHasRepositoryLib()
@@ -49,9 +51,17 @@ def func(parser, options, args):
iw = None # can't use index/workdir to manipulate another branch
else:
iw = stack.repository.default_iw
- if args:
+ if args and options.top:
+ parser.error('Either --top or patches must be specified')
+ elif args:
patches = set(common.parse_patches(args, list(stack.patchorder.all),
len(stack.patchorder.applied)))
+ elif options.top:
+ applied = stack.patchorder.applied
+ if applied:
+ patches = set([applied[-1]])
+ else:
+ raise common.CmdException, 'No patches applied'
else:
parser.error('No patches specified')
diff --git a/t/t1600-delete-one.sh b/t/t1600-delete-one.sh
index f55bad6..f3ca356 100755
--- a/t/t1600-delete-one.sh
+++ b/t/t1600-delete-one.sh
@@ -61,7 +61,7 @@ test_expect_success \
'
test_expect_success \
- 'Create two patches' \
+ 'Create three patches' \
'
stg new foo -m foo &&
echo foo > foo.txt &&
@@ -70,10 +70,22 @@ test_expect_success \
stg new bar -m bar &&
echo bar > bar.txt &&
stg add bar.txt &&
+ stg refresh &&
+ stg new baz -m baz &&
+ echo baz > baz.txt &&
+ stg add baz.txt &&
stg refresh
'
test_expect_success \
+ 'Try to delete a topmost patch with --top option' \
+ '
+ [ $(stg series --applied -c) -eq 3 ] &&
+ stg delete --top &&
+ [ $(stg series --applied -c) -eq 2 ]
+ '
+
+test_expect_success \
'Try to delete a non-topmost applied patch' \
'
[ $(stg series --applied -c) -eq 2 ] &&