fetch-all.sh now defaults to current location, and is recursive.

This commit is contained in:
2020-02-13 13:22:34 -05:00
parent 28598d145c
commit 49106d71ad
+13 -10
View File
@@ -1,20 +1,23 @@
#!/bin/bash
# perform a "git fetch" on each location specified
# fetch-all.sh ~/project [~/second-project]
# perform a "git fetch" on each location specified (recursively), or current location if none specified.
# will quietly ignore any git repo stored in a folder you lack permission on.
# fetch-all.sh # current location implied
# fetch-all.sh ~/my-projects /var/group-projects
function process_git_fetch () {
STARTED_IN=`pwd`
for location in "$@"; do
if [ -d "$location/.git" ]; then
echo -n "----- git fetch $location "
printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------"
echo "-----"
cd "$location"
git fetch --prune
fi
echo -n "----- git fetch $location "
printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------"
echo "-----"
cd "$location"
git fetch --prune
done
cd "$STARTED_IN"
}
process_git_fetch "$@"
# find all folders named ".git" under given locations,
# and call process_git_fetch on each location that was found.
# only works because you can fetch while inside the ".git" folder (can not git status).
find "$@" -type d -name ".git" 2> /dev/null | while read file; do process_git_fetch "$file"; done