forked from pupil-labs/pupil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate
executable file
·52 lines (39 loc) · 1.25 KB
/
update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#
# Usage: pull
#
# Pulls remote changes using rebase & tries to rebundle,
# safely stashing and re-applying your local changes, if any
#
function do_update(){
# Update our remote
echo "Fetching from $remote ..."
git fetch $remote || exit $?
# Pull, using rebase if configured
rebase="--rebase" # TODO disable if env-var is set
git pull $rebase $remote $remote_branch || exit $?
# Update submodules
git submodule update || exit $?
echo "Done"
}
cd $(dirname $0)
branch=$(git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') || exit $?
default_remote="origin"
remote=$(git config "branch.${branch}.remote" || echo "$default_remote")
remote_branch=$( (git config "branch.${branch}.merge" || echo "refs/heads/$branch") | awk -F '/' '{ print $3 }' )
# Stash any local changes
stash=$(git stash)
if [[ "$stash" =~ "No local changes to save" ]]; then
do_update
exit 0
fi
echo "You have made changes to the source code. Do you want to continue the update and have them saved in a WIP stash?"
read -p "Type: Yes/No" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]] ; then
do_update
exit 0
fi
git stash pop
echo "Aborted the Update, nothing changed"
exit 1