This is similar to the git reset --hard command.
Signed-off-by: Catalin Marinas <[email protected]>
---
stgit/commands/reset.py | 29 +++++++++++++++++------------
t/t1205-push-subdir.sh | 2 +-
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/stgit/commands/reset.py b/stgit/commands/reset.py
index f47bfce..a106e12 100644
--- a/stgit/commands/reset.py
+++ b/stgit/commands/reset.py
@@ -21,18 +21,19 @@ from stgit.argparse import opt
from stgit.commands import common
from stgit.lib import git, log, transaction
from stgit.out import out
-from stgit import argparse
+from stgit import argparse, utils
help = 'Reset the patch stack to an earlier state'
kind = 'stack'
-usage = ['[options] [--] <state> [<patchnames>]']
+usage = ['[options] [--] [<state> [<patchnames>]]']
description = """
-Reset the patch stack to an earlier state. The state is specified with
-a commit id from a stack log; "stg log" lets you view this log, and
-"stg reset" lets you reset to any state you see in the log.
+Reset the patch stack to an earlier state. If no state is specified,
+reset only the changes in the worktree.
-If one or more patch names are given, reset only those patches, and
-leave the rest alone."""
+The state is specified with a commit id from a stack log; "stg log" lets
+you view this log, and "stg reset" lets you reset to any state you see
+in the log. If one or more patch names are given, reset only those
+patches, and leave the rest alone."""
args = [argparse.patch_range(argparse.applied_patches,
argparse.unapplied_patches,
@@ -45,21 +46,25 @@ directory = common.DirectoryHasRepositoryLib()
def func(parser, options, args):
stack = directory.repository.current_stack
+ iw = stack.repository.default_iw
if len(args) >= 1:
ref, patches = args[0], args[1:]
state = log.get_log_entry(stack.repository, ref,
stack.repository.rev_parse(ref))
+ elif options.hard:
+ iw.checkout_hard(stack.head.data.tree)
+ return utils.STGIT_SUCCESS
else:
- raise common.CmdException('Wrong number of arguments')
+ raise common.CmdException('Wrong options or number of arguments')
+
trans = transaction.StackTransaction(stack, 'reset',
discard_changes = options.hard,
allow_bad_head = True)
try:
if patches:
- log.reset_stack_partially(trans, stack.repository.default_iw,
- state, patches)
+ log.reset_stack_partially(trans, iw, state, patches)
else:
- log.reset_stack(trans, stack.repository.default_iw, state)
+ log.reset_stack(trans, iw, state)
except transaction.TransactionHalted:
pass
- return trans.run(stack.repository.default_iw, allow_bad_head = not patches)
+ return trans.run(iw, allow_bad_head = not patches)
diff --git a/t/t1205-push-subdir.sh b/t/t1205-push-subdir.sh
index 4af63ce..ed407d0 100755
--- a/t/t1205-push-subdir.sh
+++ b/t/t1205-push-subdir.sh
@@ -53,7 +53,7 @@ test_expect_success 'Conflicting push from subdir' '
'
test_expect_success 'Conflicting add/unknown file in subdir' '
- stg status --reset &&
+ stg reset --hard &&
stg new foo -m foo &&
mkdir d &&
echo foo > d/test &&
_______________________________________________
stgit-users mailing list
[email protected]
https://mail.gna.org/listinfo/stgit-users