simple repo updater
This file contains 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/env bash | |
# `gitup.repos` is a text file | |
# with one absolute path per line | |
if [ ! -e ./gitup.repos ]; then | |
echo "No repo list (gitup.repos) found!" | |
exit 1; | |
fi | |
while read repoDir; do | |
if [ "$repoDir" == "" ]; then | |
echo "Empty line in gitup.repos found. Skipping..." | |
continue | |
fi | |
echo "Entering $repoDir" | |
cd "$repoDir" | |
# making sure branch is master | |
git checkout master | |
if [ $? -ne 0 ]; then | |
echo "Dirty working directory! Stashing..." | |
BRANCH=$(git stash | line | sed -rn 's/Saved working directory and index state WIP on (.*): .*/\1/p') | |
git checkout master | |
fi | |
echo "Pulling from 'origin' remote..." | |
git pull origin master | |
if [ "$BRANCH" != "" ]; then | |
echo "Returning to branch: $BRANCH" | |
git checkout $BRANCH | |
echo "Popping stash..." | |
git stash pop | |
fi | |
done < ./gitup.repos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment