diff --git a/scripts/.update_dotfiles.sh b/scripts/.update_dotfiles.sh index 1cbe53a..8ec8034 100755 --- a/scripts/.update_dotfiles.sh +++ b/scripts/.update_dotfiles.sh @@ -1,6 +1,34 @@ #!/usr/bin/env sh -echo 'Updating dotfiles' -cd @GIT_DIR@ -git checkout master -git pull -git submodule update + +# Update the status of the origin +git remote update origin + +# Check if we need to update at all +# Kindly borrowed from http://stackoverflow.com/questions/3258243/git-check-if-pull-needed +LOCAL=$(git rev-parse @) +REMOTE=$(git rev-parse @{u}) +BASE=$(git merge-base @ @{u}) + +# All good, no need to update +if [ $LOCAL = $REMOTE ]; then + echo "Up-to-date" + exit 0 +# Time to update to the remote branch +elif [ $LOCAL = $BASE ]; then + echo "Need to pull" + echo 'Updating dotfiles' + opwd=$PWD + cd @GIT_DIR@ + git checkout master + git pull + git submodule update + cd $owpd +# Local changes exist, we need to push these before we can cleanly update +elif [ $REMOTE = $BASE ]; then + echo "Local changes, need to push before updating." + exit 1 +# Divereged branches, this will need a manual cleanup to fix +else + echo "Error: Diverged Branches. Resolve Manually" + exit 1 +fi