From 26700d7efa082b55bb56b2af63e46416d3d8fae2 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 1 Dec 2021 01:51:39 -0500 Subject: [PATCH] Fixes types from built-in Git --- src/@types/vscode.git.d.ts | 68 +------------------------------ src/@types/vscode.git.enums.ts | 70 ++++++++++++++++++++++++++++++++ src/@types/vscode.git.resources.d.ts | 7 ++++ src/@types/vscode.git.resources.enums.ts | 7 ++++ src/commands/externalDiff.ts | 44 ++++---------------- src/commands/stashSave.ts | 14 +++---- 6 files changed, 100 insertions(+), 110 deletions(-) create mode 100644 src/@types/vscode.git.enums.ts create mode 100644 src/@types/vscode.git.resources.d.ts create mode 100644 src/@types/vscode.git.resources.enums.ts diff --git a/src/@types/vscode.git.d.ts b/src/@types/vscode.git.d.ts index 81b9c3d..c5bef27 100644 --- a/src/@types/vscode.git.d.ts +++ b/src/@types/vscode.git.d.ts @@ -5,7 +5,7 @@ import { Disposable, Event, ProviderResult, Uri } from 'vscode'; -export { ProviderResult } from 'vscode'; +import { GitErrorCodes, RefType, Status } from '../@types/vscode.git.enums'; export interface Git { readonly path: string; @@ -15,12 +15,6 @@ export interface InputBox { value: string; } -export const enum RefType { - Head, - RemoteHead, - Tag, -} - export interface Ref { readonly type: RefType; readonly name?: string; @@ -62,28 +56,6 @@ export interface Remote { readonly isReadOnly: boolean; } -export const enum Status { - INDEX_MODIFIED, - INDEX_ADDED, - INDEX_DELETED, - INDEX_RENAMED, - INDEX_COPIED, - - MODIFIED, - DELETED, - UNTRACKED, - IGNORED, - INTENT_TO_ADD, - - ADDED_BY_US, - ADDED_BY_THEM, - DELETED_BY_US, - DELETED_BY_THEM, - BOTH_ADDED, - BOTH_DELETED, - BOTH_MODIFIED, -} - export interface Change { /** * Returns either `originalUri` or `renameUri`, depending @@ -267,41 +239,3 @@ export interface GitExtension { */ getAPI(version: 1): API; } - -export const enum GitErrorCodes { - BadConfigFile = 'BadConfigFile', - AuthenticationFailed = 'AuthenticationFailed', - NoUserNameConfigured = 'NoUserNameConfigured', - NoUserEmailConfigured = 'NoUserEmailConfigured', - NoRemoteRepositorySpecified = 'NoRemoteRepositorySpecified', - NotAGitRepository = 'NotAGitRepository', - NotAtRepositoryRoot = 'NotAtRepositoryRoot', - Conflict = 'Conflict', - StashConflict = 'StashConflict', - UnmergedChanges = 'UnmergedChanges', - PushRejected = 'PushRejected', - RemoteConnectionError = 'RemoteConnectionError', - DirtyWorkTree = 'DirtyWorkTree', - CantOpenResource = 'CantOpenResource', - GitNotFound = 'GitNotFound', - CantCreatePipe = 'CantCreatePipe', - PermissionDenied = 'PermissionDenied', - CantAccessRemote = 'CantAccessRemote', - RepositoryNotFound = 'RepositoryNotFound', - RepositoryIsLocked = 'RepositoryIsLocked', - BranchNotFullyMerged = 'BranchNotFullyMerged', - NoRemoteReference = 'NoRemoteReference', - InvalidBranchName = 'InvalidBranchName', - BranchAlreadyExists = 'BranchAlreadyExists', - NoLocalChanges = 'NoLocalChanges', - NoStashFound = 'NoStashFound', - LocalChangesOverwritten = 'LocalChangesOverwritten', - NoUpstreamBranch = 'NoUpstreamBranch', - IsInSubmodule = 'IsInSubmodule', - WrongCase = 'WrongCase', - CantLockRef = 'CantLockRef', - CantRebaseMultipleBranches = 'CantRebaseMultipleBranches', - PatchDoesNotApply = 'PatchDoesNotApply', - NoPathFound = 'NoPathFound', - UnknownPath = 'UnknownPath', -} diff --git a/src/@types/vscode.git.enums.ts b/src/@types/vscode.git.enums.ts new file mode 100644 index 0000000..904e8a8 --- /dev/null +++ b/src/@types/vscode.git.enums.ts @@ -0,0 +1,70 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export const enum RefType { + Head, + RemoteHead, + Tag, +} + +export const enum Status { + INDEX_MODIFIED, + INDEX_ADDED, + INDEX_DELETED, + INDEX_RENAMED, + INDEX_COPIED, + + MODIFIED, + DELETED, + UNTRACKED, + IGNORED, + INTENT_TO_ADD, + + ADDED_BY_US, + ADDED_BY_THEM, + DELETED_BY_US, + DELETED_BY_THEM, + BOTH_ADDED, + BOTH_DELETED, + BOTH_MODIFIED, +} + +export const enum GitErrorCodes { + BadConfigFile = 'BadConfigFile', + AuthenticationFailed = 'AuthenticationFailed', + NoUserNameConfigured = 'NoUserNameConfigured', + NoUserEmailConfigured = 'NoUserEmailConfigured', + NoRemoteRepositorySpecified = 'NoRemoteRepositorySpecified', + NotAGitRepository = 'NotAGitRepository', + NotAtRepositoryRoot = 'NotAtRepositoryRoot', + Conflict = 'Conflict', + StashConflict = 'StashConflict', + UnmergedChanges = 'UnmergedChanges', + PushRejected = 'PushRejected', + RemoteConnectionError = 'RemoteConnectionError', + DirtyWorkTree = 'DirtyWorkTree', + CantOpenResource = 'CantOpenResource', + GitNotFound = 'GitNotFound', + CantCreatePipe = 'CantCreatePipe', + PermissionDenied = 'PermissionDenied', + CantAccessRemote = 'CantAccessRemote', + RepositoryNotFound = 'RepositoryNotFound', + RepositoryIsLocked = 'RepositoryIsLocked', + BranchNotFullyMerged = 'BranchNotFullyMerged', + NoRemoteReference = 'NoRemoteReference', + InvalidBranchName = 'InvalidBranchName', + BranchAlreadyExists = 'BranchAlreadyExists', + NoLocalChanges = 'NoLocalChanges', + NoStashFound = 'NoStashFound', + LocalChangesOverwritten = 'LocalChangesOverwritten', + NoUpstreamBranch = 'NoUpstreamBranch', + IsInSubmodule = 'IsInSubmodule', + WrongCase = 'WrongCase', + CantLockRef = 'CantLockRef', + CantRebaseMultipleBranches = 'CantRebaseMultipleBranches', + PatchDoesNotApply = 'PatchDoesNotApply', + NoPathFound = 'NoPathFound', + UnknownPath = 'UnknownPath', +} diff --git a/src/@types/vscode.git.resources.d.ts b/src/@types/vscode.git.resources.d.ts new file mode 100644 index 0000000..125055f --- /dev/null +++ b/src/@types/vscode.git.resources.d.ts @@ -0,0 +1,7 @@ +import { Status as ScmStatus } from '../@types/vscode.git.d.ts'; +import { ScmResourceGroupType } from '../@types/vscode.git.resources.enums'; + +export interface ScmResource extends SourceControlResourceState { + readonly resourceGroupType?: ScmResourceGroupType; + readonly type?: ScmStatus; +} diff --git a/src/@types/vscode.git.resources.enums.ts b/src/@types/vscode.git.resources.enums.ts new file mode 100644 index 0000000..1da099f --- /dev/null +++ b/src/@types/vscode.git.resources.enums.ts @@ -0,0 +1,7 @@ +export { Status as ScmStatus } from './vscode.git.enums'; + +export const enum ScmResourceGroupType { + Merge, + Index, + WorkingTree, +} diff --git a/src/commands/externalDiff.ts b/src/commands/externalDiff.ts index c9dc911..5f018a6 100644 --- a/src/commands/externalDiff.ts +++ b/src/commands/externalDiff.ts @@ -1,5 +1,7 @@ 'use strict'; import { env, SourceControlResourceState, Uri, window } from 'vscode'; +import { ScmResource } from '../@types/vscode.git.resources'; +import { ScmResourceGroupType, ScmStatus } from '../@types/vscode.git.resources.enums'; import { Container } from '../container'; import { GitRevision } from '../git/git'; import { GitUri } from '../git/gitUri'; @@ -16,38 +18,6 @@ import { isCommandContextViewNodeHasFileRefs, } from './common'; -enum Status { - INDEX_MODIFIED, - INDEX_ADDED, - INDEX_DELETED, - INDEX_RENAMED, - INDEX_COPIED, - - MODIFIED, - DELETED, - UNTRACKED, - IGNORED, - - ADDED_BY_US, - ADDED_BY_THEM, - DELETED_BY_US, - DELETED_BY_THEM, - BOTH_ADDED, - BOTH_DELETED, - BOTH_MODIFIED, -} - -enum ResourceGroupType { - Merge, - Index, - WorkingTree, -} - -interface Resource extends SourceControlResourceState { - readonly resourceGroupType: ResourceGroupType; - readonly type: Status; -} - interface ExternalDiffFile { uri: Uri; staged: boolean; @@ -103,14 +73,14 @@ export class ExternalDiffCommand extends Command { if (context.type === 'scm-states') { args.files = context.scmResourceStates.map(r => ({ uri: r.resourceUri, - staged: (r as Resource).resourceGroupType === ResourceGroupType.Index, + staged: (r as ScmResource).resourceGroupType === ScmResourceGroupType.Index, })); } else if (context.type === 'scm-groups') { args.files = Arrays.filterMap(context.scmResourceGroups[0].resourceStates, r => this.isModified(r) ? { uri: r.resourceUri, - staged: (r as Resource).resourceGroupType === ResourceGroupType.Index, + staged: (r as ScmResource).resourceGroupType === ScmResourceGroupType.Index, } : undefined, ); @@ -145,8 +115,10 @@ export class ExternalDiffCommand extends Command { } private isModified(resource: SourceControlResourceState) { - const status = (resource as Resource).type; - return status === Status.BOTH_MODIFIED || status === Status.INDEX_MODIFIED || status === Status.MODIFIED; + const status = (resource as ScmResource).type; + return ( + status === ScmStatus.BOTH_MODIFIED || status === ScmStatus.INDEX_MODIFIED || status === ScmStatus.MODIFIED + ); } async execute(args?: ExternalDiffCommandArgs) { diff --git a/src/commands/stashSave.ts b/src/commands/stashSave.ts index 2e5e3a2..6bdfc1d 100644 --- a/src/commands/stashSave.ts +++ b/src/commands/stashSave.ts @@ -1,5 +1,7 @@ 'use strict'; import { Uri } from 'vscode'; +import type { ScmResource } from '../@types/vscode.git.resources'; +import { ScmResourceGroupType } from '../@types/vscode.git.resources.enums'; import { GitActions } from '../commands'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; @@ -13,12 +15,6 @@ import { isCommandContextViewNodeHasRepository, } from './common'; -const enum ResourceGroupType { - Merge, - Index, - WorkingTree, -} - export interface StashSaveCommandArgs { message?: string; repoPath?: string; @@ -50,7 +46,11 @@ export class StashSaveCommand extends Command { const status = await Container.instance.git.getStatusForRepo(args.repoPath); if (status?.computeWorkingTreeStatus().staged) { - if (!context.scmResourceStates.some(s => (s as any).resourceGroupType === ResourceGroupType.Index)) { + if ( + !context.scmResourceStates.some( + s => (s as ScmResource).resourceGroupType === ScmResourceGroupType.Index, + ) + ) { args.keepStaged = true; } }