Skip to content

Commit 788a776

Browse files
nasamuffingitster
authored andcommitted
bugreport: collect list of populated hooks
Occasionally a failure a user is seeing may be related to a specific hook which is being run, perhaps without the user realizing. While the contents of hooks can be sensitive - containing user data or process information specific to the user's organization - simply knowing that a hook is being run at a certain stage can help us to understand whether something is going wrong. Without a definitive list of hook names within the code, we compile our own list from the documentation. This is likely prone to bitrot, but designing a single source of truth for acceptable hooks is too much overhead for this small change to the bugreport tool. Signed-off-by: Emily Shaffer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f0e984 commit 788a776

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Documentation/git-bugreport.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The following information is captured automatically:
2828
- 'git version --build-options'
2929
- uname sysname, release, version, and machine strings
3030
- Compiler-specific info string
31+
- A list of enabled hooks
3132

3233
This tool is invoked via the typical Git setup process, which means that in some
3334
cases, it might not be able to launch - for example, if a relevant config file

bugreport.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "strbuf.h"
44
#include "help.h"
55
#include "compat/compiler.h"
6+
#include "run-command.h"
7+
68

79
static void get_system_info(struct strbuf *sys_info)
810
{
@@ -31,6 +33,53 @@ static void get_system_info(struct strbuf *sys_info)
3133
get_libc_info(sys_info);
3234
}
3335

36+
static void get_populated_hooks(struct strbuf *hook_info, int nongit)
37+
{
38+
/*
39+
* NEEDSWORK: Doesn't look like there is a list of all possible hooks;
40+
* so below is a transcription of `git help hooks`. Later, this should
41+
* be replaced with some programmatically generated list (generated from
42+
* doc or else taken from some library which tells us about all the
43+
* hooks)
44+
*/
45+
static const char *hook[] = {
46+
"applypatch-msg",
47+
"pre-applypatch",
48+
"post-applypatch",
49+
"pre-commit",
50+
"pre-merge-commit",
51+
"prepare-commit-msg",
52+
"commit-msg",
53+
"post-commit",
54+
"pre-rebase",
55+
"post-checkout",
56+
"post-merge",
57+
"pre-push",
58+
"pre-receive",
59+
"update",
60+
"post-receive",
61+
"post-update",
62+
"push-to-checkout",
63+
"pre-auto-gc",
64+
"post-rewrite",
65+
"sendemail-validate",
66+
"fsmonitor-watchman",
67+
"p4-pre-submit",
68+
"post-index-change",
69+
};
70+
int i;
71+
72+
if (nongit) {
73+
strbuf_addstr(hook_info,
74+
_("not run from a git repository - no hooks to show\n"));
75+
return;
76+
}
77+
78+
for (i = 0; i < ARRAY_SIZE(hook); i++)
79+
if (find_hook(hook[i]))
80+
strbuf_addf(hook_info, "%s\n", hook[i]);
81+
}
82+
3483
static const char * const bugreport_usage[] = {
3584
N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
3685
NULL
@@ -114,6 +163,9 @@ int cmd_main(int argc, const char **argv)
114163
get_header(&buffer, _("System Info"));
115164
get_system_info(&buffer);
116165

166+
get_header(&buffer, _("Enabled Hooks"));
167+
get_populated_hooks(&buffer, nongit_ok);
168+
117169
/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */
118170
report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666);
119171

t/t0091-bugreport.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,20 @@ test_expect_success 'can create leading directories outside of a git dir' '
5757
nongit git bugreport -o foo/bar/baz
5858
'
5959

60+
test_expect_success 'indicates populated hooks' '
61+
test_when_finished rm git-bugreport-hooks.txt &&
62+
test_when_finished rm -fr .git/hooks &&
63+
rm -fr .git/hooks &&
64+
mkdir .git/hooks &&
65+
for hook in applypatch-msg prepare-commit-msg.sample
66+
do
67+
write_script ".git/hooks/$hook" <<-EOF || return 1
68+
echo "hook $hook exists"
69+
EOF
70+
done &&
71+
git bugreport -s hooks &&
72+
grep applypatch-msg git-bugreport-hooks.txt &&
73+
! grep prepare-commit-msg git-bugreport-hooks.txt
74+
'
6075

6176
test_done

0 commit comments

Comments
 (0)