-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
35 lines (26 loc) · 963 Bytes
/
update.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
# TEST: Check if this function works correctly
shell_fns_update() {
local behind_count older_pwd current_branch
older_pwd=$(pwd)
# shellcheck disable=SC2164
return_older_pwd() { cd "${older_pwd}"; }
# shellcheck disable=SC2164
cd "${SF_PATH}"
echo -e "${LIGHTBLUE}[ SHELL-FNS ]: UPDATING...${NOCOLOR}"
current_branch=$(git branch --show-current)
if [[ $current_branch != 'master' ]]; then
echo -e "${LIGHTRED}Not on master. Aborting...${NOCOLOR}"
return_older_pwd
return
fi
echo -e "${LIGHTGREEN}Checking remote repo...${NOCOLOR}"
behind_count=$(git rev-list --right-only --count "HEAD...@{upstream}")
if ((behind_count > 0)); then
echo -e "${ORANGE}Not up to date with origin. Upgrading...${NOCOLOR}"
git pull --quiet &&
echo -e "${LIGHTGREEN}Shell-fns has been updated!"
else
echo -e "${LIGHTGREEN}[ SHELL-FNS ]: Up to date with latest version. Aborting...${NOCOLOR}"
fi
return_older_pwd
}