-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull-all.sh
More file actions
executable file
·52 lines (44 loc) · 1.72 KB
/
Copy pathpull-all.sh
File metadata and controls
executable file
·52 lines (44 loc) · 1.72 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
#!/usr/bin/env bash
# perform a "git pull" on each location specified (recursively), or current location if none specified.
# git will quietly ignore any git repo stored in a folder you lack permission on.
# pull will not go through if there are uncommitted local changes, or if the branch has no upstream.
#
# will only search symbolic links when passed "-l" option, must be before any locations
# will only search hidden directories when passed "-h" option, must be before any locations
# pull-all.sh [-l][-h] # current location implied
# pull-all.sh [-l][-h] ~/my-projects /var/group-projects
# check for "-l" and "-h" in command prompt
followLinks="-H"
checkHidden="*/.*/.git"
while getopts "lh" option; do
case $option in
l)
followLinks="-L"
;;
h)
checkHidden=""
;;
esac
done
shift "$((OPTIND-1))"
if [[ "-H" == "$followLinks" ]]; then
echo "use -l to follow symbolic links"
fi
if [[ -n "$checkHidden" ]]; then
echo "use -h to check hidden directories"
fi
# function to process each location
function process_git_pull () {
startedIn=`pwd`
location=$(realpath $(dirname "$@"))
line="--- --- --- --- --- --- --- --- ---"
# use "--" to tell printf there are no more commands, only strings to print
printf -- "--- git pull %s %s ---\n" "$location" "${line:${#location}}"
cd "$location"
git pull --ff-only
cd "$startedIn"
}
# find all folders named ".git" under given locations,
# and call process_git_pull on each location that was found.
# we then work on the folder that contained the ".git" folder.
find "$followLinks" "$@" -type d -name ".git" -not -path "$checkHidden" | sort | while read -r file; do process_git_pull "$file"; done