-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull-down-work-changes.sh
executable file
·68 lines (51 loc) · 1.25 KB
/
pull-down-work-changes.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
#!/usr/bin/env zsh
YELLOW='\033[1;33m'
RED='\033[0;31m'
NO_COLOR='\033[0m'
logInfo() {
echo -e "${YELLOW}$1${NO_COLOR}"
}
logError() {
echo -e "${RED}$1${NO_COLOR}"
}
any_local_changes() {
git diff --quiet HEAD
return $?
}
any_conflicts() {
git status | grep conflict
}
rebase_off_master() {
logInfo "Checking for any local changes"
LOCAL_CHANGES=false
if [[ "$(any_local_changes)" != "0" ]]; then
LOCAL_CHANGES=true
logInfo "Stashing changes for now..."
git stash
fi
logInfo "Pulling down latest changes for master and rebasing..."
git fetch && git rebase origin/master
logInfo "Installing dependencies"
npm install
if [ "$LOCAL_CHANGES" = true ]; then
logInfo "Restoring the local changes that were stashed..."
git stash pop
fi
FINAL_MSG="Finished with updates"
if any_conflicts; then
$FINAL_MSG="There are conflicts after updating"
fi
terminal-notifier -message $FINAL_MSG
}
#=================================
logInfo "Switching to work directory..."
cd $WORK_DIRECTORY
if [ $? != 0 ]; then
logError "Directory configured in script is invalid"
exit 1
fi
if [[ "$NO_REBASE" = true ]]; then
logInfo "\$NO_REBASE=true, skipping pulling changes from master"
else
rebase_off_master
fi