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:
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
}