Browse Source

Adds protection/logging for unsafe repositories

main
Eric Amodio 1 year ago
parent
commit
d2950cdbe6
1 changed files with 11 additions and 0 deletions
  1. +11
    -0
      src/env/node/git/git.ts

+ 11
- 0
src/env/node/git/git.ts View File

@ -1604,6 +1604,17 @@ export class Git {
// Keep trailing spaces which are part of the directory name
return data.length === 0 ? undefined : normalizePath(data.trimStart().replace(/[\r|\n]+$/, ''));
} catch (ex) {
const unsafeMatch =
/^fatal: detected dubious ownership in repository at '([^']+)'[\s\S]*git config --global --add safe\.directory '?([^'\n]+)'?$/m.exec(
ex.stderr,
);
if (unsafeMatch?.length === 3) {
Logger.log(
`Skipping; unsafe repository detected in '${unsafeMatch[1]}'; run 'git config --global --add safe.directory ${unsafeMatch[2]}' to allow it`,
);
return undefined;
}
const inDotGit = /this operation must be run in a work tree/.test(ex.stderr);
// Check if we are in a bare clone
if (inDotGit && workspace.isTrusted) {

Loading…
Cancel
Save