Last active
April 15, 2019 15:43
-
-
Save jgriff/ee9c6ac28b58fe1b892b8b88bf823ad2 to your computer and use it in GitHub Desktop.
Recursively walks a directory and perform a git pull (if dir is a git repo). Ignores non-git directories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dir="$1" | |
display_prefix="$2" | |
# No directory has been provided, use current | |
if [ -z "$dir" ] | |
then | |
dir="`pwd`" | |
fi | |
# Make sure directory ends with "/" | |
if [[ $dir != */ ]] | |
then | |
dir="$dir/*" | |
else | |
dir="$dir*" | |
fi | |
# Loop all sub-directories | |
for f in $dir | |
do | |
# Only interested in directories | |
[ -d "${f}" ] || continue | |
# Check if directory is a git repository | |
if [ -d "$f/.git" ] | |
then | |
echo -n "Pulling " | |
echo -en "\033[0;34m" | |
echo -n $display_prefix | |
echo -n `basename $f` | |
echo -en "\033[0m" | |
echo -n "... " | |
git -C $f pull --rebase --prune --quiet &> /dev/null | |
if [ $? -eq 0 ] | |
then # everything is good | |
echo -en "\033[0;32m" | |
echo -n "✔ " | |
echo -e "\033[0m" | |
else # there are local changes | |
echo -en "\033[0;31m" | |
echo -n "✘ " | |
echo -e "\033[0m" | |
fi | |
else | |
# recurse into sub-directory | |
git-pull $f "${display_prefix}${f##*/}/" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation
Place in your
PATH
.Usage
From current directory,
Or specify a specific directory (that you're not currently in),