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.

48 lines
1.3 KiB

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