From f6bc474d0d9d01ef8dfe8fc313f39a7c2a9c241e Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 19 Dec 2022 11:28:05 +0100 Subject: [PATCH] git-pull-all: Better help and output --- git/git-pull-all | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) 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 -- 2.39.5