From 1a652e42e799e350da4015400952e8b1544079e3 Mon Sep 17 00:00:00 2001 From: Sergio Date: Wed, 23 Oct 2024 14:49:49 +0200 Subject: [PATCH] rebase & lint fixes --- src/env/node/git/git.ts | 39 +++++++++++++--------------- src/env/node/git/localGitProvider.ts | 2 +- src/git/errors.ts | 4 --- src/git/gitProvider.ts | 2 +- src/git/gitProviderService.ts | 4 +-- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/env/node/git/git.ts b/src/env/node/git/git.ts index 8219f1a10f33f..b02ef4afd6c8e 100644 --- a/src/env/node/git/git.ts +++ b/src/env/node/git/git.ts @@ -74,39 +74,37 @@ const textDecoder = new TextDecoder('utf8'); const rootSha = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; export const GitErrors = { + alreadyCheckedOut: /already checked out/i, + alreadyExists: /already exists/i, + ambiguousArgument: /fatal:\s*ambiguous argument ['"].+['"]: unknown revision or path not in the working tree/i, badRevision: /bad revision '(.*?)'/i, cantLockRef: /cannot lock ref|unable to update local ref/i, - changesWouldBeOverwritten: /Your local changes to the following files would be overwritten/i, commitChangesFirst: /Please, commit your changes before you can/i, conflict: /^CONFLICT \([^)]+\): \b/m, + entryNotUpToDate: /error:\s*Entry ['"].+['"] not uptodate\. Cannot merge\./i, failedToDeleteDirectoryNotEmpty: /failed to delete '(.*?)': Directory not empty/i, + invalidLineCount: /file .+? has only \d+ lines/i, invalidObjectName: /invalid object name: (.*)\s/i, invalidObjectNameList: /could not open object name list: (.*)\s/i, + mainWorkingTree: /is a main working tree/i, noFastForward: /\(non-fast-forward\)/i, noMergeBase: /no merge base/i, noRemoteRepositorySpecified: /No remote repository specified\./i, + noUpstream: /^fatal: The current branch .* has no upstream branch/i, + noUserNameConfigured: /Please tell me who you are\./i, notAValidObjectName: /Not a valid object name/i, notAWorkingTree: /'(.*?)' is not a working tree/i, - noUserNameConfigured: /Please tell me who you are\./i, - invalidLineCount: /file .+? has only \d+ lines/i, - uncommittedChanges: /contains modified or untracked files/i, - alreadyExists: /already exists/i, - alreadyCheckedOut: /already checked out/i, - mainWorkingTree: /is a main working tree/i, - noUpstream: /^fatal: The current branch .* has no upstream branch/i, permissionDenied: /Permission.*denied/i, pushRejected: /^error: failed to push some refs to\b/m, rebaseMultipleBranches: /cannot rebase onto multiple branches/i, + refLocked: /fatal:\s*cannot lock ref ['"].+['"]: unable to create file/i, remoteAhead: /rejected because the remote contains work/i, remoteConnection: /Could not read from remote repository/i, tagConflict: /! \[rejected\].*\(would clobber existing tag\)/m, + uncommittedChanges: /contains modified or untracked files/i, + unmergedChanges: /error:\s*you need to resolve your current index first/i, unmergedFiles: /is not possible because you have unmerged files/i, unstagedChanges: /You have unstaged changes/i, - unmergedChanges: /error:\s*you need to resolve your current index first/i, - ambiguousArgument: /fatal:\s*ambiguous argument ['"].+['"]: unknown revision or path not in the working tree/i, - entryNotUpToDate: /error:\s*Entry ['"].+['"] not uptodate\. Cannot merge\./i, - changesWouldBeOverwritten: /error:\s*Your local changes to the following files would be overwritten/i, - refLocked: /fatal:\s*cannot lock ref ['"].+['"]: unable to create file/i, }; const GitWarnings = { @@ -167,12 +165,11 @@ function getStdinUniqueKey(): number { type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly: true }; export type PushForceOptions = { withLease: true; ifIncludes?: boolean } | { withLease: false; ifIncludes?: never }; -const resetErrorAndReason = [ - [unmergedChanges, ResetErrorReason.UnmergedChanges], - [ambiguousArgument, ResetErrorReason.AmbiguousArgument], - [entryNotUpToDate, ResetErrorReason.EntryNotUpToDate], - [changesWouldBeOverwritten, ResetErrorReason.LocalChangesWouldBeOverwritten], - [refLocked, ResetErrorReason.RefLocked], +const resetErrorAndReason: [RegExp, ResetErrorReason][] = [ + [GitErrors.unmergedChanges, ResetErrorReason.UnmergedChanges], + [GitErrors.ambiguousArgument, ResetErrorReason.AmbiguousArgument], + [GitErrors.entryNotUpToDate, ResetErrorReason.EntryNotUpToDate], + [GitErrors.refLocked, ResetErrorReason.RefLocked], ]; export class Git { @@ -1586,9 +1583,9 @@ export class Git { return this.git({ cwd: repoPath }, 'remote', 'get-url', remote); } - reset(repoPath: string, pathspecs: string[], ...args: string[]) { + async reset(repoPath: string, pathspecs: string[], ...args: string[]) { try { - return this.git({ cwd: repoPath }, 'reset', '-q', ...args, '--', ...pathspecs); + await this.git({ cwd: repoPath }, 'reset', '-q', ...args, '--', ...pathspecs); } catch (ex) { const msg: string = ex?.toString() ?? ''; for (const [error, reason] of resetErrorAndReason) { diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 5f1d81bf05751..095056ab17abc 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -5789,7 +5789,7 @@ export class LocalGitProvider implements GitProvider, Disposable { } @log() - async reset(repoPath: string, options?: { hard?: boolean; soft?: boolean }, ref?: string): Promise { + async reset(repoPath: string, ref: string, options?: { hard?: boolean; soft?: boolean }): Promise { const flags = []; if (options?.hard) { flags.push('--hard'); diff --git a/src/git/errors.ts b/src/git/errors.ts index 8c54495331ab7..1271b3e48bdf0 100644 --- a/src/git/errors.ts +++ b/src/git/errors.ts @@ -494,7 +494,6 @@ export const enum ResetErrorReason { UnmergedChanges, AmbiguousArgument, EntryNotUpToDate, - LocalChangesWouldBeOverwritten, RefLocked, Other, } @@ -529,9 +528,6 @@ export class ResetError extends Error { case ResetErrorReason.EntryNotUpToDate: message = `${message} because the entry is not up to date`; break; - case ResetErrorReason.LocalChangesWouldBeOverwritten: - message = `${message} because local changes would be overwritten`; - break; case ResetErrorReason.RefLocked: message = `${message} because the ref is locked`; break; diff --git a/src/git/gitProvider.ts b/src/git/gitProvider.ts index 4b833c9f4c5ee..a7ac22af9e373 100644 --- a/src/git/gitProvider.ts +++ b/src/git/gitProvider.ts @@ -125,7 +125,7 @@ export interface GitProviderRepository { pruneRemote?(repoPath: string, name: string): Promise; removeRemote?(repoPath: string, name: string): Promise; - reset?(repoPath: string, options?: { hard?: boolean; soft?: boolean }, ref?: string): Promise; + reset?(repoPath: string, ref: string, options?: { hard?: boolean; soft?: boolean }): Promise; applyUnreachableCommitForPatch?( repoPath: string, diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index f7a93cb50d001..cfc45688a87e4 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -1335,7 +1335,7 @@ export class GitProviderService implements Disposable { } @log() - async reset(repoPath: string, flags: string[], ref?: string): Promise { + async reset(repoPath: string, flags: string[], ref: string): Promise { const { provider, path } = this.getProvider(repoPath); if (provider.reset == null) throw new ProviderNotSupportedError(provider.descriptor.name); @@ -1353,7 +1353,7 @@ export class GitProviderService implements Disposable { } } - return provider.reset(path, options, ref); + return provider.reset(path, ref, options); } @log()