Git - Add "Checkout" action to graph (#237734)

This commit is contained in:
Ladislau Szomoru
2025-01-12 19:51:10 +01:00
committed by GitHub
parent c9efcc2cd0
commit d6fd2c075b
2 changed files with 33 additions and 12 deletions

View File

@@ -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 })