Просмотр исходного кода

Changes branch/tag/commit to implement GitRef

Adds isOfRefType to branch/tag/commit/ref
main
Eric Amodio 5 лет назад
Родитель
Сommit
7308996088
7 измененных файлов: 60 добавлений и 17 удалений
  1. +5
    -1
      src/commands/diffWithRevision.ts
  2. +2
    -2
      src/commands/openFileRevision.ts
  3. +5
    -1
      src/commands/showQuickFileHistory.ts
  4. +7
    -1
      src/git/models/branch.ts
  5. +17
    -11
      src/git/models/commit.ts
  6. +16
    -0
      src/git/models/models.ts
  7. +8
    -1
      src/git/models/tag.ts

+ 5
- 1
src/commands/diffWithRevision.ts Просмотреть файл

@ -86,7 +86,11 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
}
commandArgs = { ...args };
const icon = GitTag.is(args.reference) ? '$(tag) ' : GitBranch.is(args.reference) ? '$(git-branch) ' : '';
const icon = GitTag.isOfRefType(args.reference)
? '$(tag) '
: GitBranch.isOfRefType(args.reference)
? '$(git-branch) '
: '';
const currentCommand = new CommandQuickPickItem(
{
label: `go back ${GlyphChars.ArrowBack}`,

+ 2
- 2
src/commands/openFileRevision.ts Просмотреть файл

@ -116,9 +116,9 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
}
commandArgs = { ...args };
const icon = GitTag.is(args.reference)
const icon = GitTag.isOfRefType(args.reference)
? '$(tag) '
: GitBranch.is(args.reference)
: GitBranch.isOfRefType(args.reference)
? '$(git-branch) '
: '';
const currentCommand = new CommandQuickPickItem(

+ 5
- 1
src/commands/showQuickFileHistory.ts Просмотреть файл

@ -108,7 +108,11 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
}
}
const icon = GitTag.is(args.reference) ? '$(tag) ' : GitBranch.is(args.reference) ? '$(git-branch) ' : '';
const icon = GitTag.isOfRefType(args.reference)
? '$(tag) '
: GitBranch.isOfRefType(args.reference)
? '$(git-branch) '
: '';
// Create a command to get back to where we are right now
const currentCommand = new CommandQuickPickItem(
{

+ 7
- 1
src/git/models/branch.ts Просмотреть файл

@ -4,6 +4,7 @@ import { Container } from '../../container';
import { Git, GitRemote } from '../git';
import { GitStatus } from './status';
import { memoize } from '../../system';
import { GitReference } from './models';
const whitespaceRegex = /\s/;
@ -12,11 +13,15 @@ export interface GitTrackingState {
behind: number;
}
export class GitBranch {
export class GitBranch implements GitReference {
static is(branch: any): branch is GitBranch {
return branch instanceof GitBranch;
}
static isOfRefType(branch: GitReference | undefined) {
return branch !== undefined && branch.refType === 'branch';
}
static sort(branches: GitBranch[]) {
return branches.sort(
(a, b) =>
@ -27,6 +32,7 @@ export class GitBranch {
);
}
readonly refType = 'branch';
readonly detached: boolean;
readonly id: string;
readonly tracking?: string;

+ 17
- 11
src/git/models/commit.ts Просмотреть файл

@ -7,6 +7,7 @@ import { CommitFormatter } from '../formatters/formatters';
import { Git } from '../git';
import { GitUri } from '../gitUri';
import { getAvatarUri } from '../../avatars';
import { GitReference } from './models';
export interface GitAuthor {
name: string;
@ -41,20 +42,17 @@ export const CommitFormatting = {
}
};
export abstract class GitCommit {
export abstract class GitCommit implements GitReference {
static is(commit: any): commit is GitCommit {
return (
commit instanceof GitCommit
// || (commit.repoPath !== undefined &&
// commit.sha !== undefined &&
// (commit.type === GitCommitType.Blame ||
// commit.type === GitCommitType.Log ||
// commit.type === GitCommitType.LogFile ||
// commit.type === GitCommitType.Stash ||
// commit.type === GitCommitType.StashFile))
);
return commit instanceof GitCommit;
}
static isOfRefType(branch: GitReference | undefined) {
return branch !== undefined && branch.refType === 'revision';
}
readonly refType = 'revision';
constructor(
public readonly type: GitCommitType,
public readonly repoPath: string,
@ -72,6 +70,14 @@ export abstract class GitCommit {
this._fileName = fileName || '';
}
get ref() {
return this.sha;
}
get name() {
return this.shortSha;
}
private readonly _fileName: string;
get fileName() {
// If we aren't a single-file commit, return an empty file name (makes it default to the repoPath)

+ 16
- 0
src/git/models/models.ts Просмотреть файл

@ -1,10 +1,26 @@
'use strict';
import { Git } from '../git';
export interface GitReference {
readonly refType: 'branch' | 'tag' | 'revision';
name: string;
ref: string;
}
export namespace GitReference {
export function create(
ref: string,
{ name, refType }: { name?: string; refType?: 'branch' | 'tag' } = {}
): GitReference {
return { name: name || Git.shortenSha(ref, { force: true }), ref: ref, refType: refType || 'revision' };
}
export function isOfRefType(ref: GitReference | undefined, refType: 'branch' | 'tag' | 'revision' = 'revision') {
return ref !== undefined && ref.refType === refType;
}
}
export * from './blame';
export * from './blameCommit';
export * from './branch';

+ 8
- 1
src/git/models/tag.ts Просмотреть файл

@ -1,15 +1,22 @@
'use strict';
import { memoize } from '../../system';
import { GitReference } from './models';
export class GitTag {
export class GitTag implements GitReference {
static is(tag: any): tag is GitTag {
return tag instanceof GitTag;
}
static isOfRefType(tag: GitReference | undefined) {
return tag !== undefined && tag.refType === 'tag';
}
static sort(tags: GitTag[]) {
return tags.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
}
readonly refType = 'tag';
constructor(
public readonly repoPath: string,
public readonly name: string,

Загрузка…
Отмена
Сохранить