git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob 012a2973b38df644bcf4d535133c91ddebf7db4f 2020 bytes (raw)
name: builtin/hook.c 	 # note: path name is non-authoritative(*)

 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
 
#include "cache.h"
#include "builtin.h"
#include "config.h"
#include "hook.h"
#include "parse-options.h"
#include "strbuf.h"
#include "strvec.h"

#define BUILTIN_HOOK_RUN_USAGE \
	N_("git hook run <hook-name> [-- <hook-args>]")

static const char * const builtin_hook_usage[] = {
	BUILTIN_HOOK_RUN_USAGE,
	NULL
};

static const char * const builtin_hook_run_usage[] = {
	BUILTIN_HOOK_RUN_USAGE,
	NULL
};

static int run(int argc, const char **argv, const char *prefix)
{
	int i;
	struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
	const char *hook_name;
	const char *hook_path;
	struct option run_options[] = {
		OPT_END(),
	};
	int ret;

	argc = parse_options(argc, argv, prefix, run_options,
			     builtin_hook_run_usage,
			     PARSE_OPT_KEEP_DASHDASH);

	if (!argc)
		goto usage;

	/*
	 * Having a -- for "run" when providing <hook-args> is
	 * mandatory.
	 */
	if (argc > 1 && strcmp(argv[1], "--") &&
	    strcmp(argv[1], "--end-of-options"))
		goto usage;

	/* Add our arguments, start after -- */
	for (i = 2 ; i < argc; i++)
		strvec_push(&opt.args, argv[i]);

	/* Need to take into account core.hooksPath */
	git_config(git_default_config, NULL);

	/*
	 * We are not using a plain run_hooks() because we'd like to
	 * detect missing hooks. Let's find it ourselves and call
	 * run_hooks() instead.
	 */
	hook_name = argv[0];
	hook_path = find_hook(hook_name);
	if (!hook_path) {
		error("cannot find a hook named %s", hook_name);
		return 1;
	}

	ret = run_hooks(hook_name, hook_path, &opt);
	run_hooks_opt_clear(&opt);
	return ret;
usage:
	usage_with_options(builtin_hook_run_usage, run_options);
}

int cmd_hook(int argc, const char **argv, const char *prefix)
{
	struct option builtin_hook_options[] = {
		OPT_END(),
	};

	argc = parse_options(argc, argv, NULL, builtin_hook_options,
			     builtin_hook_usage, PARSE_OPT_STOP_AT_NON_OPTION);
	if (!argc)
		goto usage;

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

usage:
	usage_with_options(builtin_hook_usage, builtin_hook_options);
}

debug log:

solving 012a2973b38 ...
found 012a2973b38 in https://public-inbox.org/git/patch-01.13-a39c0748d3f-20211012T131934Z-avarab@gmail.com/ ||
	https://public-inbox.org/git/patch-v5-08.36-72dd1010f5b-20210902T125110Z-avarab@gmail.com/

applying [1/1] https://public-inbox.org/git/patch-01.13-a39c0748d3f-20211012T131934Z-avarab@gmail.com/
diff --git a/builtin/hook.c b/builtin/hook.c
new file mode 100644
index 00000000000..012a2973b38

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

skipping https://public-inbox.org/git/patch-v5-08.36-72dd1010f5b-20210902T125110Z-avarab@gmail.com/ for 012a2973b38
index at:
100644 012a2973b38df644bcf4d535133c91ddebf7db4f	builtin/hook.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).