Skip to content

Commit

Permalink
Pass PID of git process to hooks.
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Pauly <alpauly@microsoft.com>
  • Loading branch information
alepauly authored and dscho committed Nov 14, 2023
1 parent cad2a90 commit e60bc76
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ static int run_pre_command_hook(const char **argv)

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

Expand Down
3 changes: 2 additions & 1 deletion t/t0400-pre-command-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ test_expect_success 'with no hook' '
test_expect_success 'with succeeding hook' '
mkdir -p .git/hooks &&
write_script .git/hooks/pre-command <<-EOF &&
echo "\$*" >\$(git rev-parse --git-dir)/pre-command.out
echo "\$*" | sed "s/ --git-pid=[0-9]*//" \
>\$(git rev-parse --git-dir)/pre-command.out
EOF
echo "second" >> file &&
git add file &&
Expand Down
3 changes: 2 additions & 1 deletion t/t0401-post-command-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ test_expect_success 'with no hook' '
test_expect_success 'with succeeding hook' '
mkdir -p .git/hooks &&
write_script .git/hooks/post-command <<-EOF &&
echo "\$*" >\$(git rev-parse --git-dir)/post-command.out
echo "\$*" | sed "s/ --git-pid=[0-9]*//" \
>\$(git rev-parse --git-dir)/post-command.out
EOF
echo "second" >> file &&
git add file &&
Expand Down

0 comments on commit e60bc76

Please sign in to comment.