git-pull-all: Better help and output
authorStefan Huber <shuber@sthu.org>
Mon, 19 Dec 2022 10:28:05 +0000 (11:28 +0100)
committerStefan Huber <shuber@sthu.org>
Mon, 19 Dec 2022 10:28:18 +0000 (11:28 +0100)
git/git-pull-all

index bd6182fb70a234d8bb7ddad224f4aea3372c7153..25252e58b575f0b41a4106324e943db7defee754 100755 (executable)
@@ -30,13 +30,30 @@ set -u
 
 showHelp()
 {
-       echo "Usage: $0 [-h|--help]"
-       echo "       $0 [OPTIONS]"
+       echo "Recursively pull git repositories behind origin."
+       echo ""
+       echo "Usage:"
+       echo "  git-pull-all [OPTIONS]"
+       echo "  git-pull-all [OPTIONS] DIR"
        echo ""
        echo "OPTIONS:"
-       echo "  -a, --ask          ask user for each repo"
-       echo "  -h, --help         show this message"
-       echo "  -n, --dry-run      do not actually perform pull"
+       echo "  -a, --ask       ask user for each repo before pull"
+       echo "  -h, --help      show this message"
+       echo "  -n, --dry-run   do not actually perform pull"
+       echo ""
+       echo ""
+       echo "Examples:"
+       echo ""
+       echo "Recursively find git repositories and invoke pull if"
+       echo "branch is behind origin:"
+       echo ""
+       echo "  git-pull-all"
+       echo ""
+       echo "Find git repositories in home directory and print"
+       echo "whether they are up to date:"
+       echo ""
+       echo "  git-pull-all -n ~"
+
 }
 
 if ! options=$(getopt -u -o ahn -l ask,help,dry-run -- "$@"); then
@@ -64,7 +81,7 @@ done
 for REPODIR in $(find "$@" -name .git -type d 2> /dev/null); do
 
        REPO=$(dirname ${REPODIR})
-       echo "Run ${REPO}…"
+       echo "Run ${REPO} …"
 
        if [ "${optAsk}" = 1 ]; then
                read -p "  Process [y/N]? " -n1  response
@@ -78,7 +95,10 @@ for REPODIR in $(find "$@" -name .git -type d 2> /dev/null); do
        if [ -z "$(git -C ${REPO} status -uno | grep 'Your branch is behind')" ] ; then
                echo -e "\e[1;32m Already up to date\e[0m"
        else
-               [ "${optDryRun}" = 1 ] && continue
+               if [ "${optDryRun}" = 1 ]; then
+                       echo -e "\e[1;31m Skipping due to dry-run\e[0m"
+                       continue
+               fi
                git -C ${REPO} pull
        fi