diff options
author | Catalin Marinas <catalin.marinas@gmail.com> | 2011-09-09 16:58:30 +0100 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@gmail.com> | 2011-09-12 10:13:11 +0100 |
commit | bd8778ae3ddf8b1c9d885b9b97aa0ae026bb8ae1 (patch) | |
tree | 934e36d17c72363e7d4a15ffc85064cf299961b6 | |
parent | b487d68f4dd0372e00bcc44e547162c2a5301cf8 (diff) | |
download | stgit-bd8778ae3ddf8b1c9d885b9b97aa0ae026bb8ae1.tar.gz |
Allow 'stg reset --hard' to reset the changes in the worktree
This is similar to the git reset --hard command.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
-rw-r--r-- | stgit/commands/reset.py | 29 | ||||
-rwxr-xr-x | 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 && |