Skip to content

Commit cd22e17

Browse files
Restore repo-tracked files after copying test binaries (#14632)
The install/copy-binaries script rm -rf's and re-copies the installed extension's bin, debugAdapters, and LLVM folders. A few files under bin are checked into the repo (bin/cpp.hint and bin/messages/**/messages.json); the copy overwrote them with the installed extension's versions (differing line endings and/or content), leaving spurious local modifications that had to be reverted by hand. Restore any tracked files the copy changed so only the untracked binaries remain, and gitignore the generated bin/binaryVersion.json marker. Co-authored-by: Colen Garoutte-Carson <49173979+Colengms@users.noreply.github.com>
1 parent 2d5e77c commit cd22e17

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

Extension/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ server
1010
debugAdapters
1111
LLVM
1212
bin/assert_dialog.sh
13+
bin/binaryVersion.json
1314
bin/cpptools*
1415
bin/edge_cli
1516
bin/isense_driver

Extension/.scripts/copyExtensionBinaries.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { cp, readdir, rm, stat } from 'node:fs/promises';
77
import { homedir } from 'node:os';
88
import { basename, join } from 'node:path';
99
import { verbose } from '../src/Utility/Text/streams';
10-
import { $args, $root, green, heading, note } from './common';
10+
import { $args, $root, Git, green, heading, note, warn } from './common';
1111

1212
const extensionPrefix = 'ms-vscode.cpptools-';
1313
const foldersToCopy = ['bin', 'debugAdapters', 'LLVM'] as const;
@@ -125,6 +125,33 @@ async function findLatestInstalledExtension(providedPath?: string): Promise<stri
125125
return installed[0].path;
126126
}
127127

128+
/**
129+
* A few files inside the copied folders are checked into the repo (for example bin/cpp.hint and
130+
* bin/messages/**). The copy overwrites them with the installed extension's versions, which can differ
131+
* in line endings or content and then show up as spurious local modifications. Restore any tracked files
132+
* that the copy changed so only the untracked binaries remain in the working tree.
133+
*/
134+
async function restoreTrackedFiles(): Promise<void> {
135+
const modified = await Git('ls-files', '--modified', '--', ...foldersToCopy);
136+
if (modified.code) {
137+
warn(`Unable to determine which tracked files to restore: ${modified.error.all().join('\n')}`);
138+
return;
139+
}
140+
141+
const files = modified.stdio.all().map(line => line.trim()).filter(line => line.length > 0);
142+
if (!files.length) {
143+
return;
144+
}
145+
146+
const restored = await Git('checkout', '--', ...files);
147+
if (restored.code) {
148+
warn(`Unable to restore tracked files after copy: ${restored.error.all().join('\n')}`);
149+
return;
150+
}
151+
152+
note(`Restored ${files.length} tracked ${files.length === 1 ? 'file' : 'files'} overwritten by the copy.`);
153+
}
154+
128155
export async function main(sourcePath = $args[0]): Promise<string | undefined> {
129156
console.log(heading('Copy installed extension binaries'));
130157

@@ -142,6 +169,8 @@ export async function main(sourcePath = $args[0]): Promise<string | undefined> {
142169

143170
note(`Copied installed binaries into ${$root}`);
144171

172+
await restoreTrackedFiles();
173+
145174
const installedVersion = tryParseVersion(basename(installedExtensionPath));
146175
return installedVersion?.join('.');
147176
}

0 commit comments

Comments
 (0)