Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src/git-command-manager.ts
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2020-06-18 10:20:33 -0400
committerGitHub <noreply@github.com>2020-06-18 10:20:33 -0400
commitb8cb77a290d6bf1500962ef3fdb92249d45b0ac6 (patch)
tree456f207b7d487d1414c5d954dac17ce0d33789ca /src/git-command-manager.ts
parent33f740f1eb34a02546c9a2eb2d6a725d7c67ca92 (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.ts29
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
}