hook: scaffolding for git-hook subcommand

Introduce infrastructure for a new subcommand, git-hook, which will be
used to ease config-based hook management. This command will handle
parsing configs to compose a list of hooks to run for a given event, as
well as adding or modifying hook configs in an interactive fashion.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Emily Shaffer
2020-05-21 11:54:12 -07:00
committed by Junio C Hamano
parent a351cc04e6
commit aa8bbb612b
7 changed files with 55 additions and 0 deletions

1
.gitignore vendored
View File

@ -75,6 +75,7 @@
/git-grep
/git-hash-object
/git-help
/git-hook
/git-http-backend
/git-http-fetch
/git-http-push

View File

@ -0,0 +1,19 @@
git-hook(1)
===========
NAME
----
git-hook - Manage configured hooks
SYNOPSIS
--------
[verse]
'git hook'
DESCRIPTION
-----------
You can list, add, and modify hooks with this command.
GIT
---
Part of the linkgit:git[1] suite

View File

@ -1077,6 +1077,7 @@ BUILTIN_OBJS += builtin/get-tar-commit-id.o
BUILTIN_OBJS += builtin/grep.o
BUILTIN_OBJS += builtin/hash-object.o
BUILTIN_OBJS += builtin/help.o
BUILTIN_OBJS += builtin/hook.o
BUILTIN_OBJS += builtin/index-pack.o
BUILTIN_OBJS += builtin/init-db.o
BUILTIN_OBJS += builtin/interpret-trailers.o

View File

@ -157,6 +157,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
int cmd_grep(int argc, const char **argv, const char *prefix);
int cmd_hash_object(int argc, const char **argv, const char *prefix);
int cmd_help(int argc, const char **argv, const char *prefix);
int cmd_hook(int argc, const char **argv, const char *prefix);
int cmd_index_pack(int argc, const char **argv, const char *prefix);
int cmd_init_db(int argc, const char **argv, const char *prefix);
int cmd_interpret_trailers(int argc, const char **argv, const char *prefix);

21
builtin/hook.c Normal file
View File

@ -0,0 +1,21 @@
#include "cache.h"
#include "builtin.h"
#include "parse-options.h"
static const char * const builtin_hook_usage[] = {
N_("git hook"),
NULL
};
int cmd_hook(int argc, const char **argv, const char *prefix)
{
struct option builtin_hook_options[] = {
OPT_END(),
};
argc = parse_options(argc, argv, prefix, builtin_hook_options,
builtin_hook_usage, 0);
return 0;
}

1
git.c
View File

@ -517,6 +517,7 @@ static struct cmd_struct commands[] = {
{ "grep", cmd_grep, RUN_SETUP_GENTLY },
{ "hash-object", cmd_hash_object },
{ "help", cmd_help },
{ "hook", cmd_hook, RUN_SETUP },
{ "index-pack", cmd_index_pack, RUN_SETUP_GENTLY | NO_PARSEOPT },
{ "init", cmd_init_db },
{ "init-db", cmd_init_db },

11
t/t1360-config-based-hooks.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
test_description='config-managed multihooks, including git-hook command'
. ./test-lib.sh
test_expect_success 'git hook command does not crash' '
git hook
'
test_done