-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-post-commit-environ
More file actions
executable file
·53 lines (45 loc) · 1.65 KB
/
example-post-commit-environ
File metadata and controls
executable file
·53 lines (45 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# .git/hooks/example-post-commit-environ
#
# Environment-based post-commit hook for Git Friends
# This hook uses environment variables for configuration instead of command-line arguments
#
# To use this hook:
# 1. Copy this file to .git/hooks/post-commit
# 2. Make it executable: chmod +x .git/hooks/post-commit
# 3. Source the accompanying .profile file or set the environment variables manually
#
# Environment variables used:
# - GF_HOOK_PATH: Path to the gf-hook binary (required)
# - GF_SERVER_URL: URL of the gf-server (optional, defaults to http://localhost:8080)
# - GF_TOKEN: Authentication token (optional, only needed if server requires auth)
# - GF_CONFIG: Path to git-friends config file (optional)
# Source the git-friends profile if it exists
if [ -f "$HOME/.git-friends.profile" ]; then
source "$HOME/.git-friends.profile"
fi
# Check if gf-hook path is set
if [ -z "$GF_HOOK_PATH" ]; then
echo "Error: GF_HOOK_PATH environment variable is not set"
echo "Please set it to the path of your gf-hook binary"
exit 1
fi
# Check if gf-hook binary exists
if [ ! -x "$GF_HOOK_PATH" ]; then
echo "Error: gf-hook binary not found or not executable at: $GF_HOOK_PATH"
exit 1
fi
# Set default server URL if not provided
GF_SERVER_URL=${GF_SERVER_URL:-"http://localhost:8080"}
# Build the command with optional arguments
GF_HOOK_ARGS="--server-url $GF_SERVER_URL"
# Add token if provided
if [ -n "$GF_TOKEN" ]; then
GF_HOOK_ARGS="$GF_HOOK_ARGS --token $GF_TOKEN"
fi
# Add config file if provided
if [ -n "$GF_CONFIG" ]; then
GF_HOOK_ARGS="$GF_HOOK_ARGS --config $GF_CONFIG"
fi
# Execute the hook
exec "$GF_HOOK_PATH" $GF_HOOK_ARGS