reset: Make reset remove the sequencer state

Years of muscle memory have trained users to use "git reset --hard" to remove the branch state after any sort operation. Make it also remove the sequencer state to facilitate this established workflow: $ git cherry-pick foo..bar ... conflict encountered ... $ git reset --hard # Oops, I didn't mean that $ git cherry-pick quux..bar ... cherry-pick succeeded ... Guard against accidental removal of the sequencer state by providing one level of "undo". In the first "reset" invocation, ".git/sequencer" is moved to ".git/sequencer-old"; it is completely removed only in the second invocation. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Aug 4, 2011 at 16:09 UTC 95eb88d8ee588d89b4f06d2753ed4d16ab13b39f
2 files changed +46
branch.c
+2
@@ -3,6 +3,7 @@
3 #include "refs.h"
4 #include "remote.h"
5 #include "commit.h"
6 +#include "sequencer.h"
7
8 struct tracking {
9 struct refspec spec;
@@ -228,4 +229,5 @@ void remove_branch_state(void)
229 unlink(git_path("MERGE_MSG"));
230 unlink(git_path("MERGE_MODE"));
231 unlink(git_path("SQUASH_MSG"));
232 + remove_sequencer_state(0);
233 }
t/t7106-reset-sequence.sh new
+44
@@ -0,0 +1,44 @@
1 +#!/bin/sh
2 +
3 +test_description='Test interaction of reset --hard with sequencer
4 +
5 + + anotherpick: rewrites foo to d
6 + + picked: rewrites foo to c
7 + + unrelatedpick: rewrites unrelated to reallyunrelated
8 + + base: rewrites foo to b
9 + + initial: writes foo as a, unrelated as unrelated
10 +'
11 +
12 +. ./test-lib.sh
13 +
14 +pristine_detach () {
15 + git cherry-pick --reset &&
16 + git checkout -f "$1^0" &&
17 + git read-tree -u --reset HEAD &&
18 + git clean -d -f -f -q -x
19 +}
20 +
21 +test_expect_success setup '
22 + echo unrelated >unrelated &&
23 + git add unrelated &&
24 + test_commit initial foo a &&
25 + test_commit base foo b &&
26 + test_commit unrelatedpick unrelated reallyunrelated &&
27 + test_commit picked foo c &&
28 + test_commit anotherpick foo d &&
29 + git config advice.detachedhead false
30 +
31 +'
32 +
33 +test_expect_success 'reset --hard cleans up sequencer state, providing one-level undo' '
34 + pristine_detach initial &&
35 + test_must_fail git cherry-pick base..anotherpick &&
36 + test_path_is_dir .git/sequencer &&
37 + git reset --hard &&
38 + test_path_is_missing .git/sequencer &&
39 + test_path_is_dir .git/sequencer-old &&
40 + git reset --hard &&
41 + test_path_is_missing .git/sequencer-old
42 +'
43 +
44 +test_done