From 49106d71adbd164b3aa72db9e402667d8c9efcfd Mon Sep 17 00:00:00 2001 From: Andrew Stowell Date: Thu, 13 Feb 2020 13:22:34 -0500 Subject: [PATCH] fetch-all.sh now defaults to current location, and is recursive. --- fetch-all.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fetch-all.sh b/fetch-all.sh index d8bfdaf..3ec6d9d 100755 --- a/fetch-all.sh +++ b/fetch-all.sh @@ -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