Skip to content

Commit 95eb88d

Browse files
artagnongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 26ae337 commit 95eb88d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

branch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "refs.h"
44
#include "remote.h"
55
#include "commit.h"
6+
#include "sequencer.h"
67

78
struct tracking {
89
struct refspec spec;
@@ -228,4 +229,5 @@ void remove_branch_state(void)
228229
unlink(git_path("MERGE_MSG"));
229230
unlink(git_path("MERGE_MODE"));
230231
unlink(git_path("SQUASH_MSG"));
232+
remove_sequencer_state(0);
231233
}

t/t7106-reset-sequence.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)