From 42d1920cf413a734f617942022777d420765ab4f Mon Sep 17 00:00:00 2001 From: Andrew Stowell Date: Tue, 26 Sep 2023 14:30:31 +0000 Subject: [PATCH] new pull-all script, updated fetch-all to optionally work with symlinks. --- fetch-all.sh | 50 +++++++++++++++++++++++++++++++++++--------------- pull-all.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 15 deletions(-) create mode 100755 pull-all.sh diff --git a/fetch-all.sh b/fetch-all.sh index 3ec6d9d..94556ed 100755 --- a/fetch-all.sh +++ b/fetch-all.sh @@ -1,23 +1,43 @@ #!/bin/bash -# 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 +# perform a "git fetch" 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. +# fetch does not effect local files, just updating information about repo from remote. +# +# will only search symbolic links when passed "-l" option, must be before any locations +# fetch-all.sh [-l] # current location implied +# fetch-all.sh [-l] ~/my-projects /var/group-projects + +# check for "-l" in command prompt +followLinks="-H" +while getopts "l" option; do + case $option in + l) + followLinks="-L" + ;; + esac +done +shift "$((OPTIND-1))" + +if [[ "-H" == "$followLinks" ]]; then + echo "use -l to follow symbolic links" +fi + +# function to process each location function process_git_fetch () { - STARTED_IN=`pwd` - for location in "$@"; do - echo -n "----- git fetch $location " - printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------" - echo "-----" - cd "$location" - git fetch --prune - done - cd "$STARTED_IN" + startedIn=`pwd` + location=$(dirname "$@") + echo -n "----- git fetch $location " + printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------" + echo "-----" + cd "$location" + git fetch --tags --prune + cd "$startedIn" } # 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). +# we then work on the folder that contained the ".git" folder. + +find "$followLinks" "$@" -type d -name ".git" | while read file; do process_git_fetch "$file"; done -find "$@" -type d -name ".git" 2> /dev/null | while read file; do process_git_fetch "$file"; done diff --git a/pull-all.sh b/pull-all.sh new file mode 100755 index 0000000..96d2da5 --- /dev/null +++ b/pull-all.sh @@ -0,0 +1,43 @@ +#!/bin/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 +# pull-all.sh [-l] # current location implied +# pull-all.sh [-l] ~/my-projects /var/group-projects + +# check for "-l" in command prompt +followLinks="-H" +while getopts "l" option; do + case $option in + l) + followLinks="-L" + ;; + esac +done +shift "$((OPTIND-1))" + +if [[ "-H" == "$followLinks" ]]; then + echo "use -l to follow symbolic links" +fi + +# function to process each location +function process_git_pull () { + startedIn=`pwd` + location=$(dirname "$@") + echo -n "----- git pull $location " + printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------" + echo "-----" + 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" | while read file; do process_git_pull "$file"; done +