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.

47 lines
1.1KB

  1. #!/bin/bash
  2. SOURCE="${BASH_SOURCE[0]}"
  3. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  4. TARGET="$(readlink "$SOURCE")"
  5. if [[ $TARGET == /* ]]; then
  6. #echo "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'"
  7. SOURCE="$TARGET"
  8. else
  9. DIR="$( dirname "$SOURCE" )"
  10. #echo "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR')"
  11. SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  12. fi
  13. done
  14. SRPATH="$( dirname "$SOURCE" )"
  15. SFPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  16. if [ "$SFPATH" != "$SRPATH" ]; then
  17. RDIR=$SRPATH # relativ path directory
  18. fi
  19. cwdir=$PWD
  20. wdir=$SFPATH
  21. if [ "$cwdir" != "$wdir" ]; then
  22. cd $wdir
  23. fi
  24. git fetch
  25. UPSTREAM=${1:-'@{u}'}
  26. LOCAL=$(git rev-parse @)
  27. REMOTE=$(git rev-parse "$UPSTREAM")
  28. BASE=$(git merge-base @ "$UPSTREAM")
  29. if [ $LOCAL = $REMOTE ]; then
  30. echo "Up-to-date"
  31. elif [ $LOCAL = $BASE ]; then
  32. echo "Update swarmlab hybrid ..."
  33. git pull origin
  34. elif [ $REMOTE = $BASE ]; then
  35. echo "Need to push"
  36. else
  37. echo "Diverged"
  38. fi
  39. cd $cwdir