Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git - Add "Checkout" action to graph #237734

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1997,24 +1997,24 @@
],
"scm/historyItem/context": [
{
"command": "git.createTag",
"command": "git.checkoutRefDetached",
"when": "scmProvider == git",
"group": "1_create@1"
"group": "1_checkout@2"
},
{
"command": "git.branch",
"command": "git.createTag",
"when": "scmProvider == git",
"group": "1_create@2"
"group": "2_create@1"
},
{
"command": "git.cherryPickRef",
"command": "git.branch",
"when": "scmProvider == git",
"group": "2_modify@1"
"group": "2_create@2"
},
{
"command": "git.checkoutRefDetached",
"command": "git.cherryPickRef",
"when": "scmProvider == git",
"group": "2_modify@2"
"group": "3_modify@1"
},
{
"command": "git.copyCommitId",
Expand All @@ -2027,7 +2027,13 @@
"group": "9_copy@2"
}
],
"scm/historyItemRef/context": [],
"scm/historyItemRef/context": [
{
"command": "git.checkoutRef",
"when": "scmProvider == git",
"group": "1_checkout@1"
}
],
"editor/title": [
{
"command": "git.openFile",
Expand Down
21 changes: 18 additions & 3 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2545,13 +2545,28 @@ export class CommandCenter {
}

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

return this._checkout(repository, { treeish: historyItemRefId });
const config = workspace.getConfiguration('git', Uri.file(repository.root));
const pullBeforeCheckout = config.get<boolean>('pullBeforeCheckout', false) === true;

// Branch, tag
if (historyItemRef.id.startsWith('refs/heads/') || historyItemRef.id.startsWith('refs/tags/')) {
await repository.checkout(historyItemRef.name, { pullBeforeCheckout });
return;
}

// Remote branch
const branches = await repository.findTrackingBranches(historyItemRef.name);
if (branches.length > 0) {
await repository.checkout(branches[0].name!, { pullBeforeCheckout });
} else {
await repository.checkoutTracking(historyItemRef.name);
}
}

@command('git.checkoutRefDetached', { repository: true })
Expand Down
Loading