(cwd)
| 91 | } |
| 92 | |
| 93 | export function detectDefaultBranch(cwd) { |
| 94 | const symbolic = git(cwd, ["symbolic-ref", "refs/remotes/origin/HEAD"]); |
| 95 | if (symbolic.status === 0) { |
| 96 | const remoteHead = symbolic.stdout.trim(); |
| 97 | if (remoteHead.startsWith("refs/remotes/origin/")) { |
| 98 | return remoteHead.replace("refs/remotes/origin/", ""); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | const candidates = ["main", "master", "trunk"]; |
| 103 | for (const candidate of candidates) { |
| 104 | const local = git(cwd, ["show-ref", "--verify", "--quiet", `refs/heads/${candidate}`]); |
| 105 | if (local.status === 0) { |
| 106 | return candidate; |
| 107 | } |
| 108 | const remote = git(cwd, ["show-ref", "--verify", "--quiet", `refs/remotes/origin/${candidate}`]); |
| 109 | if (remote.status === 0) { |
| 110 | return `origin/${candidate}`; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | throw new Error("Unable to detect the repository default branch. Pass --base <ref> or use --scope working-tree."); |
| 115 | } |
| 116 | |
| 117 | export function getCurrentBranch(cwd) { |
| 118 | return gitChecked(cwd, ["branch", "--show-current"]).stdout.trim() || "HEAD"; |
no test coverage detected