git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Orgad Shaneh <orgads@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] Rebase: Run post-checkout hook on checkout
Date: Wed, 2 Jan 2019 16:47:16 +0100 (STD)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.1901021646060.45@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <20181229213759.12878-2-orgads@gmail.com>

Hi Orgad,

On Sat, 29 Dec 2018, orgads@gmail.com wrote:

> From: Orgad Shaneh <orgads@gmail.com>
> 
> The scripted version of rebase used to run this hook on the initial
> checkout. The transition to built-in introduced a regression.
> 
> Signed-off-by: Orgad Shaneh <orgads@gmail.com>

ACK!

For lurkers: there was a "pre-review" at
https://github.com/git-for-windows/git/pull/1992

Ciao,
Dscho

> ---
>  builtin/rebase.c              | 12 ++++++++++--
>  t/t5403-post-checkout-hook.sh | 20 ++++++++++++++++++++
>  2 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index b5c99ec10c..8402765a79 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -530,6 +530,7 @@ static int run_specific_rebase(struct rebase_options *opts)
>  
>  #define RESET_HEAD_DETACH (1<<0)
>  #define RESET_HEAD_HARD (1<<1)
> +#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)
>  
>  static int reset_head(struct object_id *oid, const char *action,
>  		      const char *switch_to_branch, unsigned flags,
> @@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action,
>  {
>  	unsigned detach_head = flags & RESET_HEAD_DETACH;
>  	unsigned reset_hard = flags & RESET_HEAD_HARD;
> +	unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
>  	struct object_id head_oid;
>  	struct tree_desc desc[2] = { { NULL }, { NULL } };
>  	struct lock_file lock = LOCK_INIT;
> @@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action,
>  			ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
>  					 UPDATE_REFS_MSG_ON_ERR);
>  	}
> +	if (run_hook)
> +		run_hook_le(NULL, "post-checkout",
> +			    oid_to_hex(orig ? orig : &null_oid),
> +			    oid_to_hex(oid), "1", NULL);
>  
>  leave_reset_head:
>  	strbuf_release(&msg);
> @@ -1465,7 +1471,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  					    getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
>  					    options.switch_to);
>  				if (reset_head(&oid, "checkout",
> -					       options.head_name, 0,
> +					       options.head_name,
> +					       RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
>  					       NULL, buf.buf) < 0) {
>  					ret = !!error(_("could not switch to "
>  							"%s"),
> @@ -1539,7 +1546,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  	strbuf_addf(&msg, "%s: checkout %s",
>  		    getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
>  	if (reset_head(&options.onto->object.oid, "checkout", NULL,
> -		       RESET_HEAD_DETACH, NULL, msg.buf))
> +		       RESET_HEAD_DETACH | RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
> +		       NULL, msg.buf))
>  		die(_("Could not detach HEAD"));
>  	strbuf_release(&msg);
>  
> diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh
> index 1d15a1031f..a539ffc080 100755
> --- a/t/t5403-post-checkout-hook.sh
> +++ b/t/t5403-post-checkout-hook.sh
> @@ -13,6 +13,8 @@ test_expect_success setup '
>  	EOF
>  	test_commit one &&
>  	test_commit two &&
> +	test_commit rebase-on-me &&
> +	git reset --hard HEAD^ &&
>  	test_commit three
>  '
>  
> @@ -44,6 +46,24 @@ test_expect_success 'post-checkout receives the right args when not switching br
>  	test $old = $new && test $flag = 0
>  '
>  
> +test_expect_success 'post-checkout is triggered on rebase' '
> +	test_when_finished "rm -f .git/post-checkout.args" &&
> +	git checkout -b rebase-test master &&
> +	rm -f .git/post-checkout.args &&
> +	git rebase rebase-on-me &&
> +	read old new flag <.git/post-checkout.args &&
> +	test $old != $new && test $flag = 1
> +'
> +
> +test_expect_success 'post-checkout is triggered on rebase with fast-forward' '
> +	test_when_finished "rm -f .git/post-checkout.args" &&
> +	git checkout -b ff-rebase-test rebase-on-me^ &&
> +	rm -f .git/post-checkout.args &&
> +	git rebase rebase-on-me &&
> +	read old new flag <.git/post-checkout.args &&
> +	test $old != $new && test $flag = 1
> +'
> +
>  test_expect_success 'post-checkout hook is triggered by clone' '
>  	mkdir -p templates/hooks &&
>  	write_script templates/hooks/post-checkout <<-\EOF &&
> -- 
> 2.20.1
> 
> 

  reply	other threads:[~2019-01-02 15:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-29 21:37 [PATCH 1/2] t5403: simplify by using a single repository orgads
2018-12-29 21:37 ` [PATCH 2/2] Rebase: Run post-checkout hook on checkout orgads
2019-01-02 15:47   ` Johannes Schindelin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-12-24 21:24 [PATCH] " orgads
2018-12-24 21:24 ` [PATCH 2/2] " orgads
2018-12-28 22:53   ` Junio C Hamano
2018-12-29 21:31     ` Orgad Shaneh
2018-12-20 21:55 [PATCH 1/2] t5403: Refactor orgads
2018-12-20 21:55 ` [PATCH 2/2] Rebase: Run post-checkout hook on checkout orgads
2018-12-20 21:48 [PATCH 1/2] t5403: Refactor orgads
2018-12-20 21:48 ` [PATCH 2/2] Rebase: Run post-checkout hook on checkout orgads
2018-12-21 16:12   ` Johannes Schindelin
2018-12-24 21:24     ` Orgad Shaneh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.1901021646060.45@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=orgads@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).