git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
16324d4195849c63003aeb94a05c6ad975e646c8 blob 3056 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
 
#include "cache.h"

#include "builtin.h"
#include "config.h"
#include "hook.h"
#include "parse-options.h"
#include "strbuf.h"

static const char * const builtin_hook_usage[] = {
	N_("git hook list <hookname>"),
	NULL
};

static enum hookdir_opt should_run_hookdir;

static int list(int argc, const char **argv, const char *prefix)
{
	struct list_head *head, *pos;
	struct hook *item;
	struct strbuf hookname = STRBUF_INIT;
	struct strbuf hookdir_annotation = STRBUF_INIT;

	struct option list_options[] = {
		OPT_END(),
	};

	argc = parse_options(argc, argv, prefix, list_options,
			     builtin_hook_usage, 0);

	if (argc < 1) {
		usage_msg_opt(_("You must specify a hook event name to list."),
			      builtin_hook_usage, list_options);
	}

	strbuf_addstr(&hookname, argv[0]);

	head = hook_list(&hookname);

	if (list_empty(head)) {
		printf(_("no commands configured for hook '%s'\n"),
		       hookname.buf);
		strbuf_release(&hookname);
		return 0;
	}

	switch (should_run_hookdir) {
		case hookdir_no:
			strbuf_addstr(&hookdir_annotation, _(" (will not run)"));
			break;
		case hookdir_interactive:
			strbuf_addstr(&hookdir_annotation, _(" (will prompt)"));
			break;
		case hookdir_warn:
		case hookdir_unknown:
			strbuf_addstr(&hookdir_annotation, _(" (will warn)"));
			break;
		case hookdir_yes:
		/*
		 * The default behavior should agree with
		 * hook.c:configured_hookdir_opt().
		 */
		default:
			break;
	}

	list_for_each(pos, head) {
		item = list_entry(pos, struct hook, list);
		if (item) {
			/* Don't translate 'hookdir' - it matches the config */
			printf("%s: %s%s\n",
			       (item->from_hookdir
				? "hookdir"
				: config_scope_name(item->origin)),
			       item->command.buf,
			       (item->from_hookdir
				? hookdir_annotation.buf
				: ""));
		}
	}

	clear_hook_list(head);
	strbuf_release(&hookname);

	return 0;
}

int cmd_hook(int argc, const char **argv, const char *prefix)
{
	const char *run_hookdir = NULL;

	struct option builtin_hook_options[] = {
		OPT_STRING(0, "run-hookdir", &run_hookdir, N_("option"),
			   N_("what to do with hooks found in the hookdir")),
		OPT_END(),
	};

	argc = parse_options(argc, argv, prefix, builtin_hook_options,
			     builtin_hook_usage, 0);

	/* after the parse, we should have "<command> <hookname> <args...>" */
	if (argc < 1)
		usage_with_options(builtin_hook_usage, builtin_hook_options);


	/* argument > config */
	if (run_hookdir)
		if (!strcmp(run_hookdir, "no"))
			should_run_hookdir = hookdir_no;
		else if (!strcmp(run_hookdir, "yes"))
			should_run_hookdir = hookdir_yes;
		else if (!strcmp(run_hookdir, "warn"))
			should_run_hookdir = hookdir_warn;
		else if (!strcmp(run_hookdir, "interactive"))
			should_run_hookdir = hookdir_interactive;
		else
			die(_("'%s' is not a valid option for --run-hookdir "
			      "(yes, warn, interactive, no)"), run_hookdir);
	else
		should_run_hookdir = configured_hookdir_opt();

	if (!strcmp(argv[0], "list"))
		return list(argc, argv, prefix);

	usage_with_options(builtin_hook_usage, builtin_hook_options);
}
debug log:

solving 16324d4195 ...
found 16324d4195 in https://public-inbox.org/git/20201205014607.1464119-6-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20201014232447.3050579-5-emilyshaffer@google.com/
found 45bbc83b2b in https://public-inbox.org/git/20201205014607.1464119-5-emilyshaffer@google.com/
found 4d36de52f8 in https://public-inbox.org/git/20201014232447.3050579-4-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20201205014607.1464119-4-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20201222000220.1491091-4-emilyshaffer@google.com/
found b2bbc84d4d in https://public-inbox.org/git/20191210023335.49987-2-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20200909004939.1942347-3-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20200728222455.3023400-3-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20200521185414.43760-3-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20200414005457.3505-2-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20201205014607.1464119-3-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20201014232447.3050579-3-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20210311021037.3001235-3-emilyshaffer@google.com/ ||
	https://public-inbox.org/git/20201222000220.1491091-3-emilyshaffer@google.com/

applying [1/15] https://public-inbox.org/git/20191210023335.49987-2-emilyshaffer@google.com/
diff --git a/builtin/hook.c b/builtin/hook.c
new file mode 100644
index 0000000000..b2bbc84d4d

Checking patch builtin/hook.c...
Applied patch builtin/hook.c cleanly.

skipping https://public-inbox.org/git/20200909004939.1942347-3-emilyshaffer@google.com/ for b2bbc84d4d
skipping https://public-inbox.org/git/20200728222455.3023400-3-emilyshaffer@google.com/ for b2bbc84d4d
skipping https://public-inbox.org/git/20200521185414.43760-3-emilyshaffer@google.com/ for b2bbc84d4d
skipping https://public-inbox.org/git/20200414005457.3505-2-emilyshaffer@google.com/ for b2bbc84d4d
skipping https://public-inbox.org/git/20201205014607.1464119-3-emilyshaffer@google.com/ for b2bbc84d4d
skipping https://public-inbox.org/git/20201014232447.3050579-3-emilyshaffer@google.com/ for b2bbc84d4d
skipping https://public-inbox.org/git/20210311021037.3001235-3-emilyshaffer@google.com/ for b2bbc84d4d
skipping https://public-inbox.org/git/20201222000220.1491091-3-emilyshaffer@google.com/ for b2bbc84d4d
index at:
100644 b2bbc84d4d98aa1380c6fac60370dae76eb10f55	builtin/hook.c

applying [2/15] https://public-inbox.org/git/20201014232447.3050579-4-emilyshaffer@google.com/
diff --git a/builtin/hook.c b/builtin/hook.c
index b2bbc84d4d..4d36de52f8 100644

Checking patch builtin/hook.c...
Applied patch builtin/hook.c cleanly.

skipping https://public-inbox.org/git/20201205014607.1464119-4-emilyshaffer@google.com/ for 4d36de52f8
skipping https://public-inbox.org/git/20201222000220.1491091-4-emilyshaffer@google.com/ for 4d36de52f8
index at:
100644 4d36de52f86085647b87e38d01908577026785d3	builtin/hook.c

applying [3/15] https://public-inbox.org/git/20201205014607.1464119-5-emilyshaffer@google.com/
diff --git a/builtin/hook.c b/builtin/hook.c
index 4d36de52f8..45bbc83b2b 100644


applying [4/15] https://public-inbox.org/git/20201205014607.1464119-6-emilyshaffer@google.com/
diff --git a/builtin/hook.c b/builtin/hook.c
index 45bbc83b2b..16324d4195 100644

Checking patch builtin/hook.c...
Applied patch builtin/hook.c cleanly.
Checking patch builtin/hook.c...
Applied patch builtin/hook.c cleanly.

skipping https://public-inbox.org/git/20201014232447.3050579-5-emilyshaffer@google.com/ for 16324d4195
index at:
100644 16324d4195849c63003aeb94a05c6ad975e646c8	builtin/hook.c

Code repositories for project(s) associated with this 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).