Skip to content

Commit

Permalink
Fixes issue where refType info was lost on nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Aug 21, 2020
1 parent 48844a0 commit b5e8d92
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/git/models/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export abstract class GitCommit implements GitRevisionReference {
}

static isOfRefType(commit: GitReference | undefined) {
return commit?.refType === 'revision';
return commit?.refType === 'revision' || commit?.refType === 'stash';
}

readonly refType = 'revision';
readonly refType: GitRevisionReference['refType'] = 'revision';

constructor(
public readonly type: GitCommitType,
Expand Down
9 changes: 7 additions & 2 deletions src/git/models/logCommit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';
import { Uri } from 'vscode';
import { memoize, Strings } from '../../system';
import { GitUri } from '../gitUri';
import { GitCommit, GitCommitType } from './commit';
import { GitFile, GitFileStatus } from './file';
import { GitUri } from '../gitUri';
import { GitReference } from './models';
import { memoize, Strings } from '../../system';

const emptyStats = Object.freeze({
added: 0,
Expand All @@ -23,6 +24,10 @@ export interface GitLogCommitLine {
}

export class GitLogCommit extends GitCommit {
static isOfRefType(commit: GitReference | undefined) {
return commit?.refType === 'revision';
}

static is(commit: any): commit is GitLogCommit {
return (
commit instanceof GitLogCommit
Expand Down
9 changes: 5 additions & 4 deletions src/git/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ export interface GitBranchReference {
}

export interface GitRevisionReference {
readonly refType: 'revision';
readonly refType: 'revision' | 'stash';
name: string;
ref: string;
repoPath: string;

number?: string | undefined;
message?: string;
}

export interface GitStashReference {
readonly refType: 'revision';
readonly refType: 'stash';
name: string;
ref: string;
repoPath: string;
Expand Down Expand Up @@ -167,7 +168,7 @@ export namespace GitReference {
return {
name: options.name,
ref: ref,
refType: 'revision',
refType: 'stash',
repoPath: repoPath,
number: options.number,
message: options.message,
Expand Down Expand Up @@ -210,7 +211,7 @@ export namespace GitReference {
}

export function isStash(ref: GitReference | undefined): ref is GitStashReference {
return ref?.refType === 'revision' && (ref as any)?.stashName;
return ref?.refType === 'stash' || (ref?.refType === 'revision' && (ref as any)?.stashName);
}

export function isTag(ref: GitReference | undefined): ref is GitTagReference {
Expand Down
7 changes: 7 additions & 0 deletions src/git/models/stashCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
import { GitCommitType } from './commit';
import { GitFile } from './file';
import { GitLogCommit } from './logCommit';
import { GitReference } from './models';
import { memoize } from '../../system';

const stashNumberRegex = /stash@{(\d+)}/;

export class GitStashCommit extends GitLogCommit {
static isOfRefType(commit: GitReference | undefined) {
return commit?.refType === 'stash';
}

static is(commit: any): commit is GitStashCommit {
return (
commit instanceof GitStashCommit
Expand All @@ -16,6 +21,8 @@ export class GitStashCommit extends GitLogCommit {
);
}

readonly refType = 'stash';

constructor(
type: GitCommitType,
public readonly stashName: string,
Expand Down
10 changes: 5 additions & 5 deletions src/views/nodes/branchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewBranchesLayout } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { BranchDateFormatting, GitBranch, GitLog, GitRemoteType } from '../../git/git';
import { BranchDateFormatting, GitBranch, GitBranchReference, GitLog, GitRemoteType } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { debug, gate, Iterables, log, Strings } from '../../system';
import { RepositoriesView } from '../repositoriesView';
Expand All @@ -14,7 +14,7 @@ import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, ViewNode, ViewRefNode } from './viewNode';
import { RepositoryNode } from './repositoryNode';

export class BranchNode extends ViewRefNode<RepositoriesView> implements PageableViewNode {
export class BranchNode extends ViewRefNode<RepositoriesView, GitBranchReference> implements PageableViewNode {
static key = ':branch';
static getId(repoPath: string, name: string, root: boolean): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${name})${root ? ':root' : ''}`;
Expand Down Expand Up @@ -56,8 +56,8 @@ export class BranchNode extends ViewRefNode<RepositoriesView> implements Pageabl
: this.branch.getBasename();
}

get ref(): string {
return this.branch.ref;
get ref(): GitBranchReference {
return this.branch;
}

get treeHierarchy(): string[] {
Expand Down Expand Up @@ -236,7 +236,7 @@ export class BranchNode extends ViewRefNode<RepositoriesView> implements Pageabl
if (this._log === undefined) {
this._log = await Container.git.getLog(this.uri.repoPath!, {
limit: this.limit ?? this.view.config.defaultItemLimit,
ref: this.ref,
ref: this.ref.ref,
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/views/nodes/commitFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Command, Selection, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../../commands';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { CommitFormatter, GitFile, GitLogCommit, StatusFileFormatter } from '../../git/git';
import { CommitFormatter, GitFile, GitLogCommit, GitRevisionReference, StatusFileFormatter } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { View } from '../viewBase';
import { ResourceType, ViewNode, ViewRefFileNode } from './viewNode';
Expand Down Expand Up @@ -32,8 +32,8 @@ export class CommitFileNode extends ViewRefFileNode {
return 0;
}

get ref(): string {
return this.commit.sha;
get ref(): GitRevisionReference {
return this.commit;
}

getChildren(): ViewNode[] {
Expand Down
8 changes: 4 additions & 4 deletions src/views/nodes/commitNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Commands, DiffWithPreviousCommandArgs } from '../../commands';
import { ViewFilesLayout } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { CommitFormatter, GitBranch, GitLogCommit } from '../../git/git';
import { CommitFormatter, GitBranch, GitLogCommit, GitRevisionReference } from '../../git/git';
import { Arrays, Iterables, Strings } from '../../system';
import { ViewWithFiles } from '../viewBase';
import { CommitFileNode } from './commitFileNode';
import { FileNode, FolderNode } from './folderNode';
import { ResourceType, ViewNode, ViewRefNode } from './viewNode';

export class CommitNode extends ViewRefNode<ViewWithFiles> {
export class CommitNode extends ViewRefNode<ViewWithFiles, GitRevisionReference> {
constructor(
view: ViewWithFiles,
parent: ViewNode,
Expand All @@ -28,8 +28,8 @@ export class CommitNode extends ViewRefNode<ViewWithFiles> {
return this.commit.sha;
}

get ref(): string {
return this.commit.sha;
get ref(): GitRevisionReference {
return this.commit;
}

getChildren(): ViewNode[] {
Expand Down
6 changes: 3 additions & 3 deletions src/views/nodes/resultsFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as paths from 'path';
import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, DiffWithCommandArgs } from '../../commands';
import { Container } from '../../container';
import { GitFile, StatusFileFormatter } from '../../git/git';
import { GitFile, GitReference, GitRevisionReference, StatusFileFormatter } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { View } from '../viewBase';
import { ResourceType, ViewNode, ViewRefFileNode } from './viewNode';
Expand All @@ -28,8 +28,8 @@ export class ResultsFileNode extends ViewRefFileNode {
return this.file.fileName;
}

get ref() {
return this.ref1 || this.ref2;
get ref(): GitRevisionReference {
return GitReference.create(this.ref1 || this.ref2, this.uri.repoPath!);
}

getChildren(): ViewNode[] {
Expand Down
8 changes: 4 additions & 4 deletions src/views/nodes/stashNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as paths from 'path';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Container } from '../../container';
import { CommitFormatter, GitStashCommit } from '../../git/git';
import { CommitFormatter, GitStashCommit, GitStashReference } from '../../git/git';
import { Arrays, Iterables, Strings } from '../../system';
import { ViewWithFiles } from '../viewBase';
import { StashFileNode } from './stashFileNode';
Expand All @@ -11,7 +11,7 @@ import { RepositoryNode } from './repositoryNode';
import { FileNode, FolderNode } from '../nodes';
import { ViewFilesLayout } from '../../config';

export class StashNode extends ViewRefNode<ViewWithFiles> {
export class StashNode extends ViewRefNode<ViewWithFiles, GitStashReference> {
static key = ':stash';
static getId(repoPath: string, ref: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${ref})`;
Expand All @@ -29,8 +29,8 @@ export class StashNode extends ViewRefNode<ViewWithFiles> {
return StashNode.getId(this.commit.repoPath, this.commit.sha);
}

get ref(): string {
return this.commit.sha;
get ref(): GitStashReference {
return this.commit;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
8 changes: 4 additions & 4 deletions src/views/nodes/tagNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewBranchesLayout } from '../../configuration';
import { Container } from '../../container';
import { GitLog, GitRevision, GitTag, TagDateFormatting } from '../../git/git';
import { GitLog, GitRevision, GitTag, GitTagReference, TagDateFormatting } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { debug, gate, Iterables, Strings } from '../../system';
import { RepositoriesView } from '../repositoriesView';
Expand All @@ -14,7 +14,7 @@ import { emojify } from '../../emojis';
import { RepositoryNode } from './repositoryNode';
import { GlyphChars } from '../../constants';

export class TagNode extends ViewRefNode<RepositoriesView> implements PageableViewNode {
export class TagNode extends ViewRefNode<RepositoriesView, GitTagReference> implements PageableViewNode {
static key = ':tag';
static getId(repoPath: string, name: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${name})`;
Expand All @@ -36,8 +36,8 @@ export class TagNode extends ViewRefNode<RepositoriesView> implements PageableVi
return this.view.config.branches.layout === ViewBranchesLayout.Tree ? this.tag.getBasename() : this.tag.name;
}

get ref(): string {
return this.tag.name;
get ref(): GitTagReference {
return this.tag;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
13 changes: 8 additions & 5 deletions src/views/nodes/viewNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeViewVisibilityChangeEvent } from 'vscode';
import { GitFile } from '../../git/git';
import { GitFile, GitReference, GitRevisionReference } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { Logger } from '../../logger';
import { debug, Functions, gate, logName } from '../../system';
Expand Down Expand Up @@ -98,19 +98,22 @@ export abstract class ViewNode<TView extends View = View> {
}
}

export abstract class ViewRefNode<TView extends View = View> extends ViewNode<TView> {
abstract get ref(): string;
export abstract class ViewRefNode<
TView extends View = View,
TReference extends GitReference = GitReference
> extends ViewNode<TView> {
abstract get ref(): TReference;

get repoPath(): string {
return this.uri.repoPath!;
}

toString() {
return `${super.toString()}:${this.ref}`;
return `${super.toString()}:${GitReference.toString(this.ref, false)}`;
}
}

export abstract class ViewRefFileNode<TView extends View = View> extends ViewRefNode<TView> {
export abstract class ViewRefFileNode<TView extends View = View> extends ViewRefNode<TView, GitRevisionReference> {
abstract get file(): GitFile;
abstract get fileName(): string;

Expand Down

0 comments on commit b5e8d92

Please sign in to comment.