All of lore.kernel.org
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: "Jeff King" <peff@peff.net>, "Duy Nguyen" <pclouds@gmail.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Johannes Sixt" <j6t@kdbg.org>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Phillip Wood" <phillip.wood123@gmail.com>,
	"Jonathan Nieder" <jrnieder@gmail.com>
Subject: [PATCH v2 5/7] transport: add support for multiple pre-push hooks
Date: Tue, 14 May 2019 00:23:30 +0000	[thread overview]
Message-ID: <20190514002332.121089-7-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20190514002332.121089-1-sandals@crustytoothpaste.net>

Add support for multiple pre-push hooks.

Remove find_hook since there are no longer any callers of it.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 run-command.c            | 12 ------------
 run-command.h            |  6 ------
 t/t5571-pre-push-hook.sh | 19 +++++++++++++++++++
 transport.c              | 29 +++++++++++++++++++----------
 4 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/run-command.c b/run-command.c
index eb075ac86b..191d6f6f7e 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1346,18 +1346,6 @@ static int has_hook(struct strbuf *path, int strip, int check)
 	return 1;
 }
 
-const char *find_hook(const char *name)
-{
-	static struct strbuf path = STRBUF_INIT;
-
-	strbuf_reset(&path);
-	strbuf_git_path(&path, "hooks/%s", name);
-	if (has_hook(&path, 1, X_OK)) {
-		return path.buf;
-	}
-	return NULL;
-}
-
 int find_hooks(const char *name, struct string_list *list)
 {
 	struct strbuf path = STRBUF_INIT;
diff --git a/run-command.h b/run-command.h
index 1b3677fcac..15974e26d4 100644
--- a/run-command.h
+++ b/run-command.h
@@ -63,12 +63,6 @@ int finish_command(struct child_process *);
 int finish_command_in_signal(struct child_process *);
 int run_command(struct child_process *);
 
-/*
- * Returns the path to the hook file, or NULL if the hook is missing
- * or disabled. Note that this points to static storage that will be
- * overwritten by further calls to find_hook and run_hook_*.
- */
-extern const char *find_hook(const char *name);
 /*
  * Returns the paths to all hook files, or NULL if all hooks are missing or
  * disabled.
diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh
index ac53d63869..754ad8eb93 100755
--- a/t/t5571-pre-push-hook.sh
+++ b/t/t5571-pre-push-hook.sh
@@ -2,6 +2,7 @@
 
 test_description='check pre-push hooks'
 . ./test-lib.sh
+. "$TEST_DIRECTORY/lib-hooks.sh"
 
 # Setup hook that always succeeds
 HOOKDIR="$(git rev-parse --git-dir)/hooks"
@@ -125,4 +126,22 @@ test_expect_success 'sigpipe does not cause pre-push hook failure' '
 	git push parent1 "refs/heads/b/*:refs/heads/b/*"
 '
 
+push_command () {
+	test_commit "$1" &&
+	git push hooks refs/heads/master:refs/heads/master
+}
+
+push_no_verify_command () {
+	test_commit "$1" &&
+	git push --no-verify hooks refs/heads/master:refs/heads/master
+}
+
+test_expect_success 'setup' '
+	git checkout master &&
+	git init --bare hooktest &&
+	git remote add hooks hooktest
+'
+
+test_multiple_hooks pre-push push_command push_no_verify_command
+
 test_done
diff --git a/transport.c b/transport.c
index 365ea574c7..7672f4fb57 100644
--- a/transport.c
+++ b/transport.c
@@ -1042,20 +1042,23 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing)
 	die(_("Aborting."));
 }
 
-static int run_pre_push_hook(struct transport *transport,
-			     struct ref *remote_refs)
+struct pre_push_hook_data {
+	struct transport *transport;
+	struct ref *remote_refs;
+};
+
+static int do_run_pre_push_hook(const char *name, const char *path, void *p)
 {
+	struct pre_push_hook_data *data = p;
+	struct child_process proc = CHILD_PROCESS_INIT;
 	int ret = 0, x;
 	struct ref *r;
-	struct child_process proc = CHILD_PROCESS_INIT;
 	struct strbuf buf;
 	const char *argv[4];
 
-	if (!(argv[0] = find_hook("pre-push")))
-		return 0;
-
-	argv[1] = transport->remote->name;
-	argv[2] = transport->url;
+	argv[0] = path;
+	argv[1] = data->transport->remote->name;
+	argv[2] = data->transport->url;
 	argv[3] = NULL;
 
 	proc.argv = argv;
@@ -1071,7 +1074,7 @@ static int run_pre_push_hook(struct transport *transport,
 
 	strbuf_init(&buf, 256);
 
-	for (r = remote_refs; r; r = r->next) {
+	for (r = data->remote_refs; r; r = r->next) {
 		if (!r->peer_ref) continue;
 		if (r->status == REF_STATUS_REJECT_NONFASTFORWARD) continue;
 		if (r->status == REF_STATUS_REJECT_STALE) continue;
@@ -1101,10 +1104,16 @@ static int run_pre_push_hook(struct transport *transport,
 	x = finish_command(&proc);
 	if (!ret)
 		ret = x;
-
 	return ret;
 }
 
+static int run_pre_push_hook(struct transport *transport,
+			     struct ref *remote_refs)
+{
+	struct pre_push_hook_data data = { transport, remote_refs };
+	return for_each_hook("pre-push", do_run_pre_push_hook, &data);
+}
+
 int transport_push(struct repository *r,
 		   struct transport *transport,
 		   struct refspec *rs, int flags,

  parent reply	other threads:[~2019-05-14  0:24 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-14  0:23 [PATCH v2 0/7] Multiple hook support brian m. carlson
2019-05-14  0:23 ` [PATCH v2 1/7] run-command: add preliminary support for multiple hooks brian m. carlson
2019-05-14 12:46   ` Duy Nguyen
2019-05-15 22:27     ` brian m. carlson
2019-05-29  2:18       ` brian m. carlson
2019-05-14 15:12   ` Johannes Schindelin
2019-05-15 22:44     ` brian m. carlson
2019-05-16 19:11       ` Johannes Sixt
2019-05-17 20:31         ` Johannes Schindelin
2019-05-14  0:23 ` [PATCH v2 2/7] builtin/receive-pack: add " brian m. carlson
2019-05-14  0:23 ` [PATCH v2 3/7] rebase: " brian m. carlson
2019-05-14 12:56   ` Duy Nguyen
2019-05-14 17:58     ` Johannes Sixt
2019-05-15 22:55     ` brian m. carlson
2019-05-16 10:29       ` Duy Nguyen
2019-05-14  0:23 ` [PATCH v2 3/7] sequencer: " brian m. carlson
2019-05-14  0:23 ` [PATCH v2 4/7] builtin/worktree: add support for multiple post-checkout hooks brian m. carlson
2019-05-14  0:23 ` brian m. carlson [this message]
2019-05-14  0:23 ` [PATCH v2 6/7] config: allow configuration of multiple hook error behavior brian m. carlson
2019-05-14 13:20   ` Duy Nguyen
2019-05-15 23:10     ` brian m. carlson
2019-05-16  5:08       ` Jeff King
2019-05-16  5:02   ` Jeff King
2019-05-16 17:19     ` brian m. carlson
2019-05-16 21:52       ` Jeff King
2019-05-14  0:23 ` [PATCH v2 7/7] docs: document multiple hooks brian m. carlson
2019-05-14 13:38   ` Duy Nguyen
2019-05-14  0:51 ` [PATCH v2 0/7] Multiple hook support Jonathan Nieder
2019-05-14  1:59   ` brian m. carlson
2019-05-14  2:26     ` Jonathan Nieder
2019-05-16  0:42       ` brian m. carlson
2019-05-16  0:51         ` Jonathan Nieder
2019-05-16  4:51     ` Jeff King
2019-05-14 13:30 ` Duy Nguyen

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=20190514002332.121089-7-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=phillip.wood123@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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.