git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: Lars Schneider <larsxschneider@gmail.com>,
	matthew.k.gumbel@intel.com,
	Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH 1/2] run-command: teach 'run_hook' about alternate worktrees
Date: Sun, 11 Feb 2018 22:15:25 -0500	[thread overview]
Message-ID: <20180212031526.40039-2-sunshine@sunshineco.com> (raw)
In-Reply-To: <20180212031526.40039-1-sunshine@sunshineco.com>

Git commands which run hooks do so at the top level of the worktree in
which the command itself was invoked. However, the 'git worktree'
command may need to run hooks within some other directory. For
instance, when "git worktree add" runs the 'post-checkout' hook, the
hook must be run within the newly-created worktree, not within the
worktree from which "git worktree add" was invoked.

To support this case, add 'run-hook' overloads which allow the
worktree directory to be specified.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 run-command.c | 23 +++++++++++++++++++++--
 run-command.h |  4 ++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/run-command.c b/run-command.c
index 31fc5ea86e..0e3995bbf9 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1197,7 +1197,8 @@ const char *find_hook(const char *name)
 	return path.buf;
 }
 
-int run_hook_ve(const char *const *env, const char *name, va_list args)
+int run_hook_cd_ve(const char *dir, const char *const *env, const char *name,
+		   va_list args)
 {
 	struct child_process hook = CHILD_PROCESS_INIT;
 	const char *p;
@@ -1206,9 +1207,10 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
 	if (!p)
 		return 0;
 
-	argv_array_push(&hook.args, p);
+	argv_array_push(&hook.args, absolute_path(p));
 	while ((p = va_arg(args, const char *)))
 		argv_array_push(&hook.args, p);
+	hook.dir = dir;
 	hook.env = env;
 	hook.no_stdin = 1;
 	hook.stdout_to_stderr = 1;
@@ -1216,6 +1218,23 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
 	return run_command(&hook);
 }
 
+int run_hook_ve(const char *const *env, const char *name, va_list args)
+{
+	return run_hook_cd_ve(NULL, env, name, args);
+}
+
+int run_hook_cd_le(const char *dir, const char *const *env, const char *name, ...)
+{
+	va_list args;
+	int ret;
+
+	va_start(args, name);
+	ret = run_hook_cd_ve(dir, env, name, args);
+	va_end(args);
+
+	return ret;
+}
+
 int run_hook_le(const char *const *env, const char *name, ...)
 {
 	va_list args;
diff --git a/run-command.h b/run-command.h
index 3932420ec8..8beddffea8 100644
--- a/run-command.h
+++ b/run-command.h
@@ -66,7 +66,11 @@ int run_command(struct child_process *);
 extern const char *find_hook(const char *name);
 LAST_ARG_MUST_BE_NULL
 extern int run_hook_le(const char *const *env, const char *name, ...);
+extern int run_hook_cd_le(const char *dir, const char *const *env,
+			  const char *name, ...);
 extern int run_hook_ve(const char *const *env, const char *name, va_list args);
+extern int run_hook_cd_ve(const char *dir, const char *const *env,
+			  const char *name, va_list args);
 
 #define RUN_COMMAND_NO_STDIN 1
 #define RUN_GIT_CMD	     2	/*If this is to be git sub-command */
-- 
2.16.1.291.g4437f3f132


  reply	other threads:[~2018-02-12  3:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-10  1:01 [PATCH v1] worktree: set worktree environment in post-checkout hook lars.schneider
2018-02-10  1:28 ` Lars Schneider
2018-02-12  3:15 ` [PATCH 0/2] worktree: change to new worktree dir before running hook(s) Eric Sunshine
2018-02-12  3:15   ` Eric Sunshine [this message]
2018-02-12 20:58     ` [PATCH 1/2] run-command: teach 'run_hook' about alternate worktrees Lars Schneider
2018-02-12 21:49       ` Eric Sunshine
2018-02-12  3:15   ` [PATCH 2/2] worktree: add: change to new worktree directory before running hook Eric Sunshine
2018-02-12 19:37     ` Junio C Hamano
2018-02-12 20:31       ` Eric Sunshine
2018-02-12 20:01     ` Lars Schneider
2018-02-13  4:42       ` Eric Sunshine
2018-02-13  4:48         ` Eric Sunshine
2018-02-13  7:27     ` Johannes Sixt
2018-02-13  7:34       ` Eric Sunshine
2018-02-15 19:18   ` [PATCH v2] worktree: add: fix 'post-checkout' not knowing new worktree location Eric Sunshine
2018-02-15 20:52     ` Junio C Hamano
2018-02-15 21:27       ` Eric Sunshine
2018-02-15 21:36         ` Junio C Hamano
2018-02-15 23:09         ` Eric Sunshine
2018-02-15 23:09     ` [PATCH v3] " Eric Sunshine
2018-02-16 16:55       ` Lars Schneider
2018-02-16 18:27         ` Eric Sunshine
2018-02-16 18:05       ` Junio C Hamano
2018-02-12  3:27 ` [PATCH v1] worktree: set worktree environment in post-checkout hook Eric Sunshine

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=20180212031526.40039-2-sunshine@sunshineco.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --cc=matthew.k.gumbel@intel.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).