From 7cf4f9535fe3216e1c5a72b76c03076e33830fe1 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Fri, 1 Mar 2024 20:32:51 -0800 Subject: [PATCH 1/3] fix: set profile logic in sparo checkout --- apps/sparo-lib/src/cli/commands/checkout.ts | 37 +++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/apps/sparo-lib/src/cli/commands/checkout.ts b/apps/sparo-lib/src/cli/commands/checkout.ts index f84ac07..78ee3e2 100644 --- a/apps/sparo-lib/src/cli/commands/checkout.ts +++ b/apps/sparo-lib/src/cli/commands/checkout.ts @@ -108,6 +108,7 @@ export class CheckoutCommand implements ICommand { } const targetProfileNames: Set = new Set(); + const currentProfileNames: Set = new Set(); if (!isNoProfile) { // Get target profile. // 1. If profile specified from CLI parameter, preferential use it. @@ -118,7 +119,10 @@ export class CheckoutCommand implements ICommand { if (profiles.size) { profiles.forEach((p) => targetProfileNames.add(p)); } else if (localStateProfiles) { - Object.keys(localStateProfiles).forEach((p) => targetProfileNames.add(p)); + Object.keys(localStateProfiles).forEach((p) => { + targetProfileNames.add(p); + currentProfileNames.add(p); + }); } if (addProfiles.size) { @@ -180,28 +184,27 @@ export class CheckoutCommand implements ICommand { // if no profile specified, purge to skeleton await this._gitSparseCheckoutService.purgeAsync(); } else if (targetProfileNames.size) { + let isCurrentSubsetOfTarget: boolean = true; + for (const currentProfileName of currentProfileNames) { + if (!targetProfileNames.has(currentProfileName)) { + isCurrentSubsetOfTarget = false; + break; + } + } + + // In most case, sparo need to reset the sparse checkout cone. + // Only when the current profiles are subset of target profiles, we can skip this step. + if (!isCurrentSubsetOfTarget) { + await this._gitSparseCheckoutService.purgeAsync(); + } + // TODO: policy #1: Can not sparse checkout with uncommitted changes in the cone. - for (const profile of profiles) { + for (const profile of targetProfileNames) { // Since we have run localState.reset() before, for each profile we just add it to local state. const { selections, includeFolders, excludeFolders } = await this._gitSparseCheckoutService.resolveSparoProfileAsync(profile, { localStateUpdateAction: 'add' }); - // for profiles, we use sparse checkout set - await this._gitSparseCheckoutService.checkoutAsync({ - selections, - includeFolders, - excludeFolders, - checkoutAction: 'set' - }); - } - for (const profile of addProfiles) { - // For each add profile we add it to local state. - const { selections, includeFolders, excludeFolders } = - await this._gitSparseCheckoutService.resolveSparoProfileAsync(profile, { - localStateUpdateAction: 'add' - }); - // for add profiles, we use sparse checkout add await this._gitSparseCheckoutService.checkoutAsync({ selections, includeFolders, From 5c3bc1925b591aea1a1e7ac82dd0b72d7d3e92b7 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Fri, 1 Mar 2024 20:33:06 -0800 Subject: [PATCH 2/3] chore: rush change --- .../changes/sparo/fix-checkout_2024-03-02-04-33.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/sparo/fix-checkout_2024-03-02-04-33.json diff --git a/common/changes/sparo/fix-checkout_2024-03-02-04-33.json b/common/changes/sparo/fix-checkout_2024-03-02-04-33.json new file mode 100644 index 0000000..6b6ce60 --- /dev/null +++ b/common/changes/sparo/fix-checkout_2024-03-02-04-33.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "sparo", + "comment": "", + "type": "none" + } + ], + "packageName": "sparo" +} \ No newline at end of file From 6055599df22abf36e0525d67bffab25a5f52ba26 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Fri, 1 Mar 2024 22:27:37 -0800 Subject: [PATCH 3/3] chore: update change --- common/changes/sparo/fix-checkout_2024-03-02-04-33.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/changes/sparo/fix-checkout_2024-03-02-04-33.json b/common/changes/sparo/fix-checkout_2024-03-02-04-33.json index 6b6ce60..17d85a3 100644 --- a/common/changes/sparo/fix-checkout_2024-03-02-04-33.json +++ b/common/changes/sparo/fix-checkout_2024-03-02-04-33.json @@ -2,8 +2,8 @@ "changes": [ { "packageName": "sparo", - "comment": "", - "type": "none" + "comment": "Fix a regression in sparo checkout", + "type": "patch" } ], "packageName": "sparo"