|
@ -1,98 +1,50 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
import { TreeItem, TreeItemCollapsibleState } from 'vscode'; |
|
|
import { TreeItem, TreeItemCollapsibleState } from 'vscode'; |
|
|
|
|
|
import { getRepoPathOrPrompt } from '../../commands'; |
|
|
|
|
|
import { CommandContext, GlyphChars, setCommandContext } from '../../constants'; |
|
|
|
|
|
import { GitService } from '../../git/gitService'; |
|
|
|
|
|
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../../quickpicks'; |
|
|
import { debug, Functions, gate, log } from '../../system'; |
|
|
import { debug, Functions, gate, log } from '../../system'; |
|
|
import { ResultsView } from '../resultsView'; |
|
|
import { ResultsView } from '../resultsView'; |
|
|
import { MessageNode } from './common'; |
|
|
import { MessageNode } from './common'; |
|
|
import { ResourceType, unknownGitUri, ViewNode } from './viewNode'; |
|
|
|
|
|
|
|
|
import { ComparePickerNode } from './comparePickerNode'; |
|
|
|
|
|
import { NamedRef, ResourceType, unknownGitUri, ViewNode } from './viewNode'; |
|
|
|
|
|
|
|
|
|
|
|
interface RepoRef { |
|
|
|
|
|
label: string; |
|
|
|
|
|
repoPath: string; |
|
|
|
|
|
ref: string | NamedRef; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export class ResultsNode extends ViewNode<ResultsView> { |
|
|
export class ResultsNode extends ViewNode<ResultsView> { |
|
|
private _children: (ViewNode | MessageNode)[] = []; |
|
|
private _children: (ViewNode | MessageNode)[] = []; |
|
|
|
|
|
private _comparePickerNode: ComparePickerNode | undefined; |
|
|
|
|
|
|
|
|
constructor(view: ResultsView) { |
|
|
constructor(view: ResultsView) { |
|
|
super(unknownGitUri, view); |
|
|
super(unknownGitUri, view); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _selectedRef: RepoRef | undefined; |
|
|
|
|
|
get selectedRef(): RepoRef | undefined { |
|
|
|
|
|
return this._selectedRef; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
async getChildren(): Promise<ViewNode[]> { |
|
|
async getChildren(): Promise<ViewNode[]> { |
|
|
if (this._children.length === 0) { |
|
|
if (this._children.length === 0) { |
|
|
this._children = []; |
|
|
|
|
|
|
|
|
|
|
|
// const command = {
|
|
|
|
|
|
// title: 'Search Commits',
|
|
|
|
|
|
// command: 'gitlens.showCommitSearch'
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
// return [
|
|
|
|
|
|
// new CommandMessageNode(
|
|
|
|
|
|
// this.view,
|
|
|
|
|
|
// this,
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ...command,
|
|
|
|
|
|
// arguments: [this, { searchBy: GitRepoSearchBy.Message } as ShowCommitSearchCommandArgs]
|
|
|
|
|
|
// },
|
|
|
|
|
|
// `Start a commit search by`,
|
|
|
|
|
|
// 'Click to search'
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// new CommandMessageNode(
|
|
|
|
|
|
// this.view,
|
|
|
|
|
|
// this,
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ...command,
|
|
|
|
|
|
// arguments: [this, { searchBy: GitRepoSearchBy.Message } as ShowCommitSearchCommandArgs]
|
|
|
|
|
|
// },
|
|
|
|
|
|
// `${GlyphChars.Space.repeat(4)} message ${Strings.pad(GlyphChars.Dash, 1, 1)} use <message-pattern>`,
|
|
|
|
|
|
// 'Click to search by message'
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// new CommandMessageNode(
|
|
|
|
|
|
// this.view,
|
|
|
|
|
|
// this,
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ...command,
|
|
|
|
|
|
// arguments: [this, { searchBy: GitRepoSearchBy.Author } as ShowCommitSearchCommandArgs]
|
|
|
|
|
|
// },
|
|
|
|
|
|
// `${GlyphChars.Space.repeat(4)} author ${Strings.pad(GlyphChars.Dash, 1, 1)} use @<author-pattern>`,
|
|
|
|
|
|
// 'Click to search by author'
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// new CommandMessageNode(
|
|
|
|
|
|
// this.view,
|
|
|
|
|
|
// this,
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ...command,
|
|
|
|
|
|
// arguments: [this, { searchBy: GitRepoSearchBy.Sha } as ShowCommitSearchCommandArgs]
|
|
|
|
|
|
// },
|
|
|
|
|
|
// `${GlyphChars.Space.repeat(4)} commit id ${Strings.pad(GlyphChars.Dash, 1, 1)} use #<sha>`,
|
|
|
|
|
|
// 'Click to search by commit id'
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// new CommandMessageNode(
|
|
|
|
|
|
// this.view,
|
|
|
|
|
|
// this,
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ...command,
|
|
|
|
|
|
// arguments: [this, { searchBy: GitRepoSearchBy.Files } as ShowCommitSearchCommandArgs]
|
|
|
|
|
|
// },
|
|
|
|
|
|
// `${GlyphChars.Space.repeat(4)} files ${Strings.pad(GlyphChars.Dash, 1, 1)} use :<file-pattern>`,
|
|
|
|
|
|
// 'Click to search by files'
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// new CommandMessageNode(
|
|
|
|
|
|
// this.view,
|
|
|
|
|
|
// this,
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ...command,
|
|
|
|
|
|
// arguments: [this, { searchBy: GitRepoSearchBy.Changes } as ShowCommitSearchCommandArgs]
|
|
|
|
|
|
// },
|
|
|
|
|
|
// `${GlyphChars.Space.repeat(4)} changes ${Strings.pad(GlyphChars.Dash, 1, 1)} use =<pattern>`,
|
|
|
|
|
|
// 'Click to search by changes'
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// new CommandMessageNode(
|
|
|
|
|
|
// this.view,
|
|
|
|
|
|
// this,
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ...command,
|
|
|
|
|
|
// arguments: [this, { searchBy: GitRepoSearchBy.ChangedLines } as ShowCommitSearchCommandArgs]
|
|
|
|
|
|
// },
|
|
|
|
|
|
// `${GlyphChars.Space.repeat(4)} changed lines ${Strings.pad(GlyphChars.Dash, 1, 1)} use ~<pattern>`,
|
|
|
|
|
|
// 'Click to search by changed lines'
|
|
|
|
|
|
// )
|
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
|
// Not really sure why I can't reuse this node -- but if I do the Tree errors out with an id already exists error
|
|
|
|
|
|
this._comparePickerNode = new ComparePickerNode(this.view, this); |
|
|
|
|
|
this._children = [this._comparePickerNode]; |
|
|
|
|
|
} |
|
|
|
|
|
else if ( |
|
|
|
|
|
this._selectedRef !== undefined && |
|
|
|
|
|
(this._comparePickerNode === undefined || !this._children.includes(this._comparePickerNode)) |
|
|
|
|
|
) { |
|
|
|
|
|
// Not really sure why I can't reuse this node -- but if I do the Tree errors out with an id already exists error
|
|
|
|
|
|
this._comparePickerNode = new ComparePickerNode(this.view, this); |
|
|
|
|
|
this._children.splice(0, 0, this._comparePickerNode); |
|
|
|
|
|
|
|
|
|
|
|
const node = this._comparePickerNode; |
|
|
|
|
|
setImmediate(() => this.view.reveal(node, { focus: false, select: true })); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return this._children; |
|
|
return this._children; |
|
@ -112,6 +64,13 @@ export class ResultsNode extends ViewNode { |
|
|
this._children.push(results); |
|
|
this._children.push(results); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
if (this._comparePickerNode !== undefined) { |
|
|
|
|
|
const index = this._children.indexOf(this._comparePickerNode); |
|
|
|
|
|
if (index !== -1) { |
|
|
|
|
|
this._children.splice(index, 1); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this._children.splice(0, 0, results); |
|
|
this._children.splice(0, 0, results); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -120,7 +79,8 @@ export class ResultsNode extends ViewNode { |
|
|
|
|
|
|
|
|
@log() |
|
|
@log() |
|
|
clear() { |
|
|
clear() { |
|
|
if (this._children.length === 0) return; |
|
|
|
|
|
|
|
|
this._selectedRef = undefined; |
|
|
|
|
|
setCommandContext(CommandContext.ViewsCanCompare, false); |
|
|
|
|
|
|
|
|
this._children.length = 0; |
|
|
this._children.length = 0; |
|
|
this.view.triggerNodeChange(); |
|
|
this.view.triggerNodeChange(); |
|
@ -130,12 +90,15 @@ export class ResultsNode extends ViewNode { |
|
|
args: { 0: (n: ViewNode) => n.toString() } |
|
|
args: { 0: (n: ViewNode) => n.toString() } |
|
|
}) |
|
|
}) |
|
|
dismiss(node: ViewNode) { |
|
|
dismiss(node: ViewNode) { |
|
|
if (this._children.length === 0) return; |
|
|
|
|
|
|
|
|
this._selectedRef = undefined; |
|
|
|
|
|
setCommandContext(CommandContext.ViewsCanCompare, false); |
|
|
|
|
|
|
|
|
const index = this._children.findIndex(n => n === node); |
|
|
|
|
|
if (index === -1) return; |
|
|
|
|
|
|
|
|
if (this._children.length !== 0) { |
|
|
|
|
|
const index = this._children.indexOf(node); |
|
|
|
|
|
if (index === -1) return; |
|
|
|
|
|
|
|
|
this._children.splice(index, 1); |
|
|
|
|
|
|
|
|
this._children.splice(index, 1); |
|
|
|
|
|
} |
|
|
this.view.triggerNodeChange(); |
|
|
this.view.triggerNodeChange(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -146,4 +109,61 @@ export class ResultsNode extends ViewNode { |
|
|
|
|
|
|
|
|
await Promise.all(this._children.map(c => c.refresh()).filter(Functions.isPromise) as Promise<any>[]); |
|
|
await Promise.all(this._children.map(c => c.refresh()).filter(Functions.isPromise) as Promise<any>[]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async compareWithSelected(repoPath?: string, ref?: string | NamedRef) { |
|
|
|
|
|
if (this._selectedRef === undefined) return; |
|
|
|
|
|
|
|
|
|
|
|
if (repoPath === undefined) { |
|
|
|
|
|
repoPath = this._selectedRef.repoPath; |
|
|
|
|
|
} |
|
|
|
|
|
else if (repoPath !== this._selectedRef.repoPath) { |
|
|
|
|
|
// If we don't have a matching repoPath, then start over
|
|
|
|
|
|
this.selectForCompare(repoPath, ref); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ref === undefined) { |
|
|
|
|
|
const pick = await new BranchesAndTagsQuickPick(repoPath).show( |
|
|
|
|
|
`Compare ${this.getRefName(this._selectedRef.ref)} to${GlyphChars.Ellipsis}` |
|
|
|
|
|
); |
|
|
|
|
|
if (pick === undefined || pick instanceof CommandQuickPickItem) return; |
|
|
|
|
|
|
|
|
|
|
|
ref = pick.name; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ref1 = this._selectedRef; |
|
|
|
|
|
|
|
|
|
|
|
this._selectedRef = undefined; |
|
|
|
|
|
setCommandContext(CommandContext.ViewsCanCompare, false); |
|
|
|
|
|
|
|
|
|
|
|
void (await this.view.compare(repoPath, ref1.ref, ref)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async selectForCompare(repoPath?: string, ref?: string | NamedRef) { |
|
|
|
|
|
if (repoPath === undefined) { |
|
|
|
|
|
repoPath = await getRepoPathOrPrompt( |
|
|
|
|
|
undefined, |
|
|
|
|
|
`Select branch or tag in which repository${GlyphChars.Ellipsis}` |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
if (repoPath === undefined) return; |
|
|
|
|
|
|
|
|
|
|
|
if (ref === undefined) { |
|
|
|
|
|
const pick = await new BranchesAndTagsQuickPick(repoPath).show( |
|
|
|
|
|
`Select branch or tag for compare${GlyphChars.Ellipsis}` |
|
|
|
|
|
); |
|
|
|
|
|
if (pick === undefined || pick instanceof CommandQuickPickItem) return; |
|
|
|
|
|
|
|
|
|
|
|
ref = pick.name; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this._selectedRef = { label: this.getRefName(ref), repoPath: repoPath, ref: ref }; |
|
|
|
|
|
setCommandContext(CommandContext.ViewsCanCompare, true); |
|
|
|
|
|
|
|
|
|
|
|
void (await this.triggerChange()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getRefName(ref: string | NamedRef) { |
|
|
|
|
|
return typeof ref === 'string' ? GitService.shortenSha(ref)! : ref.label || GitService.shortenSha(ref.ref)!; |
|
|
|
|
|
} |
|
|
} |
|
|
} |