git

Форк
0
/
hook.c 
81 строка · 1.9 Кб
1
#include "builtin.h"
2
#include "config.h"
3
#include "gettext.h"
4
#include "hook.h"
5
#include "parse-options.h"
6
#include "strvec.h"
7

8
#define BUILTIN_HOOK_RUN_USAGE \
9
	N_("git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]")
10

11
static const char * const builtin_hook_usage[] = {
12
	BUILTIN_HOOK_RUN_USAGE,
13
	NULL
14
};
15

16
static const char * const builtin_hook_run_usage[] = {
17
	BUILTIN_HOOK_RUN_USAGE,
18
	NULL
19
};
20

21
static int run(int argc, const char **argv, const char *prefix)
22
{
23
	int i;
24
	struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
25
	int ignore_missing = 0;
26
	const char *hook_name;
27
	struct option run_options[] = {
28
		OPT_BOOL(0, "ignore-missing", &ignore_missing,
29
			 N_("silently ignore missing requested <hook-name>")),
30
		OPT_STRING(0, "to-stdin", &opt.path_to_stdin, N_("path"),
31
			   N_("file to read into hooks' stdin")),
32
		OPT_END(),
33
	};
34
	int ret;
35

36
	argc = parse_options(argc, argv, prefix, run_options,
37
			     builtin_hook_run_usage,
38
			     PARSE_OPT_KEEP_DASHDASH);
39

40
	if (!argc)
41
		goto usage;
42

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

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

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

58
	hook_name = argv[0];
59
	if (!ignore_missing)
60
		opt.error_if_missing = 1;
61
	ret = run_hooks_opt(the_repository, hook_name, &opt);
62
	if (ret < 0) /* error() return */
63
		ret = 1;
64
	return ret;
65
usage:
66
	usage_with_options(builtin_hook_run_usage, run_options);
67
}
68

69
int cmd_hook(int argc, const char **argv, const char *prefix)
70
{
71
	parse_opt_subcommand_fn *fn = NULL;
72
	struct option builtin_hook_options[] = {
73
		OPT_SUBCOMMAND("run", &fn, run),
74
		OPT_END(),
75
	};
76

77
	argc = parse_options(argc, argv, NULL, builtin_hook_options,
78
			     builtin_hook_usage, 0);
79

80
	return fn(argc, argv, prefix);
81
}
82

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.