-
Notifications
You must be signed in to change notification settings - Fork 6
/
update_functions.sh
executable file
·108 lines (88 loc) · 2.05 KB
/
update_functions.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
function gitcheckout {
dir=$1
branch=$2
remote=$3
if [ ! "$(ls -A $dir)" ]; then
# Empty directory
update_exec "git submodule sync --recursive"
update_exec "git submodule update --init --recursive"
if [ ! "$(ls -A $dir)" ]; then
echo 'ERROR: el directori $dir no existeix o és buit'
exit -1
fi
fi
echo "Entrant $dir BRANCH $branch REPO $remote ..."
pushd $dir > /dev/null
if [ ! -z "$remote" ]; then
update_exec "git remote set-url origin $remote"
update_exec "git fetch"
fi
update_exec "git checkout $branch"
git_pull $branch
popd > /dev/null
echo 'OK'
}
function git_pull {
branch=$1
if [[ $action == 'stash' ]]
then
update_exec "git stash"
fi
if [[ $action == 'reset' ]]
then
update_exec "git reset --hard origin/$branch"
fi
update_exec "git pull"
if [[ $action == 'stash' ]]
then
if [[ -n $(git stash list) ]]; then
echo ' >>>> Aplicat Stash'
update_exec "git stash pop"
fi
fi
if [[ $action == 'gc' ]]
then
update_exec "git gc"
fi
}
function update_exec {
if ! $1 > /dev/null
then
echo >&2 "ERROR: on $1"
exit -2
fi
}
function get_action {
tempaction=$1
if [[ $tempaction == 'reset' ]]
then
echo 'Demanat RESET'
action=$tempaction
elif [[ $tempaction == 'stash' ]]
then
echo 'Demanat STASH'
action=$tempaction
elif [[ $tempaction == 'gc' ]]
then
echo 'Demanat GC'
action=$tempaction
else
action=""
fi
}
function pull_submodules {
if [[ $action != 'reset' ]]
then
echo 'Inicialitzant submòduls...'
update_exec "git submodule update --recursive --init"
echo 'Sincronitzant submòduls...'
update_exec "git submodule sync"
fi
./update_submodules.sh
}
function end_exec {
echo "Garbage collecting..."
git gc
echo "That's all folks!"
}