Skip to content

Commit f249409

Browse files
committed
Merge branch 'mm/rebase-i-post-rewrite-exec' into maint
"git rebase -i" fired post-rewrite hook when it shouldn't (namely, when it was told to stop sequencing with 'exec' insn). * mm/rebase-i-post-rewrite-exec: t5407: use <<- to align the expected output rebase -i: fix post-rewrite hook with failed exec command rebase -i: demonstrate incorrect behavior of post-rewrite
2 parents f09bd21 + 141ff8f commit f249409

File tree

2 files changed

+58
-41
lines changed

2 files changed

+58
-41
lines changed

git-rebase--interactive.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ do_pick () {
502502
}
503503

504504
do_next () {
505-
rm -f "$msg" "$author_script" "$amend" || exit
505+
rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit
506506
read -r command sha1 rest < "$todo"
507507
case "$command" in
508508
"$comment_char"*|''|noop)
@@ -592,9 +592,6 @@ do_next () {
592592
read -r command rest < "$todo"
593593
mark_action_done
594594
printf 'Executing: %s\n' "$rest"
595-
# "exec" command doesn't take a sha1 in the todo-list.
596-
# => can't just use $sha1 here.
597-
git rev-parse --verify HEAD > "$state_dir"/stopped-sha
598595
${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
599596
status=$?
600597
# Run in subshell because require_clean_work_tree can die.
@@ -890,7 +887,10 @@ first and then run 'git rebase --continue' again."
890887
fi
891888
fi
892889

893-
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
890+
if test -r "$state_dir"/stopped-sha
891+
then
892+
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
893+
fi
894894

895895
require_clean_work_tree "rebase"
896896
do_rest

t/t5407-post-rewrite-hook.sh

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ test_expect_success 'git rebase' '
6161
git add foo &&
6262
git rebase --continue &&
6363
echo rebase >expected.args &&
64-
cat >expected.data <<EOF &&
65-
$(git rev-parse C) $(git rev-parse HEAD^)
66-
$(git rev-parse D) $(git rev-parse HEAD)
67-
EOF
64+
cat >expected.data <<-EOF &&
65+
$(git rev-parse C) $(git rev-parse HEAD^)
66+
$(git rev-parse D) $(git rev-parse HEAD)
67+
EOF
6868
verify_hook_input
6969
'
7070

@@ -77,9 +77,9 @@ test_expect_success 'git rebase --skip' '
7777
git add foo &&
7878
git rebase --continue &&
7979
echo rebase >expected.args &&
80-
cat >expected.data <<EOF &&
81-
$(git rev-parse D) $(git rev-parse HEAD)
82-
EOF
80+
cat >expected.data <<-EOF &&
81+
$(git rev-parse D) $(git rev-parse HEAD)
82+
EOF
8383
verify_hook_input
8484
'
8585

@@ -89,9 +89,9 @@ test_expect_success 'git rebase --skip the last one' '
8989
test_must_fail git rebase --onto D A &&
9090
git rebase --skip &&
9191
echo rebase >expected.args &&
92-
cat >expected.data <<EOF &&
93-
$(git rev-parse E) $(git rev-parse HEAD)
94-
EOF
92+
cat >expected.data <<-EOF &&
93+
$(git rev-parse E) $(git rev-parse HEAD)
94+
EOF
9595
verify_hook_input
9696
'
9797

@@ -103,10 +103,10 @@ test_expect_success 'git rebase -m' '
103103
git add foo &&
104104
git rebase --continue &&
105105
echo rebase >expected.args &&
106-
cat >expected.data <<EOF &&
107-
$(git rev-parse C) $(git rev-parse HEAD^)
108-
$(git rev-parse D) $(git rev-parse HEAD)
109-
EOF
106+
cat >expected.data <<-EOF &&
107+
$(git rev-parse C) $(git rev-parse HEAD^)
108+
$(git rev-parse D) $(git rev-parse HEAD)
109+
EOF
110110
verify_hook_input
111111
'
112112

@@ -119,9 +119,9 @@ test_expect_success 'git rebase -m --skip' '
119119
git add foo &&
120120
git rebase --continue &&
121121
echo rebase >expected.args &&
122-
cat >expected.data <<EOF &&
123-
$(git rev-parse D) $(git rev-parse HEAD)
124-
EOF
122+
cat >expected.data <<-EOF &&
123+
$(git rev-parse D) $(git rev-parse HEAD)
124+
EOF
125125
verify_hook_input
126126
'
127127

@@ -148,10 +148,10 @@ test_expect_success 'git rebase -i (unchanged)' '
148148
git add foo &&
149149
git rebase --continue &&
150150
echo rebase >expected.args &&
151-
cat >expected.data <<EOF &&
152-
$(git rev-parse C) $(git rev-parse HEAD^)
153-
$(git rev-parse D) $(git rev-parse HEAD)
154-
EOF
151+
cat >expected.data <<-EOF &&
152+
$(git rev-parse C) $(git rev-parse HEAD^)
153+
$(git rev-parse D) $(git rev-parse HEAD)
154+
EOF
155155
verify_hook_input
156156
'
157157

@@ -163,9 +163,9 @@ test_expect_success 'git rebase -i (skip)' '
163163
git add foo &&
164164
git rebase --continue &&
165165
echo rebase >expected.args &&
166-
cat >expected.data <<EOF &&
167-
$(git rev-parse D) $(git rev-parse HEAD)
168-
EOF
166+
cat >expected.data <<-EOF &&
167+
$(git rev-parse D) $(git rev-parse HEAD)
168+
EOF
169169
verify_hook_input
170170
'
171171

@@ -177,10 +177,10 @@ test_expect_success 'git rebase -i (squash)' '
177177
git add foo &&
178178
git rebase --continue &&
179179
echo rebase >expected.args &&
180-
cat >expected.data <<EOF &&
181-
$(git rev-parse C) $(git rev-parse HEAD)
182-
$(git rev-parse D) $(git rev-parse HEAD)
183-
EOF
180+
cat >expected.data <<-EOF &&
181+
$(git rev-parse C) $(git rev-parse HEAD)
182+
$(git rev-parse D) $(git rev-parse HEAD)
183+
EOF
184184
verify_hook_input
185185
'
186186

@@ -189,10 +189,10 @@ test_expect_success 'git rebase -i (fixup without conflict)' '
189189
clear_hook_input &&
190190
FAKE_LINES="1 fixup 2" git rebase -i B &&
191191
echo rebase >expected.args &&
192-
cat >expected.data <<EOF &&
193-
$(git rev-parse C) $(git rev-parse HEAD)
194-
$(git rev-parse D) $(git rev-parse HEAD)
195-
EOF
192+
cat >expected.data <<-EOF &&
193+
$(git rev-parse C) $(git rev-parse HEAD)
194+
$(git rev-parse D) $(git rev-parse HEAD)
195+
EOF
196196
verify_hook_input
197197
'
198198

@@ -205,10 +205,27 @@ test_expect_success 'git rebase -i (double edit)' '
205205
git add foo &&
206206
git rebase --continue &&
207207
echo rebase >expected.args &&
208-
cat >expected.data <<EOF &&
209-
$(git rev-parse C) $(git rev-parse HEAD^)
210-
$(git rev-parse D) $(git rev-parse HEAD)
211-
EOF
208+
cat >expected.data <<-EOF &&
209+
$(git rev-parse C) $(git rev-parse HEAD^)
210+
$(git rev-parse D) $(git rev-parse HEAD)
211+
EOF
212+
verify_hook_input
213+
'
214+
215+
test_expect_success 'git rebase -i (exec)' '
216+
git reset --hard D &&
217+
clear_hook_input &&
218+
FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
219+
echo something >bar &&
220+
git add bar &&
221+
# Fails because of exec false
222+
test_must_fail git rebase --continue &&
223+
git rebase --continue &&
224+
echo rebase >expected.args &&
225+
cat >expected.data <<-EOF &&
226+
$(git rev-parse C) $(git rev-parse HEAD^)
227+
$(git rev-parse D) $(git rev-parse HEAD)
228+
EOF
212229
verify_hook_input
213230
'
214231

0 commit comments

Comments
 (0)