Browse Source

Changes many terminal commands to use git commands

main
Eric Amodio 5 years ago
parent
commit
bd91502c5a
2 changed files with 93 additions and 77 deletions
  1. +45
    -45
      package.json
  2. +48
    -32
      src/views/viewCommands.ts

+ 45
- 45
package.json View File

@ -2770,43 +2770,43 @@
"category": "GitLens"
},
{
"command": "gitlens.views.mergeBranchInto",
"title": "Merge Branch into Current",
"command": "gitlens.views.cherryPick",
"title": "Cherry Pick Commit",
"category": "GitLens"
},
{
"command": "gitlens.views.rebaseOntoBranch",
"title": "Rebase Current onto Branch",
"command": "gitlens.views.mergeBranchInto",
"title": "Merge Branch into Current...",
"category": "GitLens"
},
{
"command": "gitlens.views.rebaseOntoUpstream",
"title": "Rebase Current onto Upstream",
"command": "gitlens.views.rebaseOntoBranch",
"title": "Rebase Current onto Branch...",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalCherryPickCommit",
"title": "Cherry Pick Commit (via Terminal)",
"command": "gitlens.views.rebaseOntoCommit",
"title": "Rebase Current onto Commit...",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalPushCommit",
"title": "Push to Commit (via Terminal)",
"command": "gitlens.views.rebaseOntoUpstream",
"title": "Rebase Current onto Upstream...",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalRebaseCommit",
"title": "Rebase to Commit (via Terminal)",
"command": "gitlens.views.reset",
"title": "Reset to Commit",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalResetCommit",
"title": "Reset to Commit (via Terminal)",
"command": "gitlens.views.revert",
"title": "Revert Commit",
"category": "GitLens"
},
{
"command": "gitlens.views.terminalRevertCommit",
"title": "Revert Commit (via Terminal)",
"command": "gitlens.views.terminalPushCommit",
"title": "Push to Commit (via Terminal)",
"category": "GitLens"
},
{
@ -3660,35 +3660,35 @@
"when": "false"
},
{
"command": "gitlens.views.mergeBranchInto",
"command": "gitlens.views.cherryPick",
"when": "false"
},
{
"command": "gitlens.views.rebaseOntoBranch",
"command": "gitlens.views.mergeBranchInto",
"when": "false"
},
{
"command": "gitlens.views.rebaseOntoUpstream",
"command": "gitlens.views.rebaseOntoBranch",
"when": "false"
},
{
"command": "gitlens.views.terminalCherryPickCommit",
"command": "gitlens.views.rebaseOntoCommit",
"when": "false"
},
{
"command": "gitlens.views.terminalPushCommit",
"command": "gitlens.views.rebaseOntoUpstream",
"when": "false"
},
{
"command": "gitlens.views.terminalRebaseCommit",
"command": "gitlens.views.reset",
"when": "false"
},
{
"command": "gitlens.views.terminalResetCommit",
"command": "gitlens.views.revert",
"when": "false"
},
{
"command": "gitlens.views.terminalRevertCommit",
"command": "gitlens.views.terminalPushCommit",
"when": "false"
},
{
@ -4546,9 +4546,29 @@
"group": "inline@98"
},
{
"command": "gitlens.views.revert",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b(?=.*?\\b\\+current\\b)/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.reset",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b(?=.*?\\b\\+current\\b)/",
"group": "1_gitlens@2"
},
{
"command": "gitlens.views.cherryPick",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b(?!.*?\\b\\+current\\b)/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.switchToCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b/",
"group": "1_gitlens@1"
"group": "1_gitlens@3"
},
{
"command": "gitlens.views.rebaseOntoCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b/",
"group": "1_gitlens@4"
},
{
"command": "gitlens.openCommitInRemote",
@ -4602,31 +4622,11 @@
"group": "5_gitlens_1@2"
},
{
"command": "gitlens.views.terminalCherryPickCommit",
"when": "!gitlens:readonly && viewItem == gitlens:commit",
"group": "8_gitlens@1"
},
{
"command": "gitlens.views.terminalPushCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b(?=.*?\\b\\+current\\b)/",
"group": "8_gitlens@2"
},
{
"command": "gitlens.views.terminalRevertCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b(?=.*?\\b\\+current\\b)/",
"group": "8_gitlens@3"
},
{
"command": "gitlens.views.terminalRebaseCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b/",
"group": "8_gitlens@5"
},
{
"command": "gitlens.views.terminalResetCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b/",
"group": "8_gitlens@6"
},
{
"command": "gitlens.views.openFile",
"when": "viewItem =~ /gitlens:(history:(file|line)|status:file)\\b/",
"group": "inline@1"

+ 48
- 32
src/views/viewCommands.ts View File

@ -17,7 +17,7 @@ import {
import { BuiltInCommands, CommandContext, setCommandContext } from '../constants';
import { Container } from '../container';
import { toGitLensFSUri } from '../git/fsProvider';
import { GitService, GitUri } from '../git/gitService';
import { GitReference, GitService, GitUri } from '../git/gitService';
import {
BranchNode,
BranchTrackingStatusNode,
@ -154,17 +154,21 @@ export class ViewCommands {
this
);
commands.registerCommand('gitlens.views.cherryPick', this.cherryPick, this);
commands.registerCommand('gitlens.views.mergeBranchInto', this.merge, this);
commands.registerCommand('gitlens.views.rebaseOntoBranch', this.rebase, this);
commands.registerCommand('gitlens.views.rebaseOntoUpstream', this.rebaseToRemote, this);
commands.registerCommand('gitlens.views.rebaseOntoCommit', this.rebase, this);
commands.registerCommand('gitlens.views.reset', this.reset, this);
commands.registerCommand('gitlens.views.revert', this.revert, this);
commands.registerCommand('gitlens.views.terminalPushCommit', this.terminalPushCommit, this);
commands.registerCommand('gitlens.views.terminalCreateBranch', this.terminalCreateBranch, this);
commands.registerCommand('gitlens.views.terminalDeleteBranch', this.terminalDeleteBranch, this);
commands.registerCommand('gitlens.views.terminalCherryPickCommit', this.terminalCherryPickCommit, this);
commands.registerCommand('gitlens.views.terminalPushCommit', this.terminalPushCommit, this);
commands.registerCommand('gitlens.views.terminalRebaseCommit', this.terminalRebaseCommit, this);
commands.registerCommand('gitlens.views.terminalResetCommit', this.terminalResetCommit, this);
commands.registerCommand('gitlens.views.terminalRevertCommit', this.terminalRevertCommit, this);
commands.registerCommand('gitlens.views.terminalRemoveRemote', this.terminalRemoveRemote, this);
commands.registerCommand('gitlens.views.terminalCreateTag', this.terminalCreateTag, this);
commands.registerCommand('gitlens.views.terminalDeleteTag', this.terminalDeleteTag, this);
@ -252,6 +256,18 @@ export class ViewCommands {
}
}
private async cherryPick(node: CommitNode) {
if (!(node instanceof CommitNode)) return undefined;
const repo = await Container.git.getRepository(node.repoPath);
const args: GitCommandsCommandArgs = {
command: 'cherry-pick',
state: { repo: repo!, references: [GitReference.create(node.ref)] }
};
return commands.executeCommand(Commands.GitCommands, args);
}
private async merge(node: BranchNode | TagNode) {
if (!(node instanceof BranchNode) && !(node instanceof TagNode)) return undefined;
@ -274,12 +290,12 @@ export class ViewCommands {
let args: GitCommandsCommandArgs;
if (node instanceof CommitNode) {
args = {
command: 'rebase',
command: 'rebase',
state: {
repo: repo!,
reference: GitReference.create(node.ref)
}
};
};
} else {
args = {
command: 'rebase',
@ -307,12 +323,36 @@ export class ViewCommands {
return commands.executeCommand(Commands.GitCommands, args);
}
private async reset(node: CommitNode) {
if (!(node instanceof CommitNode)) return undefined;
const repo = await Container.git.getRepository(node.repoPath);
const args: GitCommandsCommandArgs = {
command: 'reset',
state: { repo: repo!, reference: GitReference.create(node.ref) }
};
return commands.executeCommand(Commands.GitCommands, args);
}
private async restore(node: ViewRefFileNode) {
if (!(node instanceof ViewRefFileNode)) return undefined;
return Container.git.checkout(node.repoPath, node.ref, { fileName: node.fileName });
}
private async revert(node: CommitNode) {
if (!(node instanceof CommitNode)) return undefined;
const repo = await Container.git.getRepository(node.repoPath);
const args: GitCommandsCommandArgs = {
command: 'revert',
state: { repo: repo!, references: [GitReference.create(node.ref)] }
};
return commands.executeCommand(Commands.GitCommands, args);
}
private async switch(node: ViewRefNode) {
if (!(node instanceof ViewRefNode)) return undefined;
@ -858,12 +898,6 @@ export class ViewCommands {
runGitCommandInTerminal('checkout', `${node.ref}`, node.repoPath);
}
terminalCherryPickCommit(node: CommitNode) {
if (!(node instanceof CommitNode)) return;
runGitCommandInTerminal('cherry-pick', `-e ${node.ref}`, node.repoPath);
}
async terminalPushCommit(node: CommitNode) {
if (!(node instanceof CommitNode)) return;
@ -873,24 +907,6 @@ export class ViewCommands {
runGitCommandInTerminal('push', `${branch.getRemoteName()} ${node.ref}:${branch.getName()}`, node.repoPath);
}
terminalRebaseCommit(node: CommitNode) {
if (!(node instanceof CommitNode)) return;
runGitCommandInTerminal('rebase', `-i ${node.ref}^`, node.repoPath);
}
terminalResetCommit(node: CommitNode) {
if (!(node instanceof CommitNode)) return;
runGitCommandInTerminal('reset', `--soft ${node.ref}`, node.repoPath);
}
terminalRevertCommit(node: CommitNode) {
if (!(node instanceof CommitNode)) return;
runGitCommandInTerminal('revert', `-e ${node.ref}`, node.repoPath);
}
terminalRemoveRemote(node: RemoteNode) {
if (!(node instanceof RemoteNode)) return;

Loading…
Cancel
Save