Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically set up recommended git configuration even when full clone #79

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions apps/sparo-lib/src/cli/commands/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,54 +77,57 @@ export class CloneCommand implements ICommand<ICloneCommandOptions> {
directory: directory
};

const { full, skipGitConfig } = args;

terminal.writeLine('Initializing working directory...');
const stopwatch: Stopwatch = Stopwatch.start();

if (args.full) {
if (full) {
this._gitCloneService.fullClone(cloneOptions);
return;
} else {
this._gitCloneService.bloblessClone(cloneOptions);
}

this._gitCloneService.bloblessClone(cloneOptions);

process.chdir(directory);

const { profiles, isNoProfile } = await this._sparoProfileService.preprocessProfileArgs({
profilesFromArg: args.profile ?? [],
addProfilesFromArg: []
});

await this._GitSparseCheckoutService.ensureSkeletonExistAndUpdated();
if (!full) {
this._GitSparseCheckoutService.ensureSkeletonExistAndUpdated();

// check whether profile exist in local branch
if (!isNoProfile) {
const targetProfileNames: Set<string> = new Set(profiles);
const nonExistProfileNames: string[] = [];
for (const targetProfileName of targetProfileNames) {
if (!this._sparoProfileService.hasProfileInFS(targetProfileName)) {
nonExistProfileNames.push(targetProfileName);
}
}

// check whether profile exist in local branch
if (!isNoProfile) {
const targetProfileNames: Set<string> = new Set(profiles);
const nonExistProfileNames: string[] = [];
for (const targetProfileName of targetProfileNames) {
if (!this._sparoProfileService.hasProfileInFS(targetProfileName)) {
nonExistProfileNames.push(targetProfileName);
if (nonExistProfileNames.length) {
throw new Error(
`Clone failed. The following profile(s) are missing in cloned repo: ${Array.from(
targetProfileNames
).join(', ')}`
);
}
}

if (nonExistProfileNames.length) {
throw new Error(
`Clone failed. The following profile(s) are missing in cloned repo: ${Array.from(
targetProfileNames
).join(', ')}`
);
// Avoid redundant sync if no profile is given
if (!isNoProfile && profiles.size) {
// sync local sparse checkout state with given profiles.
await this._sparoProfileService.syncProfileState({
profiles: isNoProfile ? undefined : profiles
});
}
}

// Avoid redundant sync if no profile is given
if (!isNoProfile && profiles.size) {
// sync local sparse checkout state with given profiles.
await this._sparoProfileService.syncProfileState({
profiles: isNoProfile ? undefined : profiles
});
}

// set recommended git config
if (!args.skipGitConfig) {
if (!skipGitConfig) {
terminal.writeLine(`Applying recommended configuration...`);
this._gitService.setRecommendConfig({ overwrite: true });
}
Expand All @@ -139,7 +142,7 @@ export class CloneCommand implements ICommand<ICloneCommandOptions> {
terminal.writeLine(' ' + Colorize.cyan(`cd ${directory}`));
terminal.writeLine();

if (isNoProfile || profiles.size === 0) {
if (!full && (isNoProfile || profiles.size === 0)) {
terminal.writeLine('Your next step is to choose a Sparo profile for checkout.');
terminal.writeLine('To see available profiles in this repo:');
terminal.writeLine(' ' + Colorize.cyan('sparo list-profiles'));
Expand Down
10 changes: 10 additions & 0 deletions common/changes/sparo/feat-clone-full_2024-07-11-21-24.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Automatically set up recommended git configuration even when performing a full clone",
"type": "none"
}
],
"packageName": "sparo"
}
Loading