22
33set -Eeuo pipefail
44
5- function remove_patches() {
5+ function quiet() {
6+ " $@ " > /dev/null
7+ }
8+
9+ function indent() {
10+ local count=${1-2}
11+ local space
12+ space=$( printf " %${count} s" )
13+ sed " s/^/$space | /g"
14+ }
15+
16+ function unapply_patches() {
617 local -i exit_code=0
7- quilt pop -af || exit_code=$?
18+ quiet quilt pop -af || exit_code=$?
819 case $exit_code in
9- # Sucessfully removed .
20+ # Sucessfully unapplied .
1021 0) ;;
11- # No more patches to remove .
22+ # No more patches to unapply .
1223 2) ;;
1324 # Some error.
1425 * ) return $exit_code ;;
@@ -17,7 +28,7 @@ function remove_patches() {
1728
1829function update_vscode() {
1930 pushd lib/vscode
20- if ! git checkout " $target_vscode_version " ; then
31+ if ! git checkout 2>&1 " $target_vscode_version " ; then
2132 echo " $target_vscode_version does not exist locally, fetching..."
2233 git fetch --all --prune
2334 git checkout " $target_vscode_version "
@@ -27,9 +38,8 @@ function update_vscode() {
2738
2839function refresh_patches() {
2940 local -i exit_code=0
30- while quilt push ; ! (( exit_code= $? )) ; do
41+ while quiet quilt push ; ! (( exit_code= $? )) ; do
3142 quilt refresh
32- echo # Extra new line for separation.
3343 done
3444 case $exit_code in
3545 # No more patches to apply.
@@ -43,7 +53,7 @@ function update_node() {
4353 local node_version
4454 node_version=$( cat .node-version)
4555 if [[ $node_version == " $target_node_version " ]] ; then
46- echo " $node_version already matches $target_node_version "
56+ echo " Already set to $target_node_version "
4757 else
4858 echo " Updating from $node_version to $target_node_version ..."
4959 echo " $target_node_version " > .node-version
@@ -61,26 +71,42 @@ function get-webview-script-hash() {
6171}
6272
6373function update_csp() {
64- local -i exit_code=0
65- # Move back to the webview patch so it can be refreshed.
66- quilt pop webview || exit_code=$?
67- case $exit_code in
68- # Successfully moved.
69- 0) ;;
70- # Already at the patch.
71- 2) ;;
72- # Some error.
73- * ) return $exit_code ;;
74- esac
74+ local current=$( quilt top 2> /dev/null || echo " " )
75+ local patch_action=" "
76+ echo " Currently at ${current:- base} "
77+ if [[ $current != * /webview.diff ]] ; then
78+ echo " Moving to patches/webview.diff..."
79+ local -i exit_code=0
80+ if quilt applied 2> /dev/null | grep --quiet webview.diff ; then
81+ quiet quilt pop webview || exit_code=$?
82+ patch_action=pop
83+ else
84+ quiet quilt push webview || exit_code=$?
85+ patch_action=push
86+ fi
87+ case $exit_code in
88+ # Successfully moved.
89+ 0) ;;
90+ # Some error.
91+ * ) return $exit_code ;;
92+ esac
93+ fi
94+
7595 local file=lib/vscode/src/vs/workbench/contrib/webview/browser/pre/index.html
7696 local hash
7797 hash=$( get-webview-script-hash " $file " )
7898 echo " Calculated hash as $hash "
7999 # Use octothorpe as a delimiter since the hash may contain a slash.
80100 sed -i.bak " s#script-src 'sha256-[^']\+'#script-src 'sha256-$hash '#" " $file "
81101 quilt refresh
82- # Get patched back up.
83- quilt push -a
102+
103+ if [[ $patch_action != " " ]] ; then
104+ echo " Moving back to ${current:- base} ..."
105+ case $patch_action in
106+ pop) quiet quilt push " $current " ;;
107+ push) quiet quilt pop " ${current:- -a} " ;;
108+ esac
109+ fi
84110}
85111
86112function run() {
@@ -91,8 +117,8 @@ function run() {
91117 local fn=$1 ; shift
92118 # Only run if an earlier step has not failed.
93119 if [[ $failed == 0 ]] ; then
94- echo " [+] $name ..."
95- if $fn ; then
120+ echo " $name ..."
121+ if $fn | indent ; then
96122 echo " - [X] $name " >> .cache/checklist
97123 else
98124 (( failed++ ))
@@ -110,7 +136,7 @@ function run() {
110136
111137function add_changelog() {
112138 local file=CHANGELOG.md
113- if grep " Code $target_vscode_version " " $file " ; then
139+ if grep --quiet " Code $target_vscode_version " " $file " ; then
114140 echo " Changelog for $target_vscode_version already exists"
115141 else
116142 # TODO: This is not exactly robust. In particular, it needs to handle if
@@ -127,19 +153,28 @@ function main() {
127153 local target_node_version
128154 target_node_version=$( grep target lib/vscode/remote/.npmrc | awk -F= ' {print $2}' | tr -d ' "' )
129155
130- local target_vscode_version
131- target_vscode_version=" ${VERSION# v} "
132-
133156 declare -a steps
134- # Removing patches only needs to be done locally; in CI we start from a fresh
135- # clone each time.
136- if [[ ! ${CI-} ]] ; then
137- steps+=(" Remove patches" " remove_patches" )
157+
158+ # If version is not set, assume we are already at the target version and the
159+ # user is just trying to resolve conflics.
160+ local target_vscode_version
161+ if [[ ${VERSION-} ]] ; then
162+ # Removing patches only needs to be done locally; in CI we start from a
163+ # fresh clone each time.
164+ if [[ ! ${CI-} ]] ; then
165+ steps+=(" Unapplying patches" " unapply_patches" )
166+ fi
167+ target_vscode_version=" ${VERSION# v} "
168+ steps+=(
169+ " Update VS Code to $target_vscode_version " " update_vscode"
170+ " Refresh VS Code patches" " refresh_patches"
171+ )
172+ else
173+ target_vscode_version=" $( git -C lib/vscode describe --tags --exact-match) "
174+ echo " Detected VS Code version $target_vscode_version "
138175 fi
139176
140177 steps+=(
141- " Update VS Code to $target_vscode_version " " update_vscode"
142- " Refresh VS Code patches" " refresh_patches"
143178 " Set Node version to $target_node_version " " update_node"
144179 " Update CSP webview hash" " update_csp"
145180 " Add changelog note" " add_changelog"
0 commit comments