Fix/local branch worktree base (#2328)
* Add automatic plus branch maintenance workflow * Build plus artifacts for desktop and CLI/server * Document and summarize plus artifact workflow * Document Apple signing and pin plus workflow actions * Disable Linux plus desktop artifact * Publish plus CLI packages to GitHub Packages * Fix GitHub Packages publish paths * Fix plus mise install summary package name * Disable macOS x64 plus desktop artifact * Tag plus npm packages as latest for mise * fix(worktrees): respect selected local base ref * chore(ci): remove fork-only plus workflow * fix(worktrees): preserve exact branch picker refs --------- Co-authored-by: Matt Cowger <1929548+mcowger@users.noreply.github.com>
This commit is contained in:
co-authored by
Matt Cowger
parent
b0a5c09ace
commit
76abc50f82
@@ -1325,7 +1325,7 @@ async function resolveWorktreeSourcePlan({
|
||||
const branchName = source.branchName;
|
||||
validateWorktreeBranchName(branchName);
|
||||
const normalizedBaseBranch = normalizeRequiredBaseBranch(source.baseBranch);
|
||||
const resolvedBaseBranch = await resolveBaseBranchForWorktree(cwd, normalizedBaseBranch);
|
||||
const resolvedBaseBranch = await resolveBaseBranchForWorktree(cwd, source.baseBranch);
|
||||
const branchExists = await localBranchExists(cwd, branchName);
|
||||
const base = branchExists ? branchName : resolvedBaseBranch;
|
||||
const candidateBranch = branchExists ? desiredSlug : branchName;
|
||||
@@ -1615,19 +1615,36 @@ function normalizeRequiredBaseBranch(baseBranch: string): string {
|
||||
|
||||
async function resolveBaseBranchForWorktree(
|
||||
cwd: string,
|
||||
normalizedBaseBranch: string,
|
||||
requestedBaseBranch: string,
|
||||
): Promise<string> {
|
||||
try {
|
||||
await runGitCommand(["rev-parse", "--verify", `origin/${normalizedBaseBranch}`], { cwd });
|
||||
return `origin/${normalizedBaseBranch}`;
|
||||
} catch {
|
||||
const requested = requestedBaseBranch.trim();
|
||||
const normalized = normalizeRequiredBaseBranch(requested);
|
||||
let exactRef: string | null = null;
|
||||
if (requested.startsWith("refs/")) {
|
||||
exactRef = requested;
|
||||
} else if (requested.startsWith("origin/")) {
|
||||
exactRef = `refs/remotes/${requested}`;
|
||||
}
|
||||
|
||||
if (exactRef) {
|
||||
try {
|
||||
await runGitCommand(["rev-parse", "--verify", normalizedBaseBranch], { cwd });
|
||||
return normalizedBaseBranch;
|
||||
await runGitCommand(["rev-parse", "--verify", exactRef], { cwd });
|
||||
return exactRef;
|
||||
} catch {
|
||||
throw new Error(`Base branch not found: ${normalizedBaseBranch}`);
|
||||
throw new Error(`Base branch not found: ${normalized}`);
|
||||
}
|
||||
}
|
||||
|
||||
const candidates = [`refs/heads/${requested}`, `refs/remotes/origin/${requested}`, requested];
|
||||
for (const candidate of candidates) {
|
||||
try {
|
||||
await runGitCommand(["rev-parse", "--verify", candidate], { cwd });
|
||||
return candidate;
|
||||
} catch {
|
||||
// Try the next unambiguous local, remote, or legacy ref candidate.
|
||||
}
|
||||
}
|
||||
throw new Error(`Base branch not found: ${normalized}`);
|
||||
}
|
||||
|
||||
async function localBranchExists(cwd: string, branchName: string): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user