Skip to content

Commit 4f8ab59

Browse files
committed
Merge branch 'es/hooks-and-local-env' into maint-2.39
Doc update for environment variables set when hooks are invoked. * es/hooks-and-local-env: githooks: discuss Git operations in foreign repositories
2 parents 4950677 + 772f8ff commit 4f8ab59

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Documentation/githooks.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ repository. An exception are hooks triggered during a push ('pre-receive',
2727
'update', 'post-receive', 'post-update', 'push-to-checkout') which are always
2828
executed in $GIT_DIR.
2929

30+
Environment variables, such as `GIT_DIR`, `GIT_WORK_TREE`, etc., are exported
31+
so that Git commands run by the hook can correctly locate the repository. If
32+
your hook needs to invoke Git commands in a foreign repository or in a
33+
different working tree of the same repository, then it should clear these
34+
environment variables so they do not interfere with Git operations at the
35+
foreign location. For example:
36+
37+
------------
38+
local_desc=$(git describe)
39+
foreign_desc=$(unset $(git rev-parse --local-env-vars); git -C ../foreign-repo describe)
40+
------------
41+
3042
Hooks can get their arguments via the environment, command-line
3143
arguments, and stdin. See the documentation for each hook below for
3244
details.

0 commit comments

Comments
 (0)