From f5f80313d477eafa3111b6b46b36d0a16336346b Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 30 Apr 2024 10:32:52 -0700 Subject: [PATCH] fix: checkoout in a detached state --- apps/sparo-lib/src/cli/commands/checkout.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/sparo-lib/src/cli/commands/checkout.ts b/apps/sparo-lib/src/cli/commands/checkout.ts index ad3535b..85e8492 100644 --- a/apps/sparo-lib/src/cli/commands/checkout.ts +++ b/apps/sparo-lib/src/cli/commands/checkout.ts @@ -111,7 +111,14 @@ export class CheckoutCommand implements ICommand { } if (!operationBranch) { - throw new Error(`Failed to get branch ${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}`); + } } else { if (operationBranch !== currentBranch) { // 1. First, Sparo needs to see the branch matches any branch name