git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] sequencer: run post-commit hook

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 10, 2019, 21:31 UTC
Message-ID
<nycvar.QRO.7.76.6.1910102324140.46@tvgsbejvaqbjf.bet>
In-Reply-To
<acaa086a4860b6853bc0f35dae7fcf07d3aa59e7.1570732608.git.gitgitgadget@gmail.com>
Hi Phillip,
On Thu, 10 Oct 2019, Phillip Wood via GitGitGadget wrote:
Show 9 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Prior to commit 356ee4659b ("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 <phillip.wood@dunelm.org.uk>
Makes sense.
Show 17 quoted lines
> ---
>  builtin/commit.c              |  2 +-
>  sequencer.c                   |  5 +++++
>  sequencer.h                   |  1 +
>  t/t3404-rebase-interactive.sh | 17 +++++++++++++++++
>  4 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index d898a57f5d..adb8c89c60 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1653,7 +1653,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>
>  	repo_rerere(the_repository, 0);
>  	run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
> -	run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
> +	run_post_commit_hook(use_editor, get_index_file());

Does it really make sense to abstract the hook name away? It adds a lot of churn for just two callers...

Show 15 quoted lines
>  	if (amend && !no_post_rewrite) {
>  		commit_post_rewrite(the_repository, current_head, &oid);
>  	}
> diff --git a/sequencer.c b/sequencer.c
> index 3ce578c40b..b4947f6969 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -1173,6 +1173,10 @@ static int run_prepare_commit_msg_hook(struct repository *r,
>  	return ret;
>  }
>
> +void run_post_commit_hook(int editor_is_used, const char *index_file) {
> +	run_commit_hook(editor_is_used, index_file, "post-commit", NULL);
> +}
> +

If we must have a separate `run_post_commit_hook()`, then it should be an `inline` function, defined in the header. Or even a macro to begin with.

Show 8 quoted lines
>  static const char implicit_ident_advice_noconfig[] =
>  N_("Your name and email address were configured automatically based\n"
>  "on your username and hostname. Please check that they are accurate.\n"
> @@ -1427,6 +1431,7 @@ static int try_to_commit(struct repository *r,
>  		goto out;
>  	}
>
> +	run_post_commit_hook(0, r->index_file);
So this is the _actual_ change of this patch.
Show 26 quoted lines
>  	if (flags & AMEND_MSG)
>  		commit_post_rewrite(r, current_head, oid);
>
> diff --git a/sequencer.h b/sequencer.h
> index b0419d6ddb..e3e73c5635 100644
> --- a/sequencer.h
> +++ b/sequencer.h
> @@ -203,4 +203,5 @@ int sequencer_get_last_command(struct repository* r,
>  			       enum replay_action *action);
>  LAST_ARG_MUST_BE_NULL
>  int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
> +void run_post_commit_hook(int editor_is_used, const char *index_file);
>  #endif /* SEQUENCER_H */
> diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
> index d2f1d5bd23..d9217235b6 100755
> --- a/t/t3404-rebase-interactive.sh
> +++ b/t/t3404-rebase-interactive.sh
> @@ -1467,4 +1467,21 @@ test_expect_success 'valid author header when author contains single quote' '
>  	test_cmp expected actual
>  '
>
> +test_expect_success 'post-commit hook is called' '
> +	test_when_finished "rm -f .git/hooks/post-commit commits" &&
> +	mkdir -p .git/hooks &&
> +	write_script .git/hooks/post-commit <<-\EOS &&
> +	git rev-parse HEAD >>commits

Should `commits` be initialized before this script is written, e.g. using

	>commits &&
?
> +	EOS
> +	set_fake_editor &&

The `set_fake_editor` function sets a global environment variable, and therefore needs to be run in a subshell. Therefore, this line (as well as the next one) need to be enclosed in `( ... )`.

> +	FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
> +	echo x>file3 &&

We usually leave no space after the `>`, but we _do_ leave a space _before_ the `>`.

Show 5 quoted lines
> +	git add file3 &&
> +	FAKE_COMMIT_MESSAGE=edited git rebase --continue &&
> +	# rev-list does not support -g --reverse
> +	git rev-list --no-walk=unsorted HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} \
> +		HEAD@{1} HEAD >expected &&
Wouldn't this be better as:
	git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
		>expect &&
> +	test_cmp expected commits

We usually use the name `expect` instead of `expected` in the test suite.

Thanks, Dscho

Show 6 quoted lines
> +'
> +
>  test_done
> --
> gitgitgadget
>
Previous: Phillip Wood via GitGitGadgetNext: Junio C Hamano
Message 9 of 20 in “sequencer: start running post-commit hook again”
  1. 0/3 sequencer: start running post-commit hook againPhillip Wood via GitGitGadget, Oct 10, 2019
  2. 2/3 sequencer: use run_commit_hook()Phillip Wood via GitGitGadget, Oct 10, 2019
  3. Johannes SchindelinOct 10, 2019
  4. Junio C HamanoOct 11, 2019
  5. Phillip WoodOct 14, 2019
  6. Johannes SchindelinOct 14, 2019
  7. 1/3 sequencer.h fix placement of #endifPhillip Wood via GitGitGadget, Oct 10, 2019
  8. 3/3 sequencer: run post-commit hookPhillip Wood via GitGitGadget, Oct 10, 2019
  9. Johannes SchindelinOct 10, 2019
  10. Junio C HamanoOct 11, 2019
  11. Phillip WoodOct 11, 2019
  12. 0/6 sequencer: start running post-commit hook againPhillip Wood via GitGitGadget, Oct 15, 2019
  13. 1/6 t3404: remove unnecessary subshellPhillip Wood via GitGitGadget, Oct 15, 2019
  14. 2/6 t3404: set $EDITOR in subshellPhillip Wood via GitGitGadget, Oct 15, 2019
  15. 3/6 t3404: remove uneeded calls to set_fake_editorPhillip Wood via GitGitGadget, Oct 15, 2019
  16. 6/6 sequencer: run post-commit hookPhillip Wood via GitGitGadget, Oct 15, 2019
  17. 4/6 sequencer.h fix placement of #endifPhillip Wood via GitGitGadget, Oct 15, 2019
  18. 5/6 move run_commit_hook() to libgit and use it therePhillip Wood via GitGitGadget, Oct 15, 2019
  19. Johannes SchindelinOct 15, 2019
  20. Junio C HamanoOct 16, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.