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

fix: handle no connection to git server #279

Merged
merged 1 commit into from
Jun 10, 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
2 changes: 1 addition & 1 deletion src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class Init extends Command {
}

private async _resolveVersion(packageConfig: PackageConfig, verbose: boolean): Promise<void> {
const packageVersions = await packageConfig.getPackageVersions();
const packageVersions = await packageConfig.getPackageVersions(verbose);
const packageVersion = resolveVersionIdentifier(packageVersions, packageConfig.version);

if (verbose) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/upgrade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class Upgrade extends Command {
flags: any,
): Promise<boolean> {
const initialVersionSpecifier = packageConfig.version;
const availableVersions = await packageConfig.getPackageVersions();
const availableVersions = await packageConfig.getPackageVersions(flags.verbose);
const matchedVersion = flags['ignore-bounds']
? getLatestVersion(availableVersions.all)
: resolveVersionIdentifier(availableVersions, packageConfig.version);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { IPty, spawn } from 'node-pty';
import { exec } from 'node:child_process';
import { join, resolve } from 'node:path';
import { resolve } from 'node:path';
import { ExecSpec, ProgramSpec } from './component';
import { ProjectCache } from './project-cache';
import { ProjectConfig } from './projectConfig/projectConfig';
Expand Down
19 changes: 13 additions & 6 deletions src/modules/package-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ export class PackageDownloader {
await this.git.clone(this.packageConfig.getPackageRepo(), packageDir, cloneOpts);
}

private async _updateRepository(checkRepoAction: CheckRepoActions): Promise<void> {
private async _updateRepository(checkRepoAction: CheckRepoActions, verbose: boolean): Promise<void> {
const localRepoExists = await this.git.checkIsRepo(checkRepoAction);

if (localRepoExists) {
await this.git.fetch(['--force', '--tags', '--prune', '--prune-tags']);
try {
await this.git.fetch(['--force', '--tags', '--prune', '--prune-tags']);
} catch (error) {
if (verbose) {
console.log(`... Could not check the server version for ${this.packageConfig.repo}`);
}
}
}
}

Expand All @@ -59,12 +65,13 @@ export class PackageDownloader {
return await simpleGit(packageDir).checkIsRepo(checkRepoAction);
}

public async downloadPackage(option: { checkVersionOnly: boolean }): Promise<SimpleGit> {
public async downloadPackage(option: { checkVersionOnly?: boolean; verbose?: boolean }): Promise<SimpleGit> {
const { checkVersionOnly = false, verbose = false } = option;
let packageDir: string = this.packageConfig.getPackageDirectory();
let checkRepoAction: CheckRepoActions;
const cloneOpts: string[] = [];

if (option.checkVersionOnly) {
if (checkVersionOnly) {
packageDir = join(packageDir, '_cache');
cloneOpts.push('--bare');
checkRepoAction = CheckRepoActions.BARE;
Expand All @@ -75,9 +82,9 @@ export class PackageDownloader {

await this._checkForValidRepo(packageDir, cloneOpts, checkRepoAction);
this.git = simpleGit(packageDir);
await this._updateRepository(checkRepoAction);
await this._updateRepository(checkRepoAction, verbose);

if (!option.checkVersionOnly) {
if (!checkVersionOnly) {
await this._checkoutVersion(this.packageConfig.version);
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export class PackageConfig {
this.version = version;
}

async getPackageVersions(): Promise<TagResult> {
async getPackageVersions(verbose?: boolean): Promise<TagResult> {
try {
const packageInformation = await packageDownloader(this).downloadPackage({ checkVersionOnly: true });
const packageInformation = await packageDownloader(this).downloadPackage({ checkVersionOnly: true, verbose: verbose });
const packageVersionTags = await packageInformation.tags();
return packageVersionTags;
} catch (error) {
Expand All @@ -108,7 +108,7 @@ export class PackageConfig {

async downloadPackageVersion(verbose?: boolean): Promise<void> {
try {
await packageDownloader(this).downloadPackage({ checkVersionOnly: false });
await packageDownloader(this).downloadPackage({ verbose: verbose });
} catch (error) {
console.error(error);
}
Expand Down