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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Dec 11, 2018 at 08:11 UTC 45339f74ef87123ab79831310bf8047cebe5177b
3 files changed +14
builtin/am.c
+9
@@ -2000,6 +2000,15 @@ static void am_skip(struct am_state *state)
2000 if (clean_index(&head, &head))
2001 die(_("failed to clean index"));
2002
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 +
2012 am_next(state);
2013 am_load(state);
2014 am_run(state, 0);
git-rebase--merge.sh
+2
@@ -121,6 +121,8 @@ continue)
121 skip)
122 read_state
123 git rerere clear
124 + cmt="$(cat "$state_dir/cmt.$msgnum")"
125 + echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
126 msgnum=$(($msgnum + 1))
127 while test "$msgnum" -le "$end"
128 do
t/t5407-post-rewrite-hook.sh
+3
@@ -78,6 +78,7 @@ test_expect_success 'git rebase --skip' '
78 git rebase --continue &&
79 echo rebase >expected.args &&
80 cat >expected.data <<-EOF &&
81 + $(git rev-parse C) $(git rev-parse HEAD^)
82 $(git rev-parse D) $(git rev-parse HEAD)
83 EOF
84 verify_hook_input
@@ -91,6 +92,7 @@ test_expect_success 'git rebase --skip the last one' '
92 echo rebase >expected.args &&
93 cat >expected.data <<-EOF &&
94 $(git rev-parse E) $(git rev-parse HEAD)
95 + $(git rev-parse F) $(git rev-parse HEAD)
96 EOF
97 verify_hook_input
98 '
@@ -120,6 +122,7 @@ test_expect_success 'git rebase -m --skip' '
122 git rebase --continue &&
123 echo rebase >expected.args &&
124 cat >expected.data <<-EOF &&
125 + $(git rev-parse C) $(git rev-parse HEAD^)
126 $(git rev-parse D) $(git rev-parse HEAD)
127 EOF
128 verify_hook_input