-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitify.sh
executable file
·117 lines (93 loc) · 2.66 KB
/
gitify.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
desired_branch="main"
username="your_username"
email="your_email"
# Prints its first argument...
# Adds a 1 second cooldown...
log() {
echo -e "$1"
sleep 1
}
# Checks if there is already a username and email in configuration...
# If no username or email if found, it will config it...
check_credentials() {
log "\nChecking credentials..."
if ! git config --get user.name || ! git config --get user.email; then
log "No Credentials found!!!"
log "Configuring credentials..."
git config user.name "$username"
git config user.email "$email"
fi
log "Credentials have been configured successfully!"
}
# Checks if we are in the desired branch before adding files...
# Exits the program is we're in a different branch to prevent confusion...
check_branch() {
log "\nChecking branch..."
git branch -a
if [ "$(git rev-parse --abbrev-ref HEAD)" != "$desired_branch" ]; then
log "[WARNING] Not on branch $desired_branch..."
log "Please restart..."
exit 1
fi
log "You're on branch $desired_branch!"
}
# Adds the files given as arguments...
# If there is no arguments, it adds all files...
add_files() {
log "\nAdding files..."
if [ $# -eq 0 ]; then
log "No Files specified..."
log "Adding all changes..."
git add .
else
log "Adding Specified files..."
for file in "$@"; do
git add "$file"
log "Added: $file"
done
fi
log "Files added successfully!"
}
# Prompts the user for a commit message...
# Then commits the changes...
# Then pushes the changes...
# Cannot be called with auto_push() at the same time...
commit_and_push() {
log "\nTime to push changes..."
git status
read -r -p "Enter Commit Message: " commit_message
git commit -a -m "$commit_message"
git push origin "$desired_branch"
git push mirror "$desired_branch"
log "Well done!"
}
# Adds files, then commits with a autogenerated message, then pushes...
# All in a defined time interval...
# Not used, needs further investigations...
# Requires commit_and_push() to be desactivated...
auto_push() {
i=1
# Continuous process...
while true; do
if [[ -n $(git status -s) ]]; then
add_files "$@"
log "Status:"
git status
git commit -a -m "Auto Commit - $i"
git push origin master
i=$((i + 1))
fi
sleep 1200
done
}
#_________________________________________________________________________
#
main() {
check_credentials
check_branch
add_files "$@"
commit_and_push
# auto_push
}
main "$@"