diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-06-18 10:20:33 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-18 10:20:33 -0400 |
| commit | b8cb77a290d6bf1500962ef3fdb92249d45b0ac6 (patch) | |
| tree | 456f207b7d487d1414c5d954dac17ce0d33789ca /src/git-command-manager.ts | |
| parent | 33f740f1eb34a02546c9a2eb2d6a725d7c67ca92 (diff) | |
fix default branch for .wiki and when using ssh (#284)
Diffstat (limited to 'src/git-command-manager.ts')
| -rw-r--r-- | src/git-command-manager.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 9d2d45f..8bf3aa1 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -25,6 +25,7 @@ export interface IGitCommandManager { ): Promise<void> configExists(configKey: string, globalConfig?: boolean): Promise<boolean> fetch(refSpec: string[], fetchDepth?: number): Promise<void> + getDefaultBranch(repositoryUrl: string): Promise<string> getWorkingDirectory(): string init(): Promise<void> isDetached(): Promise<boolean> @@ -195,6 +196,34 @@ class GitCommandManager { }) } + async getDefaultBranch(repositoryUrl: string): Promise<string> { + let output: GitOutput | undefined + await retryHelper.execute(async () => { + output = await this.execGit([ + 'ls-remote', + '--quiet', + '--exit-code', + '--symref', + repositoryUrl, + 'HEAD' + ]) + }) + + if (output) { + // Satisfy compiler, will always be set + for (let line of output.stdout.trim().split('\n')) { + line = line.trim() + if (line.startsWith('ref:') || line.endsWith('HEAD')) { + return line + .substr('ref:'.length, line.length - 'ref:'.length - 'HEAD'.length) + .trim() + } + } + } + + throw new Error('Unexpected output when retrieving default branch') + } + getWorkingDirectory(): string { return this.workingDirectory } |
