UNPKG

1.4 kBapplication/x-shView Raw
1#!/usr/bin/env bash
2set -eE
3
4REPO_DIR=$1
5REPO=$(basename $1)
6ORG_DIR=$(dirname $1)
7ORG=$(basename $ORG_DIR)
8NAME="$ORG/$REPO"
9PROJECT_NAME=$2
10if [[ -z "$PROJECT_NAME" ]]; then
11 PROJECT_NAME=$REPO
12fi
13
14GROWL_NOTIFY="$(dirname $0)/growl-notify.sh"
15notify () {
16 $GROWL_NOTIFY "$@" >/dev/null 2>&1 &
17}
18
19lockfile=/tmp/octoblu-dev-git-prompt-${PROJECT_NAME}.lock
20"$(dirname $0)/lock.sh" $lockfile 'git-prompt'
21
22mkdir -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)
58rm $lockfile