Sfoglia il codice sorgente

Fixes git search for #734

main
Eric Amodio 5 anni fa
parent
commit
030b6e7a5b
2 ha cambiato i file con 20 aggiunte e 4 eliminazioni
  1. +6
    -2
      src/git/locator.ts
  2. +14
    -2
      src/git/shell.ts

+ 6
- 2
src/git/locator.ts Vedi File

@ -12,10 +12,14 @@ function parseVersion(raw: string): string {
}
async function findSpecificGit(path: string): Promise<GitLocation> {
const version = await run<string>(path, ['--version'], 'utf8');
let version = await run<string>(path, ['--version'], 'utf8');
// If needed, let's update our path to avoid the search on every command
if (!path || path === 'git') {
path = findExecutable(path, ['--version']).cmd;
const foundPath = findExecutable(path, ['--version']).cmd;
// Ensure that the path we found works
version = await run<string>(foundPath, ['--version'], 'utf8');
path = foundPath;
}
return {

+ 14
- 2
src/git/shell.ts Vedi File

@ -25,17 +25,20 @@ function runDownPath(exe: string): string {
const target = paths.join('.', exe);
try {
if (fs.statSync(target)) return target;
const stats = fs.statSync(target);
if (stats && stats.isFile() && isExecutable(stats)) return target;
}
catch {}
const path = process.env.PATH;
if (path != null && path.length !== 0) {
const haystack = path.split(isWindows ? ';' : ':');
let stats;
for (const p of haystack) {
const needle = paths.join(p, exe);
try {
if (fs.statSync(needle)) return needle;
stats = fs.statSync(needle);
if (stats && stats.isFile() && isExecutable(stats)) return needle;
}
catch {}
}
@ -44,6 +47,15 @@ function runDownPath(exe: string): string {
return exe;
}
function isExecutable(stats: fs.Stats) {
if (isWindows) return true;
const isGroup = stats.gid ? process.getgid && stats.gid === process.getgid() : true;
const isUser = stats.uid ? process.getuid && stats.uid === process.getuid() : true;
return Boolean(stats.mode & 0o0001 || (stats.mode & 0o0010 && isGroup) || (stats.mode & 0o0100 && isUser));
}
/**
* Finds the executable and parameters to run on Windows. This method
* mimics the POSIX behavior of being able to run scripts as executables by

||||||
x
 
000:0
Caricamento…
Annulla
Salva