Skip to content

Commit acaa086

Browse files
committed
sequencer: run post-commit hook
Prior to commit 356ee46 ("sequencer: try to commit without forking 'git commit'", 2017-11-24) the sequencer would always run the post-commit hook after each pick or revert as it forked `git commit` to create the commit. The conversion to committing without forking `git commit` omitted to call the post-commit hook after creating the commit. Signed-off-by: Phillip Wood <[email protected]>
1 parent 420ecf4 commit acaa086

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16531653

16541654
repo_rerere(the_repository, 0);
16551655
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
1656-
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
1656+
run_post_commit_hook(use_editor, get_index_file());
16571657
if (amend && !no_post_rewrite) {
16581658
commit_post_rewrite(the_repository, current_head, &oid);
16591659
}

sequencer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,10 @@ static int run_prepare_commit_msg_hook(struct repository *r,
11731173
return ret;
11741174
}
11751175

1176+
void run_post_commit_hook(int editor_is_used, const char *index_file) {
1177+
run_commit_hook(editor_is_used, index_file, "post-commit", NULL);
1178+
}
1179+
11761180
static const char implicit_ident_advice_noconfig[] =
11771181
N_("Your name and email address were configured automatically based\n"
11781182
"on your username and hostname. Please check that they are accurate.\n"
@@ -1427,6 +1431,7 @@ static int try_to_commit(struct repository *r,
14271431
goto out;
14281432
}
14291433

1434+
run_post_commit_hook(0, r->index_file);
14301435
if (flags & AMEND_MSG)
14311436
commit_post_rewrite(r, current_head, oid);
14321437

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,5 @@ int sequencer_get_last_command(struct repository* r,
203203
enum replay_action *action);
204204
LAST_ARG_MUST_BE_NULL
205205
int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
206+
void run_post_commit_hook(int editor_is_used, const char *index_file);
206207
#endif /* SEQUENCER_H */

t/t3404-rebase-interactive.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,4 +1467,21 @@ test_expect_success 'valid author header when author contains single quote' '
14671467
test_cmp expected actual
14681468
'
14691469

1470+
test_expect_success 'post-commit hook is called' '
1471+
test_when_finished "rm -f .git/hooks/post-commit commits" &&
1472+
mkdir -p .git/hooks &&
1473+
write_script .git/hooks/post-commit <<-\EOS &&
1474+
git rev-parse HEAD >>commits
1475+
EOS
1476+
set_fake_editor &&
1477+
FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
1478+
echo x>file3 &&
1479+
git add file3 &&
1480+
FAKE_COMMIT_MESSAGE=edited git rebase --continue &&
1481+
# rev-list does not support -g --reverse
1482+
git rev-list --no-walk=unsorted HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} \
1483+
HEAD@{1} HEAD >expected &&
1484+
test_cmp expected commits
1485+
'
1486+
14701487
test_done

0 commit comments

Comments
 (0)