Skip to content

Commit

Permalink
Merge branch 'mm/rebase-i-post-rewrite-exec'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
Junio C Hamano committed Jun 1, 2015
2 parents a9d3493 + 141ff8f commit a6be52e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 41 deletions.
10 changes: 5 additions & 5 deletions git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ do_pick () {
}

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

record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
if test -r "$state_dir"/stopped-sha
then
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
fi

require_clean_work_tree "rebase"
do_rest
Expand Down
89 changes: 53 additions & 36 deletions t/t5407-post-rewrite-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ test_expect_success 'git rebase' '
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -77,9 +77,9 @@ test_expect_success 'git rebase --skip' '
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -89,9 +89,9 @@ test_expect_success 'git rebase --skip the last one' '
test_must_fail git rebase --onto D A &&
git rebase --skip &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse E) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse E) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -103,10 +103,10 @@ test_expect_success 'git rebase -m' '
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -119,9 +119,9 @@ test_expect_success 'git rebase -m --skip' '
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -148,10 +148,10 @@ test_expect_success 'git rebase -i (unchanged)' '
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -163,9 +163,9 @@ test_expect_success 'git rebase -i (skip)' '
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -177,10 +177,10 @@ test_expect_success 'git rebase -i (squash)' '
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse C) $(git rev-parse HEAD)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse C) $(git rev-parse HEAD)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -189,10 +189,10 @@ test_expect_success 'git rebase -i (fixup without conflict)' '
clear_hook_input &&
FAKE_LINES="1 fixup 2" git rebase -i B &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse C) $(git rev-parse HEAD)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse C) $(git rev-parse HEAD)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand All @@ -205,10 +205,27 @@ test_expect_success 'git rebase -i (double edit)' '
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
cat >expected.data <<-EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

test_expect_success 'git rebase -i (exec)' '
git reset --hard D &&
clear_hook_input &&
FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
echo something >bar &&
git add bar &&
# Fails because of exec false
test_must_fail git rebase --continue &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<-EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'

Expand Down

0 comments on commit a6be52e

Please sign in to comment.