Skip to content

fix: honor Settings > Git > Default Branch, stop hardcoding "main" - #148

Merged
devlint merged 3 commits into
mainfrom
fix/136-default-branch-setting
Aug 10, 2026
Merged

fix: honor Settings > Git > Default Branch, stop hardcoding "main"#148
devlint merged 3 commits into
mainfrom
fix/136-default-branch-setting

Conversation

@devlint

@devlint devlint commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • get_main_branch_name() (ops.rs) and a separately-implemented fallback in git_branch_merged (read.rs) both ended in a hardcoded "main" literal when nothing verified, causing git branch --format=...%(ahead-behind:main) / git branch --merged main to fail with fatal: failed to find 'main' on repos whose mainline is e.g. develop/trunk.
  • Settings → Git → Default Branch existed in useSettings.ts/SettingsPanel.vue but was never passed to any backend command — purely cosmetic.
  • New shared resolve_default_branch() in src/git/cmd.rs (used by both ops.rs and read.rs): configured setting → remote origin/HEAD symref → main/master/origin/main/origin/master → current branch (always resolves in a non-empty repo, replacing the old hardcoded literal). Mirrored in dev-server.mjs for pnpm dev:web parity.
  • git_branches, git_branch_merged, git_branch_top_authors now take an optional default_branch param, threaded from settings.defaultBranch through backend.ts to every call site.
  • Along the way: fixed a dev-server-only issue where introducing a user-configured value into what used to be a fixed 4-literal set exposed the pre-existing execSync + shell: true git-branches route to shell injection — switched to spawnSync with a discrete args array (no shell), per AGENTS.md's anti-injection rule.

Test plan

  • New Rust unit tests for resolve_default_branch (5) using a real temp repo whose only branch is trunk
  • New integration tests in ops.rs/read.rs (5) against real temp repos, including the exact fatal: failed to find 'main' regression and a configured-branch-wins case
  • cargo test --lib: 176/176 pass
  • pnpm test:parity: 15/15 pass
  • Frontend suite: 651/651 pass
  • vue-tsc --noEmit: no new errors

Fixes #136

Laurent Guitton added 3 commits August 10, 2026 12:58
…#136)

git_branches, git_branch_merged, and git_branch_top_authors hardcoded a
"main"/"master"/origin/main/origin/master fallback chain that ended in the
literal "main" even when nothing verified, so repos whose mainline was e.g.
"develop"/"trunk" hit a recurring `fatal: failed to find 'main'` notification.
The Default Branch setting was also never wired to any backend command.

Thread the configured default branch through to all three commands (tried
first, before the existing chain), and replace the hardcoded "main" fallback
with the current branch, which always resolves in a non-empty repo. Shared
the fallback logic in a new `resolve_default_branch()` helper (git/cmd.rs)
used by both ops.rs and read.rs, mirrored it in dev-server.mjs, and updated
backend.ts + every Vue call site to pass `settings.defaultBranch` through.

disabled
# Conflicts:
#	CHANGELOG.md
@devlint
devlint merged commit 3dc1764 into main Aug 10, 2026
4 checks passed
@devlint
devlint deleted the fix/136-default-branch-setting branch August 10, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error: failed to find 'main'

1 participant