From: Stefan Huber Date: Mon, 19 Dec 2022 10:28:05 +0000 (+0100) Subject: git-pull-all: Better help and output X-Git-Url: https://git.sthu.org/?p=shutils.git;a=commitdiff_plain;h=f6bc474d0d9d01ef8dfe8fc313f39a7c2a9c241e git-pull-all: Better help and output --- diff --git a/git/git-pull-all b/git/git-pull-all index bd6182f..25252e5 100755 --- a/git/git-pull-all +++ b/git/git-pull-all @@ -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