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.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. #echo $cwdir
  25. git fetch
  26. UPSTREAM=${1:-'@{u}'}
  27. LOCAL=$(git rev-parse @)
  28. REMOTE=$(git rev-parse "$UPSTREAM")
  29. BASE=$(git merge-base @ "$UPSTREAM")
  30. if [ $LOCAL = $REMOTE ]; then
  31. echo "Up-to-date"
  32. elif [ $LOCAL = $BASE ]; then
  33. echo "Update swarmlab hybrid ..."
  34. git pull origin
  35. elif [ $REMOTE = $BASE ]; then
  36. echo "Need to push"
  37. else
  38. echo "Diverged"
  39. fi
  40. cd $cwdir