Browse Source

Closes #684 - adds checkout to files

main
Eric Amodio 5 years ago
parent
commit
7b7b788be1
6 changed files with 52 additions and 32 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +12
    -2
      package.json
  3. +6
    -2
      src/views/nodes/commitFileNode.ts
  4. +8
    -4
      src/views/nodes/resultsFileNode.ts
  5. +4
    -0
      src/views/nodes/viewNode.ts
  6. +21
    -24
      src/views/viewCommands.ts

+ 1
- 0
CHANGELOG.md View File

@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Added ### Added
- Adds a _Checkout_ command to file nodes in the views to replace the local file with the specified revision — closes [#684](https://github.com/eamodio/vscode-gitlens/issues/684)
- Adds a prompt to enable the view to the _Show \* View_ commands when the specified view is disabled — closes [#710](https://github.com/eamodio/vscode-gitlens/issues/710) & [#711](https://github.com/eamodio/vscode-gitlens/issues/711) - Adds a prompt to enable the view to the _Show \* View_ commands when the specified view is disabled — closes [#710](https://github.com/eamodio/vscode-gitlens/issues/710) & [#711](https://github.com/eamodio/vscode-gitlens/issues/711)
### Removed ### Removed

+ 12
- 2
package.json View File

@ -4320,19 +4320,29 @@
"group": "5_gitlens_1@1" "group": "5_gitlens_1@1"
}, },
{ {
"command": "gitlens.views.checkout",
"when": "viewItem =~ /gitlens:file:(commit|results)\\b/",
"group": "5_gitlens_1@2"
},
{
"command": "gitlens.views.applyChanges", "command": "gitlens.views.applyChanges",
"when": "!gitlens:readonly && viewItem == gitlens:file:stash", "when": "!gitlens:readonly && viewItem == gitlens:file:stash",
"group": "1_gitlens@1" "group": "1_gitlens@1"
}, },
{ {
"command": "gitlens.views.checkout",
"when": "!gitlens:readonly && viewItem == gitlens:file:stash",
"group": "1_gitlens@2"
},
{
"command": "gitlens.showQuickCommitDetails", "command": "gitlens.showQuickCommitDetails",
"when": "viewItem =~ /gitlens:file\\b(?!(:stash|:status))/", "when": "viewItem =~ /gitlens:file\\b(?!(:stash|:status))/",
"group": "5_gitlens_2@2"
"group": "5_gitlens_2@1"
}, },
{ {
"command": "gitlens.showCommitInView", "command": "gitlens.showCommitInView",
"when": "viewItem =~ /gitlens:file\\b(?!(:stash|:status))/", "when": "viewItem =~ /gitlens:file\\b(?!(:stash|:status))/",
"group": "5_gitlens_2@3"
"group": "5_gitlens_2@2"
}, },
{ {
"command": "gitlens.showQuickFileHistory", "command": "gitlens.showQuickFileHistory",

+ 6
- 2
src/views/nodes/commitFileNode.ts View File

@ -6,7 +6,7 @@ import { GlyphChars } from '../../constants';
import { Container } from '../../container'; import { Container } from '../../container';
import { CommitFormatter, GitFile, GitLogCommit, GitUri, StatusFileFormatter } from '../../git/gitService'; import { CommitFormatter, GitFile, GitLogCommit, GitUri, StatusFileFormatter } from '../../git/gitService';
import { View } from '../viewBase'; import { View } from '../viewBase';
import { ResourceType, ViewNode, ViewRefNode } from './viewNode';
import { ResourceType, ViewNode, ViewRefFileNode } from './viewNode';
export enum CommitFileNodeDisplayAs { export enum CommitFileNodeDisplayAs {
CommitLabel = 1 << 0, CommitLabel = 1 << 0,
@ -19,7 +19,7 @@ export enum CommitFileNodeDisplayAs {
File = FileLabel | StatusIcon File = FileLabel | StatusIcon
} }
export class CommitFileNode extends ViewRefNode {
export class CommitFileNode extends ViewRefFileNode {
constructor( constructor(
view: View, view: View,
parent: ViewNode, parent: ViewNode,
@ -31,6 +31,10 @@ export class CommitFileNode extends ViewRefNode {
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent); super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent);
} }
get fileName(): string {
return this.file.fileName;
}
get priority(): number { get priority(): number {
return 0; return 0;
} }

+ 8
- 4
src/views/nodes/resultsFileNode.ts View File

@ -5,9 +5,9 @@ import { Commands, DiffWithCommandArgs } from '../../commands';
import { Container } from '../../container'; import { Container } from '../../container';
import { GitFile, GitUri, StatusFileFormatter } from '../../git/gitService'; import { GitFile, GitUri, StatusFileFormatter } from '../../git/gitService';
import { View } from '../viewBase'; import { View } from '../viewBase';
import { ResourceType, ViewNode } from './viewNode';
import { ResourceType, ViewNode, ViewRefFileNode } from './viewNode';
export class ResultsFileNode extends ViewNode {
export class ResultsFileNode extends ViewRefFileNode {
constructor( constructor(
view: View, view: View,
parent: ViewNode, parent: ViewNode,
@ -16,11 +16,15 @@ export class ResultsFileNode extends ViewNode {
public readonly ref1: string, public readonly ref1: string,
public readonly ref2: string public readonly ref2: string
) { ) {
super(GitUri.fromFile(file, repoPath, ref1 ? ref1 : ref2 ? ref2 : undefined), view, parent);
super(GitUri.fromFile(file, repoPath, ref1 || ref2), view, parent);
}
get fileName(): string {
return this.file.fileName;
} }
get ref() { get ref() {
return this.ref1 ? this.ref1 : this.ref2 ? this.ref2 : undefined;
return this.ref1 || this.ref2;
} }
getChildren(): ViewNode[] { getChildren(): ViewNode[] {

+ 4
- 0
src/views/nodes/viewNode.ts View File

@ -113,6 +113,10 @@ export abstract class ViewRefNode extends ViewNode
} }
} }
export abstract class ViewRefFileNode<TView extends View = View> extends ViewRefNode<TView> {
abstract get fileName(): string;
}
export interface PageableViewNode { export interface PageableViewNode {
readonly supportsPaging: boolean; readonly supportsPaging: boolean;
maxCount: number | undefined; maxCount: number | undefined;

+ 21
- 24
src/views/viewCommands.ts View File

@ -34,6 +34,7 @@ import {
StatusFileNode, StatusFileNode,
TagNode, TagNode,
ViewNode, ViewNode,
ViewRefFileNode,
ViewRefNode, ViewRefNode,
viewSupportsNodeDismissal viewSupportsNodeDismissal
} from './nodes'; } from './nodes';
@ -210,10 +211,8 @@ export class ViewCommands implements Disposable {
return node.push({ force: force }); return node.push({ force: force });
} }
private async applyChanges(node: CommitFileNode | StashFileNode | ResultsFileNode) {
if (!(node instanceof CommitFileNode) && !(node instanceof ResultsFileNode)) {
return;
}
private async applyChanges(node: ViewRefFileNode) {
if (!(node instanceof ViewRefFileNode)) return;
void (await this.openFile(node)); void (await this.openFile(node));
@ -228,9 +227,13 @@ export class ViewCommands implements Disposable {
} }
} }
private checkout(node: ViewRefNode) {
private checkout(node: ViewRefNode | ViewRefFileNode) {
if (!(node instanceof ViewRefNode)) return undefined; if (!(node instanceof ViewRefNode)) return undefined;
if (node instanceof ViewRefFileNode) {
return Container.git.checkout(node.repoPath, node.ref, node.fileName);
}
return Container.git.checkout(node.repoPath, node.ref); return Container.git.checkout(node.repoPath, node.ref);
} }
@ -287,14 +290,11 @@ export class ViewCommands implements Disposable {
Container.compareView.selectForCompare(node.repoPath, node.ref); Container.compareView.selectForCompare(node.repoPath, node.ref);
} }
private compareFileWithSelected(node: CommitFileNode | ResultsFileNode | StashFileNode) {
if (
this._selectedFile === undefined ||
(!(node instanceof CommitFileNode) && !(node instanceof ResultsFileNode)) ||
node.ref === undefined
) {
private compareFileWithSelected(node: ViewRefFileNode) {
if (this._selectedFile === undefined || !(node instanceof ViewRefFileNode) || node.ref === undefined) {
return undefined; return undefined;
} }
if (this._selectedFile.repoPath !== node.repoPath) { if (this._selectedFile.repoPath !== node.repoPath) {
this.selectFileForCompare(node); this.selectFileForCompare(node);
return undefined; return undefined;
@ -321,8 +321,8 @@ export class ViewCommands implements Disposable {
private _selectedFile: CompareSelectedInfo | undefined; private _selectedFile: CompareSelectedInfo | undefined;
private selectFileForCompare(node: CommitFileNode | ResultsFileNode | StashFileNode) {
if ((!(node instanceof CommitFileNode) && !(node instanceof ResultsFileNode)) || node.ref === undefined) return;
private selectFileForCompare(node: ViewRefFileNode) {
if (!(node instanceof ViewRefFileNode) || node.ref === undefined) return;
this._selectedFile = { this._selectedFile = {
ref: node.ref, ref: node.ref,
@ -343,8 +343,8 @@ export class ViewCommands implements Disposable {
void commands.executeCommand(BuiltInCommands.FocusFilesExplorer); void commands.executeCommand(BuiltInCommands.FocusFilesExplorer);
} }
private openChanges(node: CommitFileNode | ResultsFileNode | StashFileNode) {
if (!(node instanceof CommitFileNode) && !(node instanceof ResultsFileNode)) return undefined;
private openChanges(node: ViewRefFileNode) {
if (!(node instanceof ViewRefFileNode)) return undefined;
const command = node.getCommand(); const command = node.getCommand();
if (command === undefined || command.arguments === undefined) return undefined; if (command === undefined || command.arguments === undefined) return undefined;
@ -354,8 +354,8 @@ export class ViewCommands implements Disposable {
return commands.executeCommand(command.command, uri, args); return commands.executeCommand(command.command, uri, args);
} }
private async openChangesWithWorking(node: CommitFileNode | ResultsFileNode | StashFileNode) {
if (!(node instanceof CommitFileNode) && !(node instanceof ResultsFileNode)) return undefined;
private async openChangesWithWorking(node: ViewRefFileNode) {
if (!(node instanceof ViewRefFileNode)) return undefined;
const args: DiffWithWorkingCommandArgs = { const args: DiffWithWorkingCommandArgs = {
showOptions: { showOptions: {
@ -375,15 +375,12 @@ export class ViewCommands implements Disposable {
return commands.executeCommand(Commands.DiffWithWorking, node.uri, args); return commands.executeCommand(Commands.DiffWithWorking, node.uri, args);
} }
private openFile(
node: CommitFileNode | FileHistoryNode | LineHistoryNode | ResultsFileNode | StashFileNode | StatusFileNode
) {
private openFile(node: ViewRefFileNode | StatusFileNode | FileHistoryNode | LineHistoryNode) {
if ( if (
!(node instanceof CommitFileNode) &&
!(node instanceof ViewRefFileNode) &&
!(node instanceof StatusFileNode) &&
!(node instanceof FileHistoryNode) && !(node instanceof FileHistoryNode) &&
!(node instanceof LineHistoryNode) &&
!(node instanceof ResultsFileNode) &&
!(node instanceof StatusFileNode)
!(node instanceof LineHistoryNode)
) { ) {
return undefined; return undefined;
} }

Loading…
Cancel
Save