Skip to content

Commit

Permalink
Adds checkout command to branches and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 14, 2018
1 parent 3f6cf7e commit b28c811
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 45 deletions.
59 changes: 46 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,15 @@
"light": "images/light/icon-push.svg"
}
},
{
"command": "gitlens.views.checkout",
"title": "Checkout",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-checkout.svg",
"light": "images/light/icon-checkout.svg"
}
},
{
"command": "gitlens.views.fetch",
"title": "Fetch Repository",
Expand Down Expand Up @@ -2776,6 +2785,10 @@
"command": "gitlens.pushRepositories",
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.views.checkout",
"when": "false"
},
{
"command": "gitlens.views.fetch",
"when": "false"
Expand Down Expand Up @@ -3541,14 +3554,9 @@
"group": "1_gitlens@1"
},
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(.*?:tracking|:remote)/",
"group": "inline@98"
},
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(.*?:tracking|:remote)/",
"group": "1_gitlens@1"
"command": "gitlens.views.checkout",
"when": "viewItem =~ /gitlens:branch\\b(?!:current)\\b/",
"group": "inline@10"
},
{
"command": "gitlens.views.compareWithRemote",
Expand All @@ -3566,6 +3574,21 @@
"when": "viewItem =~ /gitlens:branch:current\\b/",
"group": "inline@97"
},
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(.*?:tracking|:remote)/",
"group": "inline@98"
},
{
"command": "gitlens.views.checkout",
"when": "viewItem =~ /gitlens:branch\\b(?!:current)\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(.*?:tracking|:remote)/",
"group": "2_gitlens@1"
},
{
"command": "gitlens.views.compareWithRemote",
"when": "viewItem =~ /gitlens:(branch\\b.*?:tracking)/",
Expand Down Expand Up @@ -3613,7 +3636,7 @@
},
{
"command": "gitlens.views.terminalCheckoutBranch",
"when": "viewItem =~ /gitlens:(branch\\b(?!:current))/",
"when": "viewItem =~ /gitlens:branch\\b(?!:current)/",
"group": "8_gitlens@1"
},
{
Expand All @@ -3623,17 +3646,17 @@
},
{
"command": "gitlens.views.terminalMergeBranch",
"when": "viewItem =~ /gitlens:(branch\\b(?!:current))/",
"when": "viewItem =~ /gitlens:branch\\b(?!:current)/",
"group": "8_gitlens@2"
},
{
"command": "gitlens.views.terminalRebaseBranch",
"when": "viewItem =~ /gitlens:(branch\\b(?!:current))/",
"when": "viewItem =~ /gitlens:branch\\b(?!:current)/",
"group": "8_gitlens@3"
},
{
"command": "gitlens.views.terminalSquashBranchIntoCommit",
"when": "viewItem =~ /gitlens:(branch\\b(?!:current))/",
"when": "viewItem =~ /gitlens:branch\\b(?!:current)/",
"group": "8_gitlens@4"
},
{
Expand All @@ -3643,7 +3666,7 @@
},
{
"command": "gitlens.views.terminalDeleteBranch",
"when": "viewItem =~ /gitlens:(branch\\b(?!:current))/",
"when": "viewItem =~ /gitlens:branch\\b(?!:current)/",
"group": "8_gitlens@6"
},
{
Expand Down Expand Up @@ -4040,6 +4063,16 @@
"when": "viewItem == gitlens:stash",
"group": "1_gitlens@2"
},
{
"command": "gitlens.views.checkout",
"when": "viewItem =~ /gitlens:tag\\b/",
"group": "inline@10"
},
{
"command": "gitlens.views.checkout",
"when": "viewItem =~ /gitlens:tag\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.terminalDeleteTag",
"when": "viewItem == gitlens:tag",
Expand Down
11 changes: 8 additions & 3 deletions src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,15 @@ export class Git {
return git<string>({ cwd: repoPath }, 'check-mailmap', author);
}

static checkout(repoPath: string, fileName: string, ref: string) {
const [file, root] = Git.splitPath(fileName, repoPath);
static checkout(repoPath: string, ref: string, fileName?: string) {
const params = ['checkout', ref, '--'];
if (fileName) {
[fileName, repoPath] = Git.splitPath(fileName, repoPath);

params.push(fileName);
}

return git<string>({ cwd: root }, 'checkout', ref, '--', file);
return git<string>({ cwd: repoPath }, ...params);
}

static async config_get(key: string, repoPath?: string) {
Expand Down
7 changes: 2 additions & 5 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,8 @@ export class GitService implements Disposable {
}

@log()
checkoutFile(uri: GitUri, ref?: string) {
ref = ref || uri.sha;
if (ref === undefined || uri.repoPath === undefined) return;

return Git.checkout(uri.repoPath, uri.fsPath, ref);
checkout(repoPath: string, ref: string, fileName?: string) {
return Git.checkout(repoPath, ref, fileName);
}

@gate()
Expand Down
4 changes: 4 additions & 0 deletions src/views/nodes/resultsFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class ResultsFileNode extends ViewNode {
super(GitUri.fromFile(file, repoPath, ref1 ? ref1 : ref2 ? ref2 : undefined), view, parent);
}

get ref() {
return this.ref1 ? this.ref1 : this.ref2 ? this.ref2 : undefined;
}

getChildren(): ViewNode[] {
return [];
}
Expand Down

0 comments on commit b28c811

Please sign in to comment.