1 | #!/usr/bin/env bash
|
2 | set -eE
|
3 |
|
4 | REPO_DIR=$1
|
5 | REPO=$(basename $1)
|
6 | ORG_DIR=$(dirname $1)
|
7 | ORG=$(basename $ORG_DIR)
|
8 | NAME="$ORG/$REPO"
|
9 | PROJECT_NAME=$2
|
10 | if [[ -z "$PROJECT_NAME" ]]; then
|
11 | PROJECT_NAME=$REPO
|
12 | fi
|
13 |
|
14 | GROWL_NOTIFY="$(dirname $0)/growl-notify.sh"
|
15 | notify () {
|
16 | $GROWL_NOTIFY "$@" >/dev/null 2>&1 &
|
17 | }
|
18 |
|
19 | lockfile=/tmp/octoblu-dev-git-prompt-${PROJECT_NAME}.lock
|
20 | "$(dirname $0)/lock.sh" $lockfile 'git-prompt'
|
21 |
|
22 | mkdir -p "$ORG_DIR" 2>/dev/null
|
23 | (
|
24 | if [[ ! -d "$REPO_DIR" ]]; then
|
25 | notify "{\"text\":\"$PROJECT_NAME\",\"options\":{\"title\":\"? git clone\"}}"
|
26 | echo "¡ERROR: Project directory $NAME does not exist!"
|
27 | echo
|
28 | read -s -p "press 'y' to clone or any other key to abort"$'\n' -n 1 GIT_CLONE
|
29 | if [[ "$GIT_CLONE" == "y" ]]; then
|
30 | cd "$ORG_DIR"
|
31 | git clone git@github.com:$NAME
|
32 | else
|
33 | rm $lockfile
|
34 | exit -1
|
35 | fi
|
36 | fi
|
37 | )
|
38 | (
|
39 | cd "$REPO_DIR"
|
40 | git fetch origin
|
41 | GIT_LOG_CMD="git log HEAD..origin/master --oneline"
|
42 | GIT_LOG="$($GIT_LOG_CMD)"
|
43 | if [[ -n "$GIT_LOG" ]]; then
|
44 | notify "{\"text\":\"$PROJECT_NAME\",\"options\":{\"title\":\"? git pull\"}}"
|
45 | echo "¡WARNING: $NAME is behind remote!"
|
46 | echo
|
47 | echo "$GIT_LOG"
|
48 | echo
|
49 | read -s -p "press 'y' to pull, any other key to continue"$'\n' -n 1 GIT_PULL
|
50 | if [[ "$GIT_PULL" == "y" ]]; then
|
51 | echo "pulling..."
|
52 | git pull
|
53 | fi
|
54 | else
|
55 | echo "+ $NAME is up to date"
|
56 | fi
|
57 | )
|
58 | rm $lockfile
|