Skip to content

Commit 430ede3

Browse files
committed
Git - Add "Checkout" action to graph
1 parent a2ea514 commit 430ede3

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

extensions/git/package.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,24 +1997,24 @@
19971997
],
19981998
"scm/historyItem/context": [
19991999
{
2000-
"command": "git.createTag",
2000+
"command": "git.checkoutRefDetached",
20012001
"when": "scmProvider == git",
2002-
"group": "1_create@1"
2002+
"group": "1_checkout@2"
20032003
},
20042004
{
2005-
"command": "git.branch",
2005+
"command": "git.createTag",
20062006
"when": "scmProvider == git",
2007-
"group": "1_create@2"
2007+
"group": "2_create@1"
20082008
},
20092009
{
2010-
"command": "git.cherryPickRef",
2010+
"command": "git.branch",
20112011
"when": "scmProvider == git",
2012-
"group": "2_modify@1"
2012+
"group": "2_create@2"
20132013
},
20142014
{
2015-
"command": "git.checkoutRefDetached",
2015+
"command": "git.cherryPickRef",
20162016
"when": "scmProvider == git",
2017-
"group": "2_modify@2"
2017+
"group": "3_modify@1"
20182018
},
20192019
{
20202020
"command": "git.copyCommitId",
@@ -2027,7 +2027,13 @@
20272027
"group": "9_copy@2"
20282028
}
20292029
],
2030-
"scm/historyItemRef/context": [],
2030+
"scm/historyItemRef/context": [
2031+
{
2032+
"command": "git.checkoutRef",
2033+
"when": "scmProvider == git",
2034+
"group": "1_checkout@1"
2035+
}
2036+
],
20312037
"editor/title": [
20322038
{
20332039
"command": "git.openFile",

extensions/git/src/commands.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,13 +2545,28 @@ export class CommandCenter {
25452545
}
25462546

25472547
@command('git.checkoutRef', { repository: true })
2548-
async checkoutRef(repository: Repository, historyItem?: SourceControlHistoryItem, historyItemRefId?: string): Promise<boolean> {
2548+
async checkoutRef(repository: Repository, historyItem?: SourceControlHistoryItem, historyItemRefId?: string): Promise<void> {
25492549
const historyItemRef = historyItem?.references?.find(r => r.id === historyItemRefId);
25502550
if (!historyItemRef) {
2551-
return false;
2551+
return;
25522552
}
25532553

2554-
return this._checkout(repository, { treeish: historyItemRefId });
2554+
const config = workspace.getConfiguration('git', Uri.file(repository.root));
2555+
const pullBeforeCheckout = config.get<boolean>('pullBeforeCheckout', false) === true;
2556+
2557+
// Branch, tag
2558+
if (historyItemRef.id.startsWith('refs/heads/') || historyItemRef.id.startsWith('refs/tags/')) {
2559+
await repository.checkout(historyItemRef.name, { pullBeforeCheckout });
2560+
return;
2561+
}
2562+
2563+
// Remote branch
2564+
const branches = await repository.findTrackingBranches(historyItemRef.name);
2565+
if (branches.length > 0) {
2566+
await repository.checkout(branches[0].name!, { pullBeforeCheckout });
2567+
} else {
2568+
await repository.checkoutTracking(historyItemRef.name);
2569+
}
25552570
}
25562571

25572572
@command('git.checkoutRefDetached', { repository: true })

0 commit comments

Comments
 (0)