Skip to content

Commit 3dd53c0

Browse files
committed
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 <[email protected]>
1 parent 4b95b1e commit 3dd53c0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

contrib/vscode/init.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ die "Could not create .vscode/"
1313

1414
# General settings
1515

16-
cat >.vscode/settings.json <<\EOF ||
16+
cat >.vscode/settings.json.new <<\EOF ||
1717
{
1818
"C_Cpp.intelliSenseEngine": "Default",
1919
"C_Cpp.intelliSenseEngineFallback": "Disabled",
@@ -51,7 +51,7 @@ esac
5151

5252
# Default build task
5353

54-
cat >.vscode/tasks.json <<EOF ||
54+
cat >.vscode/tasks.json.new <<EOF ||
5555
{
5656
// See https://go.microsoft.com/fwlink/?LinkId=733558
5757
// for the documentation about the tasks.json format
@@ -73,7 +73,7 @@ die "Could not install default build task"
7373

7474
# Debugger settings
7575

76-
cat >.vscode/launch.json <<EOF ||
76+
cat >.vscode/launch.json.new <<EOF ||
7777
{
7878
// Use IntelliSense to learn about possible attributes.
7979
// Hover to view descriptions of existing attributes.
@@ -175,3 +175,20 @@ vscode-init:
175175
echo '}'
176176
EOF
177177
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

0 commit comments

Comments
 (0)