-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_push_subdirectories.sh
61 lines (57 loc) · 1.19 KB
/
git_push_subdirectories.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
#!/bin/bash
# Functions
function for_all_subdirs()
{
local action_name="$1"
local action=$2
echo "$action_name"
for subdir in `ls`
do
if [ -d "$subdir" ]
then
cd "$subdir"
if [ -d ".git" ]
then
echo " $subdir"
$action &
else
echo "Skipping $subdir."
fi
cd ".."
fi
done
wait
echo "Done $action_name at `date`."
echo
}
function git_fetch() {
git fetch --quiet
}
function git_reset() {
git reset --quiet --hard
}
function git_pull() {
git pull --quiet
}
function git_add() {
git add "$files_to_add" >/dev/null
}
function git_commit() {
git commit -m "$commit_message" >/dev/null
}
function git_push() {
git push --quiet
}
# Main
echo "Pushing all subdirectories in `pwd`/ at `date`:"
read -p "Files to add: " -e -i "default.txt" files_to_add
read -p "Commit message: " -e -i "Update XYZ" commit_message
echo
for_all_subdirs "Fetching" git_fetch
for_all_subdirs "Resetting" git_reset
for_all_subdirs "Pulling" git_pull
for_all_subdirs "Adding files" git_add
for_all_subdirs "Committing" git_commit
for_all_subdirs "Pushing" git_push
echo "Done all at `date`."
read -p "Press any key to close the terminal." -n 1