Skip to content

Commit

Permalink
Adds Working Tree to branch/tag compare quickpick
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Sep 4, 2019
1 parent 2c2741c commit b7686f1
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/commands/diffBranchWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GlyphChars } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem, ReferencesQuickPick } from '../quickpicks';
import { CommandQuickPickItem, ReferencesQuickPick, ReferencesQuickPickIncludes } from '../quickpicks';
import {
ActiveEditorCommand,
command,
Expand Down Expand Up @@ -80,7 +80,8 @@ export class DiffBranchWithCommand extends ActiveEditorCommand {
const pick = await new ReferencesQuickPick(repoPath).show(placeHolder, {
allowEnteringRefs: true,
checked: args.ref1,
checkmarks: checkmarks
checkmarks: checkmarks,
include: ReferencesQuickPickIncludes.BranchesAndTags | ReferencesQuickPickIncludes.WorkingTree
});
if (pick === undefined) return undefined;

Expand Down
4 changes: 2 additions & 2 deletions src/commands/openBranchInRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitUri, RemoteResourceType } from '../git/gitService';
import { Logger } from '../logger';
import { CommandQuickPickItem, ReferencesQuickPick } from '../quickpicks';
import { CommandQuickPickItem, ReferencesQuickPick, ReferencesQuickPickIncludes } from '../quickpicks';
import {
ActiveEditorCommand,
command,
Expand Down Expand Up @@ -59,7 +59,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
autoPick: true,
checkmarks: false,
filterBranches: b => b.tracking !== undefined,
include: 'branches'
include: ReferencesQuickPickIncludes.Branches
}
);
if (pick === undefined || pick instanceof CommandQuickPickItem) return undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/openFileInRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitService, GitUri, RemoteResourceType } from '../git/gitService';
import { Logger } from '../logger';
import { CommandQuickPickItem, ReferencesQuickPick } from '../quickpicks';
import { CommandQuickPickItem, ReferencesQuickPick, ReferencesQuickPickIncludes } from '../quickpicks';
import {
ActiveEditorCommand,
command,
Expand Down Expand Up @@ -88,7 +88,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
autoPick: true,
checkmarks: false,
filterBranches: b => b.tracking !== undefined,
include: 'branches'
include: ReferencesQuickPickIncludes.Branches
}
);
if (pick === undefined || pick instanceof CommandQuickPickItem) return undefined;
Expand Down
9 changes: 7 additions & 2 deletions src/commands/showQuickBranchHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { Container } from '../container';
import { GitLog, GitUri } from '../git/gitService';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { BranchHistoryQuickPick, CommandQuickPickItem, ReferencesQuickPick } from '../quickpicks';
import {
BranchHistoryQuickPick,
CommandQuickPickItem,
ReferencesQuickPick,
ReferencesQuickPickIncludes
} from '../quickpicks';
import { ActiveEditorCachedCommand, command, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { ShowQuickCommitDetailsCommandArgs } from './showQuickCommitDetails';

Expand Down Expand Up @@ -62,7 +67,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
{
checkmarks: false,
goBack: goBackCommand,
include: 'branches'
include: ReferencesQuickPickIncludes.Branches
}
);
if (pick === undefined) return undefined;
Expand Down
26 changes: 25 additions & 1 deletion src/quickpicks/gitQuickPicks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,31 @@ export interface RefQuickPickItem extends QuickPickItemOfT<GitReference> {
}

export namespace RefQuickPickItem {
export function create(ref: string, picked?: boolean, options: { ref?: boolean } = {}) {
export function create(ref: string, picked?: boolean, options: { ref?: boolean } = {}): RefQuickPickItem {
if (ref === '') {
return {
label: `${Strings.pad('$(file-directory)', 0, 2)}Working Tree`,
description: '',
picked: picked,
item: GitReference.create(ref, { name: 'Working Tree' }),
current: false,
ref: ref,
remote: false
};
}

if (ref === 'HEAD') {
return {
label: 'HEAD',
description: '',
picked: picked,
item: GitReference.create(ref, { name: 'HEAD' }),
current: false,
ref: ref,
remote: false
};
}

const gitRef = GitReference.create(ref);

const item: RefQuickPickItem = {
Expand Down
28 changes: 22 additions & 6 deletions src/quickpicks/referencesQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import { BranchQuickPickItem, RefQuickPickItem, TagQuickPickItem } from './gitQu

export type ReferencesQuickPickItem = BranchQuickPickItem | TagQuickPickItem | RefQuickPickItem;

export enum ReferencesQuickPickIncludes {
Branches = 1,
Tags = 2,
WorkingTree = 4,

BranchesAndTags = 3
}

export interface ReferencesQuickPickOptions {
allowEnteringRefs?: boolean;
autoPick?: boolean;
Expand All @@ -17,19 +25,23 @@ export interface ReferencesQuickPickOptions {
filterBranches?(branch: GitBranch): boolean;
filterTags?(tag: GitTag): boolean;
goBack?: CommandQuickPickItem;
include?: 'branches' | 'tags' | 'all';
include?: ReferencesQuickPickIncludes;
}

export class ReferencesQuickPick {
constructor(public readonly repoPath: string | undefined) {}

async show(
placeHolder: string,
options?: Exclude<ReferencesQuickPickOptions, CommandQuickPickItem> & { include: 'branches' }
options?: Exclude<ReferencesQuickPickOptions, CommandQuickPickItem> & {
include: ReferencesQuickPickIncludes.Branches;
}
): Promise<BranchQuickPickItem | undefined>;
async show(
placeHolder: string,
options?: Exclude<ReferencesQuickPickOptions, CommandQuickPickItem> & { include: 'tags' }
options?: Exclude<ReferencesQuickPickOptions, CommandQuickPickItem> & {
include: ReferencesQuickPickIncludes.Tags;
}
): Promise<TagQuickPickItem | undefined>;
async show(
placeHolder: string,
Expand Down Expand Up @@ -137,17 +149,17 @@ export class ReferencesQuickPick {
{ checked, checkmarks, filterBranches, filterTags, goBack, include, ...options }: ReferencesQuickPickOptions,
token: CancellationToken
): Promise<(BranchQuickPickItem | TagQuickPickItem | CommandQuickPickItem)[]> {
include = include || 'all';
include = include || ReferencesQuickPickIncludes.BranchesAndTags;

const results = await Promises.cancellable(
Promise.all<GitBranch[] | undefined, GitTag[] | undefined>([
include === 'all' || include === 'branches'
include & ReferencesQuickPickIncludes.Branches
? Container.git.getBranches(this.repoPath, {
...options,
filter: filterBranches && filterBranches
})
: undefined,
include === 'all' || include === 'tags'
include & ReferencesQuickPickIncludes.Tags
? Container.git.getTags(this.repoPath, {
...options,
filter: filterTags && filterTags,
Expand Down Expand Up @@ -207,6 +219,10 @@ export class ReferencesQuickPick {
}
}

if (include & ReferencesQuickPickIncludes.WorkingTree) {
(items as QuickPickItem[]).splice(0, 0, RefQuickPickItem.create('', undefined));
}

if (goBack !== undefined) {
(items as QuickPickItem[]).splice(0, 0, goBack);
}
Expand Down
8 changes: 5 additions & 3 deletions src/views/nodes/compareNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { getRepoPathOrPrompt } from '../../commands';
import { CommandContext, GlyphChars, NamedRef, setCommandContext } from '../../constants';
import { GitService } from '../../git/gitService';
import { ReferencesQuickPick } from '../../quickpicks';
import { ReferencesQuickPick, ReferencesQuickPickIncludes } from '../../quickpicks';
import { debug, gate, Iterables, log, Promises } from '../../system';
import { CompareView } from '../compareView';
import { MessageNode } from './common';
Expand Down Expand Up @@ -143,7 +143,8 @@ export class CompareNode extends ViewNode<CompareView> {
allowEnteringRefs: true,
checked:
typeof this._selectedRef.ref === 'string' ? this._selectedRef.ref : this._selectedRef.ref.ref,
checkmarks: true
checkmarks: true,
include: ReferencesQuickPickIncludes.BranchesAndTags | ReferencesQuickPickIncludes.WorkingTree
}
);
if (pick === undefined) {
Expand Down Expand Up @@ -179,7 +180,8 @@ export class CompareNode extends ViewNode<CompareView> {
if (ref === undefined) {
const pick = await new ReferencesQuickPick(repoPath).show(`Compare${GlyphChars.Ellipsis}`, {
allowEnteringRefs: true,
checkmarks: false
checkmarks: false,
include: ReferencesQuickPickIncludes.BranchesAndTags | ReferencesQuickPickIncludes.WorkingTree
});
if (pick === undefined) {
await this.view.show();
Expand Down

0 comments on commit b7686f1

Please sign in to comment.