vscode: only overwrite C/C++ settings
The C/C++ settings are special, as they are the only generated VS Code configurations that *will* change over the course of Git's development, e.g. when a new constant is defined. Therefore, let's only update the C/C++ settings, also to prevent user modifications from being overwritten. Ideally, we would keep user modifications in the C/C++ settings, but that would require parsing JSON, a task for which a Unix shell script is distinctly unsuited. So we write out .new files instead, and warn the user if they may want to reconcile their changes. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jul 30, 2018 at 08:42 UTC
0f47f78e02d16e6edd0448285815ccc1744294e8
1 file changed
+20
-3
contrib/vscode/init.sh
+20
-3
@@ -13,7 +13,7 @@ die "Could not create .vscode/"
13
14
# General settings
15
16
-cat >.vscode/settings.json <<\EOF ||
16
+cat >.vscode/settings.json.new <<\EOF ||
17
{
18
"C_Cpp.intelliSenseEngine": "Default",
19
"C_Cpp.intelliSenseEngineFallback": "Disabled",
@@ -51,7 +51,7 @@ esac
51
52
# Default build task
53
54
-cat >.vscode/tasks.json <<EOF ||
54
+cat >.vscode/tasks.json.new <<EOF ||
55
{
56
// See https://go.microsoft.com/fwlink/?LinkId=733558
57
// for the documentation about the tasks.json format
@@ -73,7 +73,7 @@ die "Could not install default build task"
73
74
# Debugger settings
75
76
-cat >.vscode/launch.json <<EOF ||
76
+cat >.vscode/launch.json.new <<EOF ||
77
{
78
// Use IntelliSense to learn about possible attributes.
79
// Hover to view descriptions of existing attributes.
@@ -175,3 +175,20 @@ vscode-init:
175
echo '}'
176
EOF
177
die "Could not write settings for the C/C++ extension"
178
+
179
+for file in .vscode/settings.json .vscode/tasks.json .vscode/launch.json
180
+do
181
+ if test -f $file
182
+ then
183
+ if git diff --no-index --quiet --exit-code $file $file.new
184
+ then
185
+ rm $file.new
186
+ else
187
+ printf "The file $file.new has these changes:\n\n"
188
+ git --no-pager diff --no-index $file $file.new
189
+ printf "\n\nMaybe \`mv $file.new $file\`?\n\n"
190
+ fi
191
+ else
192
+ mv $file.new $file
193
+ fi
194
+done