Skip to content

fix(desktop): honor selected local project branch - #5974

Open
wlg949 wants to merge 2 commits into
block:mainfrom
wlg949:fix/local-branch-selection
Open

fix(desktop): honor selected local project branch#5974
wlg949 wants to merge 2 commits into
block:mainfrom
wlg949:fix/local-branch-selection

Conversation

@wlg949

@wlg949 wlg949 commented Aug 15, 2026

Copy link
Copy Markdown

Summary

  • make the Projects Local source honor the branch selected in the UI
  • preserve working-tree and untracked-file visibility when the selected branch is the checked-out branch
  • read another selected branch directly from its local or origin/* ref without checking it out or mutating the working directory
  • return an explicit error when a selected branch is unavailable locally instead of silently rendering HEAD
  • reject an invalid nonblank selected branch instead of treating it as no selection
  • add regression coverage for the exact mismatch: a feature/PR branch checked out while main is selected

Root cause

The frontend already passed the selected branch into get_project_local_repo_snapshot, but snapshot_from_worktree used unqualified HEAD, git log, and git ls-files. The selector therefore changed query state without changing the commit or files rendered by Local.

Implementation

For the active branch, the existing worktree snapshot remains unchanged so local edits and untracked files stay visible. For any other selected branch, the backend resolves refs/heads/<branch> first and refs/remotes/origin/<branch> second, then reads commits, contributors, tree entries, and UTF-8 previews directly from that ref. Blob previews use a single git cat-file --batch process rather than one subprocess per file.

The selected-ref path only runs read-only Git commands (rev-parse, log, ls-tree, and cat-file); it never checks out a branch or mutates the working tree, index, or HEAD.

Validation

Validated implementation commit: 31f6ce27ea84d2884bc9b627ce3e4cedd7c82c39.

  • formatting and git diff --check passed
  • Linux: Clippy, compile, compiled-flag verification, and the full Tauri workspace suite passed — 2,443 tests, 0 failures, including all three new regressions (run)
  • Windows/MSVC: the desktop package compiled and its tests passed at the same exact commit (job)
  • the Windows job's final repository-wide Clippy step reports pre-existing Windows-only warnings in unrelated files; neither changed project_git file appears in the diagnostics, and Linux Clippy passed
  • independent review verified the selected-ref semantics, batch parser, process lifecycle, no-mutation property, missing-ref behavior, and invalid-selection regression

Buzz origin

buzz://message?channel=953cc31b-96dd-4b1a-9658-8872dfec35e5&id=342192eb4bffd9cfebb996e71d4341ec0a5cf4fd6b939f42c75d985ca20446c1

wlg949 added 2 commits August 15, 2026 10:36
Co-authored-by: wlg949 <xt349100921@protonmail.com>
Signed-off-by: wlg949 <xt349100921@protonmail.com>
Co-authored-by: wlg949 <xt349100921@protonmail.com>
Signed-off-by: wlg949 <xt349100921@protonmail.com>
@wlg949
wlg949 marked this pull request as ready for review August 15, 2026 18:26
@wlg949
wlg949 requested a review from a team as a code owner August 15, 2026 18:26

@themiguelamador themiguelamador left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one selected-ref correctness issue: the new reader used line-delimited git ls-tree output. Git C-quotes valid filenames containing tabs/newlines (and, depending on configuration, non-ASCII bytes), so Local could display the quoted spelling, fail to associate last-commit metadata, and omit the preview because that spelling is not the real tree path. The active-worktree path already avoids this class with NUL delimiters.

I fixed it in Complear/buzz commit 222892e30 (review/pr-5974-fix) by parsing git ls-tree -z as bytes, disabling unnecessary Unicode path quoting in the history query, and resolving the exceptional quoted history paths exactly. The regression now also removes the local branch and proves the origin/* fallback preserves a tab-containing path, its preview, and latest commit metadata.

Verification: full Tauri workspace suite (2,443 passed, 15 expected OS-keychain ignores), focused project Git tests, strict Tauri-library Clippy, Rust formatting, and git diff --check.

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.

2 participants