You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB

  1. #!/usr/bin/env bash
  2. ENV=/usr/bin/env
  3. # Need to move into the git directory to perform the checks
  4. opwd=$PWD
  5. GIT_DIR="@GIT_DIR@"
  6. cd $GIT_DIR
  7. # Update the status of the origin
  8. # No need to print the result, this should be silent and invisible
  9. git remote update origin 1>/dev/null
  10. # Check if we need to update at all
  11. # Kindly borrowed from http://stackoverflow.com/questions/3258243/git-check-if-pull-needed
  12. LOCAL=$(git rev-parse @)
  13. REMOTE=$(git rev-parse @{u})
  14. BASE=$(git merge-base @ @{u})
  15. # Exit if for some reason we don't get info from the remote.
  16. if [ -z "$REMOTE" ]; then
  17. exit 0
  18. fi
  19. # All good, no need to update
  20. if [ $LOCAL = $REMOTE ]; then
  21. # No need to declare anything while we do this
  22. exit 0
  23. # Time to update to the remote branch
  24. elif [ $LOCAL = $BASE ]; then
  25. echo "Updating dotfiles in: $PWD"
  26. git checkout master
  27. git pull
  28. git submodule update
  29. #Since we updated, we should execute the bootstrapper again.
  30. $ENV bash $GIT_DIR/scripts/bootstrap.sh
  31. # Local changes exist, we need to push these before we can cleanly update
  32. elif [ $REMOTE = $BASE ]; then
  33. echo "Local changes, need to push before updating."
  34. exit 1
  35. # Divereged branches, this will need a manual cleanup to fix
  36. else
  37. echo "Error: Diverged Branches. Resolve Manually"
  38. exit 1
  39. fi
  40. # Return to where we started incase this was sourced from another script
  41. cd $owpd