@gitkraken/core-gitlens 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -1
- package/dist/git/providers/config.d.ts +8 -0
- package/dist/git/service.d.ts +2 -1
- package/dist/git/service.js +2 -1
- package/dist/git/service.js.map +1 -1
- package/dist/git/watching/worktreeSummary.d.ts +3 -2
- package/dist/git/watching/worktreeSummary.js +4 -3
- package/dist/git/watching/worktreeSummary.js.map +1 -1
- package/dist/git-cli/cliGitProvider.js +1 -1
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/exec/git.d.ts +17 -1
- package/dist/git-cli/exec/git.js +48 -6
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/indexLock.d.ts +2 -0
- package/dist/git-cli/exec/indexLock.js +2 -2
- package/dist/git-cli/exec/indexLock.js.map +1 -1
- package/dist/git-cli/providers/config.d.ts +4 -1
- package/dist/git-cli/providers/config.js +30 -40
- package/dist/git-cli/providers/config.js.map +1 -1
- package/dist/git-cli/providers/pausedOperations.js +7 -3
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/package.json +1 -1
|
@@ -66,7 +66,7 @@ function isIndexWriteCommand(args) {
|
|
|
66
66
|
* prints the same line from its own git command and fails makes the run exit 1, after the hook's work is done.
|
|
67
67
|
*/
|
|
68
68
|
function isIndexLockHeldError(ex) {
|
|
69
|
-
return ex instanceof RunError && !(ex instanceof CancelledRunError) && toExitCode(ex.code) ===
|
|
69
|
+
return ex instanceof RunError && !(ex instanceof CancelledRunError) && toExitCode(ex.code) === 128 && indexLockHeldRegex.test(ex.stderr);
|
|
70
70
|
}
|
|
71
71
|
/** Resolves after `ms`, or rejects as soon as `signal` aborts. */
|
|
72
72
|
async function delay(ms, signal) {
|
|
@@ -169,6 +169,6 @@ function waitFor(promise, signal) {
|
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
//#endregion
|
|
172
|
-
export { KeyedSequencer, indexLockRetryDelays, isConfigCommand, isConfigLockHeldError, isIndexLockHeldError, isIndexWriteCommand, retryWhileConfigLocked, retryWhileIndexLocked, toExitCode };
|
|
172
|
+
export { KeyedSequencer, gitFatalExitCode, indexLockRetryDelays, isConfigCommand, isConfigLockHeldError, isIndexLockHeldError, isIndexWriteCommand, retryWhileConfigLocked, retryWhileIndexLocked, toExitCode };
|
|
173
173
|
|
|
174
174
|
//# sourceMappingURL=indexLock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexLock.js","names":["wait"],"sources":["../../../../git-cli/src/exec/indexLock.ts"],"sourcesContent":["import { setTimeout as wait } from 'timers/promises';\nimport { leadingCommand } from './commandClassifier.js';\nimport { CancelledRunError, RunError } from './exec.errors.js';\nimport { abortReason } from './gitQueue.js';\n\n/**\n * Verbs that take `<gitdir>/index.lock` before changing anything, so a run that loses the race fails at once\n * with nothing half-done and is safe to retry. `stash` is left out because it is multi-step and can fail part\n * way, and the long or interactive verbs (`merge`, `rebase`, `cherry-pick`, `revert`, `am`, `pull`) because\n * holding the lock-ordering chain for their whole run would stall every other write to the checkout.\n */\nconst indexWritingVerbs: ReadonlySet<string> = new Set([\n\t'add',\n\t'checkout',\n\t'commit',\n\t'mv',\n\t'read-tree',\n\t'reset',\n\t'restore',\n\t'rm',\n\t'switch',\n\t'update-index',\n]);\n\nconst applyIndexOptions: ReadonlySet<string> = new Set(['--index', '--cached', '--3way', '-3']);\n\n/**\n * Matches git's `fatal: Unable to create '<path>/index.lock': File exists.` — the wording varies a little by version,\n * but git always `die()`s (`fatal:`) on it.\n * Anchored to the start of stderr: git takes the lock before doing anything else, so its own failure is the first\n * thing it prints past any `warning:`/`hint:` lines from parsing its arguments (`checkout` warns of an ambiguous\n * refname first). The same line after other output came from something the run started, such as a hook running its\n * own git command, after the run had already done its work — retrying would run it all again.\n */\nconst indexLockHeldRegex =\n\t/^(?:\\s*(?:warning|hint): [^\\r\\n]*\\r?\\n)*\\s*fatal: Unable to create '[^\\r\\n]*index\\.lock': File exists/i;\n\n/**\n * The exit code in a run error's `code`, or `undefined` when the process never exited normally: a numeric string\n * is a real exit code, but an errno (`'ENOENT'`) means the spawn itself failed, and `undefined` means it was killed.\n */\nexport function toExitCode(code: number | string | undefined): number | undefined {\n\tconst exitCode = typeof code === 'number' ? code : code != null ? parseInt(code, 10) : NaN;\n\treturn Number.isInteger(exitCode) ? exitCode : undefined;\n}\n\n/** Git's exit code when it `die()`s, as it does on a held `index.lock`. */\nconst gitFatalExitCode = 128;\n\n/** How long to wait before each retry of a run that found `index.lock` held; its length is the retry count. */\nexport const indexLockRetryDelays: readonly number[] = [100, 200, 400];\n\n/**\n * Whether the argv is a command that writes the index (`apply` only does with `--index`, `--cached` or `--3way`,\n * which implies `--index`, and never with `--check`).\n */\nexport function isIndexWriteCommand(args: readonly string[]): boolean {\n\tconst { verb, rest } = leadingCommand(args);\n\tif (verb === 'apply') return !rest.includes('--check') && rest.some(a => applyIndexOptions.has(a));\n\n\treturn indexWritingVerbs.has(verb);\n}\n\n/**\n * Whether a run failed because another process held `index.lock`. The exit code must be 128 too: a hook that\n * prints the same line from its own git command and fails makes the run exit 1, after the hook's work is done.\n */\nexport function isIndexLockHeldError(ex: unknown): boolean {\n\treturn (\n\t\tex instanceof RunError &&\n\t\t!(ex instanceof CancelledRunError) &&\n\t\ttoExitCode(ex.code) === gitFatalExitCode &&\n\t\tindexLockHeldRegex.test(ex.stderr)\n\t);\n}\n\n/** Resolves after `ms`, or rejects as soon as `signal` aborts. */\nasync function delay(ms: number, signal: AbortSignal | undefined): Promise<void> {\n\ttry {\n\t\tawait wait(ms, undefined, { signal: signal });\n\t} catch (ex) {\n\t\tif (signal?.aborted) throw abortReason(signal);\n\n\t\tthrow ex;\n\t}\n}\n\n/**\n * Captures the rest of git's `error: could not lock config file <path>[: <reason>]` line. A held lock reads\n * `: File exists`, except `--remove-section`/`--rename-section` print no reason (for any failure); permanent\n * failures (`Permission denied`, `No such file or directory`, ...) must not be retried.\n */\nconst configLockFailureRegex = /could not lock config file ([^\\r\\n]*)/i;\n\n/**\n * Whether the argv is `git config`. Only that verb: others that write config (`branch -m`, `remote add`) can\n * fail after a partial change, so a blind retry isn't safe.\n */\nexport function isConfigCommand(args: readonly string[]): boolean {\n\treturn leadingCommand(args).verb === 'config';\n}\n\n/** Whether a run failed because another process may hold the config file's `.lock`: the reason is `File exists` or absent. */\nexport function isConfigLockHeldError(ex: unknown): boolean {\n\tif (!(ex instanceof RunError) || ex instanceof CancelledRunError) return false;\n\n\tconst rest = configLockFailureRegex.exec(ex.stderr)?.[1];\n\tif (rest == null) return false;\n\n\treturn /: File exists\\s*$/i.test(rest) || !rest.includes(': ');\n}\n\n/**\n * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails with an error\n * `isHeldError` accepts. Any other failure, or the last lock failure, is rethrown as is.\n */\nasync function retryWhileHeld<T>(\n\tattempt: () => Promise<T>,\n\tsignal: AbortSignal | undefined,\n\tisHeldError: (ex: unknown) => boolean,\n\tbeforeRetry?: (lockError: Error) => void | Promise<void>,\n): Promise<T> {\n\tfor (let retry = 0; ; retry++) {\n\t\tlet lockError: Error;\n\t\ttry {\n\t\t\treturn await attempt();\n\t\t} catch (ex) {\n\t\t\tif (retry >= indexLockRetryDelays.length || !isHeldError(ex)) throw ex;\n\n\t\t\tlockError = ex as Error;\n\t\t}\n\n\t\tawait delay(indexLockRetryDelays[retry], signal);\n\t\tawait beforeRetry?.(lockError);\n\t}\n}\n\n/**\n * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails on a held\n * `index.lock`. Any other failure, or the last lock failure, is rethrown as is. `beforeRetry` runs after each\n * wait, right before the next attempt; whatever it throws ends the retrying and is rethrown.\n */\nexport function retryWhileIndexLocked<T>(\n\tattempt: () => Promise<T>,\n\tsignal: AbortSignal | undefined,\n\tbeforeRetry?: (lockError: Error) => void | Promise<void>,\n): Promise<T> {\n\treturn retryWhileHeld(attempt, signal, isIndexLockHeldError, beforeRetry);\n}\n\n/**\n * Like {@link retryWhileIndexLocked}, for a config write that loses the race for the file's `.lock` to another\n * process — git fails at once rather than waiting.\n */\nexport function retryWhileConfigLocked<T>(attempt: () => Promise<T>, signal: AbortSignal | undefined): Promise<T> {\n\treturn retryWhileHeld(attempt, signal, isConfigLockHeldError);\n}\n\n/**\n * Runs the work for each key one at a time, in arrival order. A failing run doesn't hold up the next one, and a\n * run whose signal aborts while it waits rejects at once without ever starting.\n */\nexport class KeyedSequencer {\n\t/** The tail of each key's chain — settles once everything queued so far has finished or been dropped. */\n\tprivate readonly _tails = new Map<string, Promise<void>>();\n\n\tasync run<T>(key: string, signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T> {\n\t\tconst previous = this._tails.get(key);\n\n\t\tlet release!: () => void;\n\t\tconst tail = new Promise<void>(resolve => (release = resolve));\n\t\tthis._tails.set(key, tail);\n\n\t\tconst finish = () => {\n\t\t\trelease();\n\t\t\tif (this._tails.get(key) === tail) {\n\t\t\t\tthis._tails.delete(key);\n\t\t\t}\n\t\t};\n\n\t\tlet started = false;\n\t\ttry {\n\t\t\tif (previous != null) {\n\t\t\t\tawait waitFor(previous, signal);\n\t\t\t}\n\n\t\t\tstarted = true;\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\tif (started || previous == null) {\n\t\t\t\tfinish();\n\t\t\t} else {\n\t\t\t\t// Dropped while waiting: whoever is queued behind still has to wait for the run ahead of us,\n\t\t\t\t// so the chain can only be released once that run is done.\n\t\t\t\tvoid previous.then(finish);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction waitFor(promise: Promise<void>, signal: AbortSignal | undefined): Promise<void> {\n\tif (signal == null) return promise;\n\tif (signal.aborted) return Promise.reject(abortReason(signal));\n\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst onAbort = () => reject(abortReason(signal));\n\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\t\tvoid promise.then(() => {\n\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AAwB,QAAgD;CACxF,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,OAAO,SAAS,OAAO,QAAQ,OAAO,YAAY,MAAM,CAAC;CAE7D,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,MAAM,gBAAgB,OAAO,YAAY,MAAM,CAAC;EAChD,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;EACxD,QAAa,WAAW;GACvB,OAAO,oBAAoB,SAAS,OAAO;GAC3C,QAAQ;EACT,CAAC;CACF,CAAC;AACF"}
|
|
1
|
+
{"version":3,"file":"indexLock.js","names":["wait"],"sources":["../../../../git-cli/src/exec/indexLock.ts"],"sourcesContent":["import { setTimeout as wait } from 'timers/promises';\nimport { leadingCommand } from './commandClassifier.js';\nimport { CancelledRunError, RunError } from './exec.errors.js';\nimport { abortReason } from './gitQueue.js';\n\n/**\n * Verbs that take `<gitdir>/index.lock` before changing anything, so a run that loses the race fails at once\n * with nothing half-done and is safe to retry. `stash` is left out because it is multi-step and can fail part\n * way, and the long or interactive verbs (`merge`, `rebase`, `cherry-pick`, `revert`, `am`, `pull`) because\n * holding the lock-ordering chain for their whole run would stall every other write to the checkout.\n */\nconst indexWritingVerbs: ReadonlySet<string> = new Set([\n\t'add',\n\t'checkout',\n\t'commit',\n\t'mv',\n\t'read-tree',\n\t'reset',\n\t'restore',\n\t'rm',\n\t'switch',\n\t'update-index',\n]);\n\nconst applyIndexOptions: ReadonlySet<string> = new Set(['--index', '--cached', '--3way', '-3']);\n\n/**\n * Matches git's `fatal: Unable to create '<path>/index.lock': File exists.` — the wording varies a little by version,\n * but git always `die()`s (`fatal:`) on it.\n * Anchored to the start of stderr: git takes the lock before doing anything else, so its own failure is the first\n * thing it prints past any `warning:`/`hint:` lines from parsing its arguments (`checkout` warns of an ambiguous\n * refname first). The same line after other output came from something the run started, such as a hook running its\n * own git command, after the run had already done its work — retrying would run it all again.\n */\nconst indexLockHeldRegex =\n\t/^(?:\\s*(?:warning|hint): [^\\r\\n]*\\r?\\n)*\\s*fatal: Unable to create '[^\\r\\n]*index\\.lock': File exists/i;\n\n/**\n * The exit code in a run error's `code`, or `undefined` when the process never exited normally: a numeric string\n * is a real exit code, but an errno (`'ENOENT'`) means the spawn itself failed, and `undefined` means it was killed.\n */\nexport function toExitCode(code: number | string | undefined): number | undefined {\n\tconst exitCode = typeof code === 'number' ? code : code != null ? parseInt(code, 10) : NaN;\n\treturn Number.isInteger(exitCode) ? exitCode : undefined;\n}\n\n/** Git's exit code when it `die()`s, as it does on a held `index.lock`. */\nexport const gitFatalExitCode = 128;\n\n/** How long to wait before each retry of a run that found `index.lock` held; its length is the retry count. */\nexport const indexLockRetryDelays: readonly number[] = [100, 200, 400];\n\n/**\n * Whether the argv is a command that writes the index (`apply` only does with `--index`, `--cached` or `--3way`,\n * which implies `--index`, and never with `--check`).\n */\nexport function isIndexWriteCommand(args: readonly string[]): boolean {\n\tconst { verb, rest } = leadingCommand(args);\n\tif (verb === 'apply') return !rest.includes('--check') && rest.some(a => applyIndexOptions.has(a));\n\n\treturn indexWritingVerbs.has(verb);\n}\n\n/**\n * Whether a run failed because another process held `index.lock`. The exit code must be 128 too: a hook that\n * prints the same line from its own git command and fails makes the run exit 1, after the hook's work is done.\n */\nexport function isIndexLockHeldError(ex: unknown): boolean {\n\treturn (\n\t\tex instanceof RunError &&\n\t\t!(ex instanceof CancelledRunError) &&\n\t\ttoExitCode(ex.code) === gitFatalExitCode &&\n\t\tindexLockHeldRegex.test(ex.stderr)\n\t);\n}\n\n/** Resolves after `ms`, or rejects as soon as `signal` aborts. */\nasync function delay(ms: number, signal: AbortSignal | undefined): Promise<void> {\n\ttry {\n\t\tawait wait(ms, undefined, { signal: signal });\n\t} catch (ex) {\n\t\tif (signal?.aborted) throw abortReason(signal);\n\n\t\tthrow ex;\n\t}\n}\n\n/**\n * Captures the rest of git's `error: could not lock config file <path>[: <reason>]` line. A held lock reads\n * `: File exists`, except `--remove-section`/`--rename-section` print no reason (for any failure); permanent\n * failures (`Permission denied`, `No such file or directory`, ...) must not be retried.\n */\nconst configLockFailureRegex = /could not lock config file ([^\\r\\n]*)/i;\n\n/**\n * Whether the argv is `git config`. Only that verb: others that write config (`branch -m`, `remote add`) can\n * fail after a partial change, so a blind retry isn't safe.\n */\nexport function isConfigCommand(args: readonly string[]): boolean {\n\treturn leadingCommand(args).verb === 'config';\n}\n\n/** Whether a run failed because another process may hold the config file's `.lock`: the reason is `File exists` or absent. */\nexport function isConfigLockHeldError(ex: unknown): boolean {\n\tif (!(ex instanceof RunError) || ex instanceof CancelledRunError) return false;\n\n\tconst rest = configLockFailureRegex.exec(ex.stderr)?.[1];\n\tif (rest == null) return false;\n\n\treturn /: File exists\\s*$/i.test(rest) || !rest.includes(': ');\n}\n\n/**\n * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails with an error\n * `isHeldError` accepts. Any other failure, or the last lock failure, is rethrown as is.\n */\nasync function retryWhileHeld<T>(\n\tattempt: () => Promise<T>,\n\tsignal: AbortSignal | undefined,\n\tisHeldError: (ex: unknown) => boolean,\n\tbeforeRetry?: (lockError: Error) => void | Promise<void>,\n): Promise<T> {\n\tfor (let retry = 0; ; retry++) {\n\t\tlet lockError: Error;\n\t\ttry {\n\t\t\treturn await attempt();\n\t\t} catch (ex) {\n\t\t\tif (retry >= indexLockRetryDelays.length || !isHeldError(ex)) throw ex;\n\n\t\t\tlockError = ex as Error;\n\t\t}\n\n\t\tawait delay(indexLockRetryDelays[retry], signal);\n\t\tawait beforeRetry?.(lockError);\n\t}\n}\n\n/**\n * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails on a held\n * `index.lock`. Any other failure, or the last lock failure, is rethrown as is. `beforeRetry` runs after each\n * wait, right before the next attempt; whatever it throws ends the retrying and is rethrown.\n */\nexport function retryWhileIndexLocked<T>(\n\tattempt: () => Promise<T>,\n\tsignal: AbortSignal | undefined,\n\tbeforeRetry?: (lockError: Error) => void | Promise<void>,\n): Promise<T> {\n\treturn retryWhileHeld(attempt, signal, isIndexLockHeldError, beforeRetry);\n}\n\n/**\n * Like {@link retryWhileIndexLocked}, for a config write that loses the race for the file's `.lock` to another\n * process — git fails at once rather than waiting.\n */\nexport function retryWhileConfigLocked<T>(attempt: () => Promise<T>, signal: AbortSignal | undefined): Promise<T> {\n\treturn retryWhileHeld(attempt, signal, isConfigLockHeldError);\n}\n\n/**\n * Runs the work for each key one at a time, in arrival order. A failing run doesn't hold up the next one, and a\n * run whose signal aborts while it waits rejects at once without ever starting.\n */\nexport class KeyedSequencer {\n\t/** The tail of each key's chain — settles once everything queued so far has finished or been dropped. */\n\tprivate readonly _tails = new Map<string, Promise<void>>();\n\n\tasync run<T>(key: string, signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T> {\n\t\tconst previous = this._tails.get(key);\n\n\t\tlet release!: () => void;\n\t\tconst tail = new Promise<void>(resolve => (release = resolve));\n\t\tthis._tails.set(key, tail);\n\n\t\tconst finish = () => {\n\t\t\trelease();\n\t\t\tif (this._tails.get(key) === tail) {\n\t\t\t\tthis._tails.delete(key);\n\t\t\t}\n\t\t};\n\n\t\tlet started = false;\n\t\ttry {\n\t\t\tif (previous != null) {\n\t\t\t\tawait waitFor(previous, signal);\n\t\t\t}\n\n\t\t\tstarted = true;\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\tif (started || previous == null) {\n\t\t\t\tfinish();\n\t\t\t} else {\n\t\t\t\t// Dropped while waiting: whoever is queued behind still has to wait for the run ahead of us,\n\t\t\t\t// so the chain can only be released once that run is done.\n\t\t\t\tvoid previous.then(finish);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction waitFor(promise: Promise<void>, signal: AbortSignal | undefined): Promise<void> {\n\tif (signal == null) return promise;\n\tif (signal.aborted) return Promise.reject(abortReason(signal));\n\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst onAbort = () => reject(abortReason(signal));\n\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\t\tvoid promise.then(() => {\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SAAwB,QAAgD;CACxF,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,OAAO,SAAS,OAAO,QAAQ,OAAO,YAAY,MAAM,CAAC;CAE7D,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,MAAM,gBAAgB,OAAO,YAAY,MAAM,CAAC;EAChD,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;EACxD,QAAa,WAAW;GACvB,OAAO,oBAAoB,SAAS,OAAO;GAC3C,QAAQ;EACT,CAAC;CACF,CAAC;AACF"}
|
|
@@ -202,13 +202,16 @@ export declare class ConfigGitSubProvider implements GitConfigSubProvider {
|
|
|
202
202
|
global?: boolean;
|
|
203
203
|
}): Promise<void>;
|
|
204
204
|
getSigningConfigFlags(config: SigningConfig): string[];
|
|
205
|
+
/**
|
|
206
|
+
* `[]` when git says `cwd` isn't a repository it can use, or `cwd` isn't a folder. Rejects when git gives no answer
|
|
207
|
+
* (it ran past its time limit, was killed or couldn't start), which says nothing about `cwd`.
|
|
208
|
+
*/
|
|
205
209
|
getRepositoryInfo(cwd: string): Promise<{
|
|
206
210
|
repoPath: string;
|
|
207
211
|
gitDir: string;
|
|
208
212
|
commonGitDir: string | undefined;
|
|
209
213
|
superprojectPath: string | undefined;
|
|
210
214
|
} | [safe: true, repoPath: string] | [safe: false] | []>;
|
|
211
|
-
private revParseGitDir;
|
|
212
215
|
/**
|
|
213
216
|
* Ensures the `.git/gk/` folder exists, but only if the parent `.git` directory already exists.
|
|
214
217
|
* This prevents creating stray `.git` directories if the computed path is wrong.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { first, some } from "../../utils/iterable.js";
|
|
2
|
-
import { CancellationError } from "../../utils/cancellation.js";
|
|
2
|
+
import { CancellationError, isCancellationError } from "../../utils/cancellation.js";
|
|
3
3
|
import { Logger as _logger } from "../../utils/logger.js";
|
|
4
4
|
import { getScopedLogger } from "../../utils/logger.scoped.js";
|
|
5
5
|
import { getSettledValue } from "../../utils/promise.js";
|
|
@@ -12,6 +12,7 @@ import { WorkspaceUntrustedError } from "../../git/errors.js";
|
|
|
12
12
|
import { fsExists } from "../../utils/env/node/exec.js";
|
|
13
13
|
import { isGitDirMovedByEnv, readGitDirs } from "../exec/gitDirResolver.js";
|
|
14
14
|
import { KeyedSequencer } from "../exec/indexLock.js";
|
|
15
|
+
import { isFolder, isGitAnswer, isGitUnanswered, throwIfUnanswered } from "../exec/git.js";
|
|
15
16
|
import { gate } from "../../utils/decorators/gate.js";
|
|
16
17
|
import { promises, statSync } from "fs";
|
|
17
18
|
import { env } from "process";
|
|
@@ -351,7 +352,7 @@ var ConfigGitSubProvider = class {
|
|
|
351
352
|
}
|
|
352
353
|
}
|
|
353
354
|
async getDefaultWorktreePath(repoPath) {
|
|
354
|
-
const gitDir = await this.getGitDir(repoPath);
|
|
355
|
+
const gitDir = await this.getGitDir(repoPath).catch(() => void 0);
|
|
355
356
|
if (gitDir == null) return void 0;
|
|
356
357
|
const basePath = (gitDir.commonUri ?? gitDir.uri).fsPath;
|
|
357
358
|
return getBestPath(normalizePath(joinPaths(basePath, "..")));
|
|
@@ -399,7 +400,9 @@ var ConfigGitSubProvider = class {
|
|
|
399
400
|
* Uses commonPath for worktrees so all worktrees share the same data.
|
|
400
401
|
*/
|
|
401
402
|
async getGkConfigPath(repoPath) {
|
|
402
|
-
const gitDir = await this.getGitDir(repoPath)
|
|
403
|
+
const gitDir = await this.getGitDir(repoPath).catch((ex) => {
|
|
404
|
+
_logger.warn(`Unable to locate GitKraken config storage for '${repoPath}': ${String(ex)}`);
|
|
405
|
+
});
|
|
403
406
|
if (gitDir == null) return void 0;
|
|
404
407
|
const basePath = (gitDir.commonUri ?? gitDir.uri).fsPath;
|
|
405
408
|
return joinPaths(basePath, "gk", "config");
|
|
@@ -496,7 +499,7 @@ var ConfigGitSubProvider = class {
|
|
|
496
499
|
read.spawned = true;
|
|
497
500
|
return {
|
|
498
501
|
map: /* @__PURE__ */ new Map(),
|
|
499
|
-
failed:
|
|
502
|
+
failed: true
|
|
500
503
|
};
|
|
501
504
|
}
|
|
502
505
|
read.path = gkConfigPath;
|
|
@@ -725,6 +728,10 @@ var ConfigGitSubProvider = class {
|
|
|
725
728
|
if (config.allowedSignersFile) flags.push("-c", `gpg.ssh.allowedSignersFile=${config.allowedSignersFile}`);
|
|
726
729
|
return flags;
|
|
727
730
|
}
|
|
731
|
+
/**
|
|
732
|
+
* `[]` when git says `cwd` isn't a repository it can use, or `cwd` isn't a folder. Rejects when git gives no answer
|
|
733
|
+
* (it ran past its time limit, was killed or couldn't start), which says nothing about `cwd`.
|
|
734
|
+
*/
|
|
728
735
|
async getRepositoryInfo(cwd) {
|
|
729
736
|
let result;
|
|
730
737
|
if (this.context.workspace?.isTrusted === false) try {
|
|
@@ -738,7 +745,9 @@ var ConfigGitSubProvider = class {
|
|
|
738
745
|
_logger.warn(`Skipping (untrusted); bare clone repository detected in '${cwd}'`);
|
|
739
746
|
return emptyArray;
|
|
740
747
|
}
|
|
741
|
-
} catch {
|
|
748
|
+
} catch (ex) {
|
|
749
|
+
if (isGitUnanswered(ex)) throw ex;
|
|
750
|
+
}
|
|
742
751
|
try {
|
|
743
752
|
result = await this.git.run({
|
|
744
753
|
cwd,
|
|
@@ -766,6 +775,7 @@ var ConfigGitSubProvider = class {
|
|
|
766
775
|
};
|
|
767
776
|
} catch (ex) {
|
|
768
777
|
if (ex instanceof WorkspaceUntrustedError) return emptyArray;
|
|
778
|
+
if (!isGitAnswer(ex) && (isCancellationError(ex) || await isFolder(cwd))) throw ex;
|
|
769
779
|
const unsafeMatch = /(?:^fatal:\s*detected dubious ownership in repository at '([^']+)'|unsafe repository \('([^']+)' is owned by someone else\))[\s\S]*(git config --global --add safe\.directory [^\n\u2022]+)/m.exec(ex.stderr);
|
|
770
780
|
if (unsafeMatch != null) {
|
|
771
781
|
_logger.warn(`Skipping; unsafe repository detected in '${unsafeMatch[1] || unsafeMatch[2]}'; run '${unsafeMatch[3]}' to allow it`);
|
|
@@ -777,8 +787,12 @@ var ConfigGitSubProvider = class {
|
|
|
777
787
|
cwd,
|
|
778
788
|
errors: "ignore"
|
|
779
789
|
}, "rev-parse", "--is-bare-repository");
|
|
790
|
+
throwIfUnanswered(result);
|
|
780
791
|
if (result.stdout.trim() === "true") {
|
|
781
|
-
const result = await this.
|
|
792
|
+
const result = await this.git.rev_parse__git_dir(cwd).catch((ex) => {
|
|
793
|
+
if (isGitAnswer(ex)) return void 0;
|
|
794
|
+
throw ex;
|
|
795
|
+
});
|
|
782
796
|
const repoPath = result?.commonPath ?? result?.path;
|
|
783
797
|
if (repoPath?.length) {
|
|
784
798
|
const workTree = await this.git.rev_parse__work_tree_of_git_dir(repoPath);
|
|
@@ -786,40 +800,19 @@ var ConfigGitSubProvider = class {
|
|
|
786
800
|
}
|
|
787
801
|
}
|
|
788
802
|
}
|
|
789
|
-
if (inDotGit
|
|
790
|
-
let exists =
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
return this.getRepositoryInfo(cwd);
|
|
799
|
-
}
|
|
803
|
+
if (inDotGit) {
|
|
804
|
+
let exists = false;
|
|
805
|
+
do {
|
|
806
|
+
const parent = dirname(cwd);
|
|
807
|
+
if (parent === cwd || parent.length === 0) return emptyArray;
|
|
808
|
+
cwd = parent;
|
|
809
|
+
exists = await fsExists(cwd);
|
|
810
|
+
} while (!exists);
|
|
811
|
+
return this.getRepositoryInfo(cwd);
|
|
800
812
|
}
|
|
801
813
|
return emptyArray;
|
|
802
814
|
}
|
|
803
815
|
}
|
|
804
|
-
async revParseGitDir(cwd) {
|
|
805
|
-
const result = await this.git.run({
|
|
806
|
-
cwd,
|
|
807
|
-
errors: "ignore"
|
|
808
|
-
}, "rev-parse", "--git-dir", "--git-common-dir");
|
|
809
|
-
if (!result.stdout) return void 0;
|
|
810
|
-
let [dotGitPath, commonDotGitPath] = result.stdout.split("\n").map((r) => r.trimStart());
|
|
811
|
-
if (!isAbsolute(dotGitPath)) dotGitPath = joinPaths(cwd, dotGitPath);
|
|
812
|
-
dotGitPath = normalizePath(dotGitPath);
|
|
813
|
-
if (commonDotGitPath) {
|
|
814
|
-
if (!isAbsolute(commonDotGitPath)) commonDotGitPath = joinPaths(cwd, commonDotGitPath);
|
|
815
|
-
commonDotGitPath = normalizePath(commonDotGitPath);
|
|
816
|
-
return {
|
|
817
|
-
path: dotGitPath,
|
|
818
|
-
commonPath: commonDotGitPath !== dotGitPath ? commonDotGitPath : void 0
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
return { path: dotGitPath };
|
|
822
|
-
}
|
|
823
816
|
/**
|
|
824
817
|
* Ensures the `.git/gk/` folder exists, but only if the parent `.git` directory already exists.
|
|
825
818
|
* This prevents creating stray `.git` directories if the computed path is wrong.
|
|
@@ -852,10 +845,7 @@ var ConfigGitSubProvider = class {
|
|
|
852
845
|
if (this._migratedRepos.has(repoPath)) return;
|
|
853
846
|
const scope = getScopedLogger();
|
|
854
847
|
const gkConfigPath = await this.getGkConfigPath(repoPath);
|
|
855
|
-
if (!gkConfigPath)
|
|
856
|
-
this._migratedRepos.add(repoPath);
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
848
|
+
if (!gkConfigPath) return;
|
|
859
849
|
const gkConfigFolder = joinPaths(gkConfigPath, "..");
|
|
860
850
|
try {
|
|
861
851
|
await promises.stat(gkConfigPath);
|