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
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
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