Skip to content

Commit 2c3382d

Browse files
nasamuffingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2067cba commit 2c3382d

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
/git-grep
7676
/git-hash-object
7777
/git-help
78+
/git-hook
7879
/git-http-backend
7980
/git-http-fetch
8081
/git-http-push

Documentation/git-hook.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
git-hook(1)
2+
===========
3+
4+
NAME
5+
----
6+
git-hook - Manage configured hooks
7+
8+
SYNOPSIS
9+
--------
10+
[verse]
11+
'git hook'
12+
13+
DESCRIPTION
14+
-----------
15+
You can list, add, and modify hooks with this command.
16+
17+
GIT
18+
---
19+
Part of the linkgit:git[1] suite

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ BUILTIN_OBJS += builtin/get-tar-commit-id.o
10771077
BUILTIN_OBJS += builtin/grep.o
10781078
BUILTIN_OBJS += builtin/hash-object.o
10791079
BUILTIN_OBJS += builtin/help.o
1080+
BUILTIN_OBJS += builtin/hook.o
10801081
BUILTIN_OBJS += builtin/index-pack.o
10811082
BUILTIN_OBJS += builtin/init-db.o
10821083
BUILTIN_OBJS += builtin/interpret-trailers.o

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
157157
int cmd_grep(int argc, const char **argv, const char *prefix);
158158
int cmd_hash_object(int argc, const char **argv, const char *prefix);
159159
int cmd_help(int argc, const char **argv, const char *prefix);
160+
int cmd_hook(int argc, const char **argv, const char *prefix);
160161
int cmd_index_pack(int argc, const char **argv, const char *prefix);
161162
int cmd_init_db(int argc, const char **argv, const char *prefix);
162163
int cmd_interpret_trailers(int argc, const char **argv, const char *prefix);

builtin/hook.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "cache.h"
2+
3+
#include "builtin.h"
4+
#include "parse-options.h"
5+
6+
static const char * const builtin_hook_usage[] = {
7+
N_("git hook"),
8+
NULL
9+
};
10+
11+
int cmd_hook(int argc, const char **argv, const char *prefix)
12+
{
13+
struct option builtin_hook_options[] = {
14+
OPT_END(),
15+
};
16+
17+
argc = parse_options(argc, argv, prefix, builtin_hook_options,
18+
builtin_hook_usage, 0);
19+
20+
return 0;
21+
}

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ static struct cmd_struct commands[] = {
517517
{ "grep", cmd_grep, RUN_SETUP_GENTLY },
518518
{ "hash-object", cmd_hash_object },
519519
{ "help", cmd_help },
520+
{ "hook", cmd_hook, RUN_SETUP },
520521
{ "index-pack", cmd_index_pack, RUN_SETUP_GENTLY | NO_PARSEOPT },
521522
{ "init", cmd_init_db },
522523
{ "init-db", cmd_init_db },

t/t1360-config-based-hooks.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
test_description='config-managed multihooks, including git-hook command'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'git hook command does not crash' '
8+
git hook
9+
'
10+
11+
test_done

0 commit comments

Comments
 (0)