Skip to content

Commit 45339f7

Browse files
newrengitster
authored andcommitted
am, rebase--merge: do not overlook --skip'ed commits with post-rewrite
The post-rewrite hook is supposed to be invoked for each rewritten commit. The fact that a commit was selected and processed by the rebase operation (even though when we hit an error a user said it had no more useful changes), suggests we should write an entry for it. In particular, let's treat it as an empty commit trivially squashed into its parent. This brings the rebase--am and rebase--merge backends in sync with the behavior of the interactive rebase backend. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5400677 commit 45339f7

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

builtin/am.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,15 @@ static void am_skip(struct am_state *state)
20002000
if (clean_index(&head, &head))
20012001
die(_("failed to clean index"));
20022002

2003+
if (state->rebasing) {
2004+
FILE *fp = xfopen(am_path(state, "rewritten"), "a");
2005+
2006+
assert(!is_null_oid(&state->orig_commit));
2007+
fprintf(fp, "%s ", oid_to_hex(&state->orig_commit));
2008+
fprintf(fp, "%s\n", oid_to_hex(&head));
2009+
fclose(fp);
2010+
}
2011+
20032012
am_next(state);
20042013
am_load(state);
20052014
am_run(state, 0);

git-rebase--merge.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ continue)
121121
skip)
122122
read_state
123123
git rerere clear
124+
cmt="$(cat "$state_dir/cmt.$msgnum")"
125+
echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
124126
msgnum=$(($msgnum + 1))
125127
while test "$msgnum" -le "$end"
126128
do

t/t5407-post-rewrite-hook.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ test_expect_success 'git rebase --skip' '
7878
git rebase --continue &&
7979
echo rebase >expected.args &&
8080
cat >expected.data <<-EOF &&
81+
$(git rev-parse C) $(git rev-parse HEAD^)
8182
$(git rev-parse D) $(git rev-parse HEAD)
8283
EOF
8384
verify_hook_input
@@ -91,6 +92,7 @@ test_expect_success 'git rebase --skip the last one' '
9192
echo rebase >expected.args &&
9293
cat >expected.data <<-EOF &&
9394
$(git rev-parse E) $(git rev-parse HEAD)
95+
$(git rev-parse F) $(git rev-parse HEAD)
9496
EOF
9597
verify_hook_input
9698
'
@@ -120,6 +122,7 @@ test_expect_success 'git rebase -m --skip' '
120122
git rebase --continue &&
121123
echo rebase >expected.args &&
122124
cat >expected.data <<-EOF &&
125+
$(git rev-parse C) $(git rev-parse HEAD^)
123126
$(git rev-parse D) $(git rev-parse HEAD)
124127
EOF
125128
verify_hook_input

0 commit comments

Comments
 (0)