Browse Source

Fixes types from built-in Git

main
Eric Amodio 3 years ago
parent
commit
26700d7efa
6 changed files with 100 additions and 110 deletions
  1. +1
    -67
      src/@types/vscode.git.d.ts
  2. +70
    -0
      src/@types/vscode.git.enums.ts
  3. +7
    -0
      src/@types/vscode.git.resources.d.ts
  4. +7
    -0
      src/@types/vscode.git.resources.enums.ts
  5. +8
    -36
      src/commands/externalDiff.ts
  6. +7
    -7
      src/commands/stashSave.ts

+ 1
- 67
src/@types/vscode.git.d.ts View File

@ -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',
}

+ 70
- 0
src/@types/vscode.git.enums.ts View File

@ -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',
}

+ 7
- 0
src/@types/vscode.git.resources.d.ts View File

@ -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;
}

+ 7
- 0
src/@types/vscode.git.resources.enums.ts View File

@ -0,0 +1,7 @@
export { Status as ScmStatus } from './vscode.git.enums';
export const enum ScmResourceGroupType {
Merge,
Index,
WorkingTree,
}

+ 8
- 36
src/commands/externalDiff.ts View File

@ -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) {

+ 7
- 7
src/commands/stashSave.ts View File

@ -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;
}
}

Loading…
Cancel
Save