From: Junio C Hamano <gitster@pobox•com>
To: Felipe Contreras <felipe.contreras@gmail•com>
Cc: git@vger•kernel.org, Ilya Bobyr <ilya.bobyr@gmail•com>
Subject: Re: [RFC/PATCH v2 2/3] run-command: make sure hooks have always GIT_DIR
Date: Wed, 23 Apr 2014 13:37:59 -0700 [thread overview]
Message-ID: <xmqqoazrye6w.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1398282160-26151-3-git-send-email-felipe.contreras@gmail.com> (Felipe Contreras's message of "Wed, 23 Apr 2014 14:42:39 -0500")
Felipe Contreras <felipe.contreras@gmail•com> writes:
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail•com>
Why is this a good change? From a zero-line log message, I cannot
even tell if this is trying to fix some problem, or trying to give
new capabilities to hooks.
How does it prevent existing hook scripts from suddenly start
misbehaving, where they do *not* expect to see an explicit GIT_DIR
pointing at the original repository hook gets run in exported into
their environment? For example, one of my post-receive hooks in a
repository I push into records $cwd (which is the GIT_DIR of
receiving repository), chdir's to another repository and then
executes "git pull $cwd" from there, and that relies on the fact
that being at the top-level of that other repository without GIT_DIR
environment pointing at elsewhere but having .git directory in that
top-level repository is sufficient to kick the auto-discovery of the
repository that receives the "pull" in order to work correctly.
> ---
> run-command.c | 24 ++++++++++++++++++++++--
> 1 file changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/run-command.c b/run-command.c
> index 75abc47..8e188f6 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -765,12 +765,29 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
> struct child_process hook;
> struct argv_array argv = ARGV_ARRAY_INIT;
> const char *p;
> - int ret;
> + const char **mod_env = NULL;
> + int ret, i = 0;
> + struct strbuf buf = STRBUF_INIT;
>
> p = find_hook(name);
> if (!p)
> return 0;
>
> + if (!getenv(GIT_DIR_ENVIRONMENT)) {
> + if (env)
> + for (i = 0; env[i]; i++);
> +
> + mod_env = xcalloc(i + 2, sizeof(*mod_env));
> +
> + if (env)
> + for (i = 0; env[i]; i++)
> + mod_env[i] = env[i];
> +
> + strbuf_addf(&buf, "GIT_DIR=%s", get_git_dir());
> + mod_env[i++] = buf.buf;
> + mod_env[i++] = NULL;
> + }
> +
> argv_array_push(&argv, p);
>
> while ((p = va_arg(args, const char *)))
> @@ -778,12 +795,15 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
>
> memset(&hook, 0, sizeof(hook));
> hook.argv = argv.argv;
> - hook.env = env;
> + hook.env = mod_env ? mod_env : env;
> hook.no_stdin = 1;
> hook.stdout_to_stderr = 1;
>
> ret = run_command(&hook);
> argv_array_clear(&argv);
> + strbuf_release(&buf);
> + free(mod_env);
> +
> return ret;
> }
next prev parent reply other threads:[~2014-04-23 20:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-23 19:42 [RFC/PATCH v2 0/3] New 'update-branch' hook Felipe Contreras
2014-04-23 19:42 ` [RFC/PATCH v2 1/3] sh-setup: export GIT_DIR Felipe Contreras
2014-04-23 20:01 ` Jeff King
2014-04-23 20:18 ` Junio C Hamano
2014-04-23 19:42 ` [RFC/PATCH v2 2/3] run-command: make sure hooks have always GIT_DIR Felipe Contreras
2014-04-23 20:37 ` Junio C Hamano [this message]
2014-04-23 21:15 ` Felipe Contreras
2014-04-23 19:42 ` [RFC/PATCH v2 3/3] Add 'update-branch' hook Felipe Contreras
2014-04-23 20:28 ` Junio C Hamano
2014-04-23 21:08 ` Felipe Contreras
2014-04-23 21:22 ` Junio C Hamano
2014-04-23 21:35 ` Felipe Contreras
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqoazrye6w.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=felipe.contreras@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=ilya.bobyr@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox