Skip to content

Commit 5cffe06

Browse files
alepaulydscho
authored andcommitted
Pass PID of git process to hooks.
Signed-off-by: Alejandro Pauly <alpauly@microsoft.com>
1 parent a573289 commit 5cffe06

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
@@ -464,6 +464,7 @@ static int run_pre_command_hook(struct repository *r, const char **argv)
464464

465465
/* call the hook proc */
466466
strvec_pushv(&sargv, argv);
467+
strvec_pushf(&sargv, "--git-pid=%"PRIuMAX, (uintmax_t)getpid());
467468
strvec_pushv(&opt.args, sargv.v);
468469
ret = run_hooks_opt(r, "pre-command", &opt);
469470

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)