diff --git a/schema.json b/schema.json index a9e582f..361156e 100644 --- a/schema.json +++ b/schema.json @@ -20,6 +20,11 @@ "type": "string", "description": "git source repository" }, + "gitBranch": { + "type": "string", + "description": "git branch to checkout", + "default": "main" + }, "gitDependenciesCachePath": { "type": "string", "description": "Path to git dependencies cache folder " diff --git a/src/commands/engine/update.ts b/src/commands/engine/update.ts index c3d5c53..a6a9e97 100644 --- a/src/commands/engine/update.ts +++ b/src/commands/engine/update.ts @@ -16,7 +16,6 @@ export const update = new Command() .option( '-b, --branch ', 'git checkout (branch | tag | commit)', - { default: 'main' }, ) .option('-r, --remote ', 'git remote', { default: 'origin' }) .option('-c, --clean', 'if we should run a git clean before updating', { @@ -41,6 +40,8 @@ export const update = new Command() } = options as UpdateOptions const cfg = Config.getInstance().mergeConfigCLIConfig({ cliOptions: options }) + const branchArg = branch || cfg.engine.gitBranch + const isRepo = await isGitRepo(cfg.engine.path) if (!isRepo) { throw new ValidationError( @@ -48,7 +49,7 @@ export const update = new Command() ) } if (clean) { - const clean = await exec('git', [ + const _clean = await exec('git', [ 'clean', gitCleanFlags ? gitCleanFlags : '-fxd', ], { cwd: cfg.engine.path, dryRun }) @@ -56,20 +57,20 @@ export const update = new Command() // Prevent the default engine hooks from running await deleteEngineHooks(cfg.engine.path) - const fetch = await exec('git', [ + const _fetch = await exec('git', [ 'fetch', remote, - branch, + branchArg, ], { cwd: cfg.engine.path, dryRun }) - const checkout = await exec('git', [ + const _checkout = await exec('git', [ 'checkout', '--quiet', '--force', - branch, + branchArg, ], { cwd: cfg.engine.path, dryRun }) - const reset = await exec('git', [ + const _reset = await exec('git', [ 'reset', '--hard', 'FETCH_HEAD', diff --git a/src/lib/schema.ts b/src/lib/schema.ts index 366dea1..25389af 100644 --- a/src/lib/schema.ts +++ b/src/lib/schema.ts @@ -30,6 +30,7 @@ export const ConfigSchema = z.object({ path: z.string().describe('Path to the engine folder'), repoType: z.string().describe('git or perforce'), gitSource: z.string().optional().describe('git source repository'), + gitBranch: z.string().optional().describe('git branch to checkout').default('main'), gitDependenciesCachePath: z .string() .optional() diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 3951453..da5a065 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -249,7 +249,7 @@ export const runEngineSetup = async ( const deps = await exec(engine.getGitDependencesBin(), args, { cwd: enginePath, dryRun }) - await exec(engine.getGenerateScript(), []) + await exec(engine.getGenerateScript(), [], { dryRun }) } export const deleteEngineHooks = async (enginePath: string) => {