mirror of
https://github.com/actions/checkout.git
synced 2025-04-19 09:06:45 +00:00
fix default branch for .wiki and when using ssh (#284)
This commit is contained in:
parent
b4483adec3
commit
fb6f360df2
6 changed files with 126 additions and 29 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue