Skip to content

Commit 281fa4f

Browse files
alepaulyvdye
authored andcommitted
Pass PID of git process to hooks.
Signed-off-by: Alejandro Pauly <alpauly@microsoft.com>
1 parent 88d4687 commit 281fa4f

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
@@ -449,6 +449,7 @@ static int run_pre_command_hook(const char **argv)
449449

450450
/* call the hook proc */
451451
strvec_pushv(&sargv, argv);
452+
strvec_pushf(&sargv, "--git-pid=%"PRIuMAX, (uintmax_t)getpid());
452453
strvec_pushv(&opt.args, sargv.v);
453454
ret = run_hooks_opt("pre-command", &opt);
454455

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)