Skip to content

Commit 9d4b2f7

Browse files
alepaulydscho
authored andcommitted
Pass PID of git process to hooks.
Signed-off-by: Alejandro Pauly <[email protected]>
1 parent 89ea17f commit 9d4b2f7

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ static int run_pre_command_hook(struct repository *r, const char **argv)
462462

463463
/* call the hook proc */
464464
strvec_pushv(&sargv, argv);
465+
strvec_pushf(&sargv, "--git-pid=%"PRIuMAX, (uintmax_t)getpid());
465466
strvec_pushv(&opt.args, sargv.v);
466467
ret = run_hooks_opt(r, "pre-command", &opt);
467468

t/t0400-pre-command-hook.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ test_expect_success 'with no hook' '
1313
test_expect_success 'with succeeding hook' '
1414
mkdir -p .git/hooks &&
1515
write_script .git/hooks/pre-command <<-EOF &&
16-
echo "\$*" >\$(git rev-parse --git-dir)/pre-command.out
16+
echo "\$*" | sed "s/ --git-pid=[0-9]*//" \
17+
>\$(git rev-parse --git-dir)/pre-command.out
1718
EOF
1819
echo "second" >> file &&
1920
git add file &&

t/t0401-post-command-hook.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ test_expect_success 'with no hook' '
1313
test_expect_success 'with succeeding hook' '
1414
mkdir -p .git/hooks &&
1515
write_script .git/hooks/post-command <<-EOF &&
16-
echo "\$*" >\$(git rev-parse --git-dir)/post-command.out
16+
echo "\$*" | sed "s/ --git-pid=[0-9]*//" \
17+
>\$(git rev-parse --git-dir)/post-command.out
1718
EOF
1819
echo "second" >> file &&
1920
git add file &&

0 commit comments

Comments
 (0)