Merge pull request #68 from tiktok/feat-checkout-detched

Feat checkout detched
This commit is contained in:
Cheng Liu 2024-05-02 11:02:00 -07:00 committed by GitHub
commit 16476655e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -111,7 +111,14 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
} }
if (!operationBranch) { if (!operationBranch) {
if (!currentBranch) {
// If current branch is missing, it means the repository is in a detached HEAD state.
// Let's treat it as a commit SHA for convenience now.
checkoutTargetKind = 'commit';
} else {
// This should not happen
throw new Error(`Failed to get branch ${operationBranch}`); throw new Error(`Failed to get branch ${operationBranch}`);
}
} else { } else {
if (operationBranch !== currentBranch) { if (operationBranch !== currentBranch) {
// 1. First, Sparo needs to see the branch matches any branch name // 1. First, Sparo needs to see the branch matches any branch name

View file

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Fix checkout command in a detached HEAD state",
"type": "none"
}
],
"packageName": "sparo"
}