refactor(git): separate init from sync

This commit is contained in:
Rhys Arkins 2020-07-05 08:25:21 +02:00
parent 7d18476d74
commit 9bdd8b53c3

View file

@ -39,6 +39,7 @@ interface LocalConfig extends StorageConfig {
baseBranchSha: string; baseBranchSha: string;
branchExists: Record<string, boolean>; branchExists: Record<string, boolean>;
branchPrefix: string; branchPrefix: string;
syncCompleted: boolean;
} }
// istanbul ignore next // istanbul ignore next
@ -146,10 +147,11 @@ export async function getSubmodules(): Promise<string[]> {
.filter((_e: string, i: number) => i % 2); .filter((_e: string, i: number) => i % 2);
} }
export async function initRepo(args: StorageConfig): Promise<void> { export async function syncGit(): Promise<void> {
config = { ...args } as any; if (config.syncCompleted) {
return;
config.branchExists = {}; }
config.syncCompleted = true;
logger.debug('Initializing git repository into ' + config.localDir); logger.debug('Initializing git repository into ' + config.localDir);
const gitHead = join(config.localDir, '.git/HEAD'); const gitHead = join(config.localDir, '.git/HEAD');
let clone = true; let clone = true;
@ -232,6 +234,12 @@ export async function initRepo(args: StorageConfig): Promise<void> {
config.baseBranch = config.baseBranch || (await getDefaultBranch(git)); config.baseBranch = config.baseBranch || (await getDefaultBranch(git));
} }
export async function initRepo(args: StorageConfig): Promise<void> {
config = { ...args } as any;
config.branchExists = {};
await syncGit();
}
// istanbul ignore next // istanbul ignore next
export async function getRepoStatus(): Promise<StatusResult> { export async function getRepoStatus(): Promise<StatusResult> {
return git.status(); return git.status();