-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandleGitConfigs.sh
executable file
·53 lines (45 loc) · 1.84 KB
/
handleGitConfigs.sh
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
# Function to check if Git is configured with the desired identity
configure_git_identity() {
# Set the desired Git identity
git config --global user.name "$GIT_USERNAME"
git config --global user.email "$GIT_EMAIL"
# Recheck if configurations match the desired identity after setting them
CONFIGURED_USERNAME=$(git config --global user.name)
CONFIGURED_EMAIL=$(git config --global user.email)
# Check if configurations match the desired identity
if [ "$CONFIGURED_USERNAME" != "$GIT_USERNAME" ] || [ "$CONFIGURED_EMAIL" != "$GIT_EMAIL" ];
then
echo "Could not configure git"
exit 1
else
echo "Git Git configured successfully"
fi
}
check_and_configure_git() {
# Check if user.name and user.email are configured globally
CONFIGURED_USERNAME=$(git config --global user.name)
CONFIGURED_EMAIL=$(git config --global user.email)
# Check if configurations match your desired identity
if [ "$CONFIGURED_USERNAME" != "$GIT_USERNAME" ] || [ "$CONFIGURED_EMAIL" != "$GIT_EMAIL" ];
then
echo "Git not configured. Configuring now with the following"
echo "Username: $GIT_USERNAME"
echo "Email: $GIT_EMAIL"
configure_git_identity
fi
}
# Main function to check and configure Git
check_and_configure_git() {
# Check if user.name and user.email are configured globally
CONFIGURED_USERNAME=$(git config --global user.name)
CONFIGURED_EMAIL=$(git config --global user.email)
# Check if configurations match your desired identity
if [ "$CONFIGURED_USERNAME" != "$GIT_USERNAME" ] || [ "$CONFIGURED_EMAIL" != "$GIT_EMAIL" ]; then
echo "Git not configured. Configuring now with the following:"
echo "Username: $GIT_USERNAME"
echo "Email: $GIT_EMAIL"
configure_git_identity
fi
}
check_and_configure_git