fix(git): supports grafted pull refs

Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
This commit is contained in:
Emilien Escalle
2023-12-15 15:05:15 +01:00
parent f8ca396f63
commit e3bdf20325
2 changed files with 31 additions and 1 deletions

View File

@@ -137,12 +137,18 @@ export class Git {
return `refs/tags/${ref.split(':')[1].trim()}`;
}
// Otherwise, it's a branch "<origin>/<branch-name>, <branch-name>"
// Branch refs are formatted as "<origin>/<branch-name>, <branch-name>"
const branchMatch = ref.match(/^[^/]+\/[^/]+, (.+)$/);
if (branchMatch) {
return `refs/heads/${branchMatch[1].trim()}`;
}
// Pull request merge refs are formatted as "pull/<number>/<state>"
const prMatch = ref.match(/^pull\/\d+\/(head|merge)$/);
if (prMatch) {
return `refs/${ref}`;
}
throw new Error(`Unsupported detached HEAD ref in "${res}"`);
}