Skip to content

Instantly share code, notes, and snippets.

@janlay
Last active April 16, 2019 13:08
Show Gist options
  • Save janlay/ba260ff4b5362fad5876 to your computer and use it in GitHub Desktop.
Save janlay/ba260ff4b5362fad5876 to your computer and use it in GitHub Desktop.
Updates all Git repos in directory, defaults to Vim bundles.
#!/bin/bash
# author: [email protected]
WORKDING_DIR="${1-$HOME/.vim/bundle}"
GIT_DIR_ROOT="$HOME/Workspace/.gitrepo"
echo "Working on $WORKDING_DIR"
for i in `find "$WORKDING_DIR" -mindepth 1 -maxdepth 1 -type d`; do
REPO_NAME="${i##*/}"
export GIT_WORK_TREE="$WORKDING_DIR/$REPO_NAME"
export GIT_DIR="$GIT_WORK_TREE/.git"
[ -d "$GIT_DIR" ] || export GIT_DIR="$GIT_DIR_ROOT/$REPO_NAME"
[ -d "$GIT_DIR" ] || continue
# echo "DEBUG: $i, $REPO_NAME, $GIT_WORK_TREE, $GIT_DIR"
echo -en "\r\033[2K⛳️ Checking \033[0;34m$REPO_NAME\033[0m ... "
# Check tracking branch
git rev-parse --abbrev-ref @{upstream} > /dev/null 2> /dev/null
if [ $? -gt 0 ]; then
echo -n "Tracking branch required"
continue
fi
# Check if updates are available
git fetch --quiet
if [ "$(git rev-parse HEAD)" == "$(git rev-parse @{u})" ]; then
continue
fi
# Start updating
echo "Updates available"
git pull --recurse-submodules 2>&1 | sed 's/^/ /'
[ -f "$GIT_DIR/.gitmodules" ] && (git submodule update 2>&1 | sed 's/^/ /')
done
unset GIT_WORK_TREE
unset GIT_DIR
echo -e "\r\033[2KAll done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment