fix(core): drop bare remote names from branch lists and search remote branches (#58597)

This commit is contained in:
Kit Langton
2026-10-25 22:39:51 -07:00
committed by GitHub
Unverified
parent 9007700546
commit f7a9f1bf06
2 changed files with 33 additions and 7 deletions
+10 -7
View File
@@ -263,19 +263,22 @@ function makeGit(proc: AppProcess.Interface, env?: Record<string, string>) {
})
const branches = Effect.fn("VcsGit.branches")(function* (cwd: string, options?: BranchOptions) {
const search = options?.search?.trim().replace(/[*?[\]\\]/g, "\\$&")
const search = options?.search?.trim().toLowerCase()
// `refname:short` collapses `refs/remotes/<remote>/HEAD` to the bare remote name, so strip the namespace
// instead. Search and limit apply here because ref globs cannot cross `/` and `--count` precedes the filter.
return (yield* lines(
[
"for-each-ref",
"--ignore-case",
"--sort=refname",
"--sort=-committerdate",
"--format=%(refname:short)",
...(options?.limit ? [`--count=${options.limit}`] : []),
...(search ? [`refs/heads/*${search}*`, `refs/remotes/*${search}*`] : ["refs/heads", "refs/remotes"]),
"--format=%(refname:lstrip=2)",
"refs/heads",
"refs/remotes",
],
{ cwd },
)).filter((item) => !item.endsWith("/HEAD")) satisfies BranchList
))
.filter((item) => !item.endsWith("/HEAD") && (!search || item.toLowerCase().includes(search)))
.slice(0, options?.limit) satisfies BranchList
})
const defaultBranch = Effect.fn("VcsGit.defaultBranch")(function* (cwd: string) {
@@ -292,7 +295,7 @@ function makeGit(proc: AppProcess.Interface, env?: Record<string, string>) {
}
}
const list = yield* lines(["for-each-ref", "--format=%(refname:short)", "refs/heads"], { cwd })
const list = yield* lines(["for-each-ref", "--format=%(refname:lstrip=2)", "refs/heads"], { cwd })
const next = yield* configured(cwd, list)
if (next) return next
if (list.includes("main")) return { name: "main", ref: "main" }
+23
View File
@@ -552,6 +552,29 @@ describe("Vcs", () => {
),
)
it.live("lists remote branches without remote HEAD symrefs", () =>
withGit((directory) =>
Effect.gen(function* () {
yield* Effect.promise(async () => {
await fs.writeFile(path.join(directory, "file.txt"), "one\n")
await commitAll(directory, "initial")
await $`git tag main`.cwd(directory).quiet()
await $`git remote add origin ${directory}`.cwd(directory).quiet()
await $`git remote add fork ${directory}`.cwd(directory).quiet()
await $`git fetch --quiet origin`.cwd(directory).quiet()
await $`git fetch --quiet fork`.cwd(directory).quiet()
await $`git remote set-head origin main`.cwd(directory).quiet()
await $`git remote set-head fork main`.cwd(directory).quiet()
})
const vcs = yield* Vcs.Service
expect(yield* vcs.branches()).toEqual(["main", "fork/main", "origin/main"])
expect(yield* vcs.branches({ limit: 2 })).toEqual(["main", "fork/main"])
expect(yield* vcs.branches({ search: "origin" })).toEqual(["origin/main"])
expect(yield* vcs.branches({ search: "MAIN", limit: 2 })).toEqual(["main", "fork/main"])
}),
),
)
it.live("reports modified, deleted, and untracked files", () =>
withGit((directory) =>
Effect.gen(function* () {