-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpull.sh
62 lines (49 loc) · 1.18 KB
/
pull.sh
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
51
52
53
54
55
56
57
58
59
60
61
62
# !/bin/bash
######################
# bash pull.sh -r branch remote
# $1 - rebase( -r = rebase | -nr = no rebase)
# $2 - set up another branch
# $3 - if branch set up, you have to set up origin
######################
### variables
#
CUR_DIR=$(pwd)
BASE_DIR=$(git rev-parse --show-cdup)
BRANCH=$(git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ $1 == "-r" ]; then
REBASE="--rebase"
else
REBASE=""
fi
if [ -z $3 ];then
REMOTE="origin"
else
REMOTE=$3
fi
if [ -z $2 ]; then
read -p "You will pull $BRANCH. Do you want to continue (yes / no)?" answ
case $answ in
[Yy]* ) echo "Continue..."; ;;
[Nn]* ) echo "Set up branch"; read -p "You will pull $BRANCH. Do you want to continue (yes / no)?" BRANCH;;
* ) echo "Please answer yes or no";;
esac
fi
# pop stashes
if [[ ! "$stash" =~ "No local changes to save" ]]; then
echo "Popping stash..."
git stash pop
fi
# update remote
# echo "Fetching from $REMOTE..."
echo "Fetching from $REMOTE..."
git fetch $REMOTE $BRANCH
# git fetch $REMOTE
# pull, using rebase if configured
if [ -z $REBASE ]; then
git pull $REBASE $REMOTE $BRANCH
else
git pull $REMOTE $BRANCH
fi
git submodule update
echo "Done"
exit 0