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.

53 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 init
  29. git submodule update
  30. #Since we updated, we should execute the bootstrapper again.
  31. $ENV bash $GIT_DIR/scripts/bootstrap.sh
  32. # Local changes exist, we need to push these before we can cleanly update
  33. elif [ $REMOTE = $BASE ]; then
  34. echo "Local changes, need to push before updating."
  35. exit 1
  36. # Divereged branches, this will need a manual cleanup to fix
  37. else
  38. echo "Error: Diverged Branches. Resolve Manually"
  39. exit 1
  40. fi
  41. echo "Finished dotfiles update check!"
  42. # Return to where we started incase this was sourced from another script
  43. cd $owpd