forked from scratchfoundation/scratch-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull_from_blockly.sh
executable file
·151 lines (135 loc) · 3.7 KB
/
pull_from_blockly.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# Pull from Blockly into Scratch Blocks and do basic cleanup.
# Rachel Fenichel (fenichel@google.com)
BOLD='\e[1m'
NOBOLD='\e[21m'
# Formatting helper.
empty_lines() { printf '\n\n'; }
bold_echo() {
echo -e "${BOLD}$1${NOBOLD}"
}
stop_on_fail() {
# Fail if any command fails.
set -e
# Even if you're piping the output.
set -o pipefail
}
# Undo the effects of start_failing.
continue_on_fail() {
set +e
set +o pipefail
}
# Prompt for y/n and put the result in $prompt_result
# The first argument specifies the text to use in the prompt.
# The second argument specifies which value to use if we're skipping prompts.
prompt() {
if [ $with_prompts ]
then
if [ $2 = true ]
then
paren_text="(Y/n)"
else
paren_text="(y/N)"
fi
# Prompt the user and retry if they try any funny business.
while true; do
read -p "$1 $paren_text > " yn
case $yn in
[Yy]* ) prompt_result=true; break;;
[Nn]* ) prompt_result=false; break;;
* ) echo "Please answer yes or no.";;
esac
done
else
# Running without prompts. Use the default value.
prompt_result=$2;
fi
}
# Ask the user for confirmation, then pull from Blockly's develop branch.
# The default is to do the pull.
pull_from_develop_fn() {
empty_lines
prompt "Do you want to pull from develop?" true
if [ $prompt_result = false ]
then
bold_echo "You don't want to pull from develop. Why are you running this script?"
exit
fi
bold_echo "Pulling from Blockly's develop branch"
sleep .5
# This pull will likely fail with merge conflicts, but that's okay.
# However, this means that we won't fail on errors other than merge conflicts.
continue_on_fail
git pull https://github.com/google/blockly.git develop
stop_on_fail
}
# Ask the user for confirmation, then run cleanup.
# The default is to run cleanup.
run_cleanup_fn() {
empty_lines
prompt "Ready to run cleanup.sh. Continue?" true
if [ $prompt_result = false ]
then
bold_echo "Skipping cleanup.sh"
prompt_for_merge_abort
empty_lines
bold_echo "Done"
exit
fi
bold_echo "Running cleanup.sh"
sleep .5
# Cleanup.sh resolves common conflicts.
./cleanup.sh
}
# Ask the user for confirmation, then possibly abort the merge.
# The default is to *not* abort the merge.
# Used to clean up the repo instead of leaving it in a bad state.
prompt_for_merge_abort() {
empty_lines
prompt "Do you want to abort this merge?" false
if [ $prompt_result = false ]
then
bold_echo "Continuing with merge..."
else
bold_echo "Running git merge --abort"
git merge --abort
display_status_fn
bold_echo "Done"
exit
fi
}
# Ask the user for confirmation, then show the current repo status.
# The default to to show status.
display_status_fn() {
empty_lines
prompt "Do you want to display the current status?" true
if [ $prompt_result = true ]
then
# Tell the user the current state.
bold_echo "Current status"
sleep .5
git status
else
bold_echo "Skipping status display."
fi
}
# Give the user one more chance to abort the merge, then tell them what their
# next steps should be.
finish_fn() {
prompt_for_merge_abort
bold_echo "Done. You may need to manually resolve conflicts."
# Helpful tips about what to do next.
empty_lines
sleep .5
echo "Fix conflicts and run 'git commit'."
echo "Use 'git add <file>' to mark resolution."
echo "Use 'git merge --abort' to abort this merge."
}
# Check whether we're running with prompts. If unset, we'll skip all prompts.
with_prompts=$1
# Here we go!
stop_on_fail
pull_from_develop_fn
run_cleanup_fn
display_status_fn
finish_fn