From 5cdb08d0d21397c04863a4a199eca253ec6f1623 Mon Sep 17 00:00:00 2001 From: Dor Chaouat <74494312+dorchaouat@users.noreply.github.com> Date: Sun, 6 Aug 2023 10:55:19 +0300 Subject: [PATCH 1/3] Initial branch name on repo creation (Resolves #102) --- src/git.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/git.ts b/src/git.ts index cb23ca4..acd6c2c 100644 --- a/src/git.ts +++ b/src/git.ts @@ -38,12 +38,12 @@ export interface GitAuthenticateOptions { type: string; repo: string; user: (() => Promise<[string | undefined, string | undefined]>) & - (( - callback: ( - username?: string | undefined, - password?: string | undefined - ) => void - ) => void); + (( + callback: ( + username?: string | undefined, + password?: string | undefined + ) => void + ) => void); headers: http.IncomingHttpHeaders; } @@ -149,9 +149,9 @@ export class Git extends EventEmitter implements GitEvents { authenticate: | (( - options: GitAuthenticateOptions, - callback: (error?: Error) => void | undefined - ) => void | Promise | undefined) + options: GitAuthenticateOptions, + callback: (error?: Error) => void | undefined + ) => void | Promise | undefined) | undefined; autoCreate: boolean; @@ -251,19 +251,20 @@ export class Git extends EventEmitter implements GitEvents { * Create a new bare repository `repoName` in the instance repository directory. * @param repo - the name of the repo * @param callback - Optionally get a callback `cb(err)` to be notified when the repository was created. + * @param initialBranch - optional name for the initial branch of the repo (instead of using the user's git config) */ - create(repo: string, callback: (error?: Error) => void) { + create(repo: string, callback: (error?: Error) => void, initialBranch?: string) { function next(self: Git) { let ps; let _error = ''; const dir = self.dirMap(repo); + const gitArgs: string[] = ['init']; - if (self.checkout) { - ps = spawn('git', ['init', dir]); - } else { - ps = spawn('git', ['init', '--bare', dir]); - } + initialBranch && gitArgs.push('-b', initialBranch); + !self.checkout && gitArgs.push('--bare'); + + ps = spawn('git', [...gitArgs, dir]); ps.stderr.on('data', function (chunk: string) { _error += chunk; @@ -371,8 +372,8 @@ export class Git extends EventEmitter implements GitEvents { callback ? basicAuth(req, res, callback) : new Promise<[string | undefined, string | undefined]>( - (resolve) => basicAuth(req, res, (u, p) => resolve([u, p])) - ); + (resolve) => basicAuth(req, res, (u, p) => resolve([u, p])) + ); const promise = this.authenticate( { From aa174d8f78af680235e54851fd53fc01ca03cd12 Mon Sep 17 00:00:00 2001 From: Dor Chaouat <74494312+dorchaouat@users.noreply.github.com> Date: Sun, 6 Aug 2023 10:58:37 +0300 Subject: [PATCH 2/3] Remove lint changes --- src/git.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/git.ts b/src/git.ts index acd6c2c..ec426ad 100644 --- a/src/git.ts +++ b/src/git.ts @@ -38,12 +38,12 @@ export interface GitAuthenticateOptions { type: string; repo: string; user: (() => Promise<[string | undefined, string | undefined]>) & - (( - callback: ( - username?: string | undefined, - password?: string | undefined - ) => void - ) => void); + (( + callback: ( + username?: string | undefined, + password?: string | undefined + ) => void + ) => void); headers: http.IncomingHttpHeaders; } @@ -149,9 +149,9 @@ export class Git extends EventEmitter implements GitEvents { authenticate: | (( - options: GitAuthenticateOptions, - callback: (error?: Error) => void | undefined - ) => void | Promise | undefined) + options: GitAuthenticateOptions, + callback: (error?: Error) => void | undefined + ) => void | Promise | undefined) | undefined; autoCreate: boolean; @@ -261,6 +261,11 @@ export class Git extends EventEmitter implements GitEvents { const dir = self.dirMap(repo); const gitArgs: string[] = ['init']; + if (self.checkout) { + ps = spawn('git', ['init', dir]); + } else { + ps = spawn('git', ['init', '--bare', dir]); + } initialBranch && gitArgs.push('-b', initialBranch); !self.checkout && gitArgs.push('--bare'); @@ -372,8 +377,8 @@ export class Git extends EventEmitter implements GitEvents { callback ? basicAuth(req, res, callback) : new Promise<[string | undefined, string | undefined]>( - (resolve) => basicAuth(req, res, (u, p) => resolve([u, p])) - ); + (resolve) => basicAuth(req, res, (u, p) => resolve([u, p])) + ); const promise = this.authenticate( { From 6f1fe654807a3ce6c7f7369dd300f6e41a81fff8 Mon Sep 17 00:00:00 2001 From: Dor Chaouat <74494312+dorchaouat@users.noreply.github.com> Date: Sun, 6 Aug 2023 10:59:47 +0300 Subject: [PATCH 3/3] Remove old implementation --- src/git.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/git.ts b/src/git.ts index ec426ad..a333741 100644 --- a/src/git.ts +++ b/src/git.ts @@ -261,11 +261,6 @@ export class Git extends EventEmitter implements GitEvents { const dir = self.dirMap(repo); const gitArgs: string[] = ['init']; - if (self.checkout) { - ps = spawn('git', ['init', dir]); - } else { - ps = spawn('git', ['init', '--bare', dir]); - } initialBranch && gitArgs.push('-b', initialBranch); !self.checkout && gitArgs.push('--bare');