diff --git a/src/commands/diffBranchWith.ts b/src/commands/diffBranchWith.ts index fcc47b4..85f6f50 100644 --- a/src/commands/diffBranchWith.ts +++ b/src/commands/diffBranchWith.ts @@ -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, @@ -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; diff --git a/src/commands/openBranchInRemote.ts b/src/commands/openBranchInRemote.ts index d9e8b70..4d5414d 100644 --- a/src/commands/openBranchInRemote.ts +++ b/src/commands/openBranchInRemote.ts @@ -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, @@ -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; diff --git a/src/commands/openFileInRemote.ts b/src/commands/openFileInRemote.ts index 95041cc..70687e0 100644 --- a/src/commands/openFileInRemote.ts +++ b/src/commands/openFileInRemote.ts @@ -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, @@ -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; diff --git a/src/commands/showQuickBranchHistory.ts b/src/commands/showQuickBranchHistory.ts index b796983..eeb10a6 100644 --- a/src/commands/showQuickBranchHistory.ts +++ b/src/commands/showQuickBranchHistory.ts @@ -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'; @@ -62,7 +67,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { { checkmarks: false, goBack: goBackCommand, - include: 'branches' + include: ReferencesQuickPickIncludes.Branches } ); if (pick === undefined) return undefined; diff --git a/src/quickpicks/gitQuickPicks.ts b/src/quickpicks/gitQuickPicks.ts index 8cebd71..1830c3c 100644 --- a/src/quickpicks/gitQuickPicks.ts +++ b/src/quickpicks/gitQuickPicks.ts @@ -205,7 +205,31 @@ export interface RefQuickPickItem extends QuickPickItemOfT { } 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 = { diff --git a/src/quickpicks/referencesQuickPick.ts b/src/quickpicks/referencesQuickPick.ts index 1bac655..5324cae 100644 --- a/src/quickpicks/referencesQuickPick.ts +++ b/src/quickpicks/referencesQuickPick.ts @@ -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; @@ -17,7 +25,7 @@ export interface ReferencesQuickPickOptions { filterBranches?(branch: GitBranch): boolean; filterTags?(tag: GitTag): boolean; goBack?: CommandQuickPickItem; - include?: 'branches' | 'tags' | 'all'; + include?: ReferencesQuickPickIncludes; } export class ReferencesQuickPick { @@ -25,11 +33,15 @@ export class ReferencesQuickPick { async show( placeHolder: string, - options?: Exclude & { include: 'branches' } + options?: Exclude & { + include: ReferencesQuickPickIncludes.Branches; + } ): Promise; async show( placeHolder: string, - options?: Exclude & { include: 'tags' } + options?: Exclude & { + include: ReferencesQuickPickIncludes.Tags; + } ): Promise; async show( placeHolder: string, @@ -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([ - 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, @@ -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); } diff --git a/src/views/nodes/compareNode.ts b/src/views/nodes/compareNode.ts index 5de8f0d..a2a12c6 100644 --- a/src/views/nodes/compareNode.ts +++ b/src/views/nodes/compareNode.ts @@ -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'; @@ -143,7 +143,8 @@ export class CompareNode extends ViewNode { 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) { @@ -179,7 +180,8 @@ export class CompareNode extends ViewNode { 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();