From f5f80313d477eafa3111b6b46b36d0a16336346b Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 30 Apr 2024 10:32:52 -0700 Subject: [PATCH 1/2] 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 From 6ddf7c2f3d7aef9a571240af98c7c85fc77c8cbd Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 30 Apr 2024 10:33:31 -0700 Subject: [PATCH 2/2] chore: rush change --- .../sparo/feat-checkout-detched_2024-04-30-17-33.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/sparo/feat-checkout-detched_2024-04-30-17-33.json diff --git a/common/changes/sparo/feat-checkout-detched_2024-04-30-17-33.json b/common/changes/sparo/feat-checkout-detched_2024-04-30-17-33.json new file mode 100644 index 0000000..16ad3a3 --- /dev/null +++ b/common/changes/sparo/feat-checkout-detched_2024-04-30-17-33.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "sparo", + "comment": "Fix checkout command in a detached HEAD state", + "type": "none" + } + ], + "packageName": "sparo" +} \ No newline at end of file