Skip to content

asyncgit: honour branch.sort config when listing branches#2918

Open
Scolliq wants to merge 1 commit intogitui-org:masterfrom
Scolliq:feat/branch-sort-config
Open

asyncgit: honour branch.sort config when listing branches#2918
Scolliq wants to merge 1 commit intogitui-org:masterfrom
Scolliq:feat/branch-sort-config

Conversation

@Scolliq
Copy link
Copy Markdown

@Scolliq Scolliq commented Apr 25, 2026

Closes #2024.

Why: get_branches_info hardcodes a lex-asc sort on the branch name, so users with branch.sort = -committerdate (or authordate, or -refname) in their git config see GitUI's branch list ignore that preference.

What changed: read branch.sort from the repo config and apply it. Supports refname, committerdate, authordate, each with the optional - prefix for descending. Anything else (including version:refname, which I left out for scope) falls back to the existing refname-ascending behaviour. Public API unchanged.

Tests: 6 parser unit tests covering recognised values, the descending prefix, whitespace, and unknown-falls-back. 2 integration tests with write_commit_file_at to pin the actual sort behaviour for -committerdate and the unset-config baseline.

cargo test -p asyncgit --lib sync::branch → 36 pass. cargo clippy -p asyncgit --all-features clean. cargo fmt --check clean.

Future scope: version:refname would need a semver-aware comparator — happy to follow up if there's interest.

Currently get_branches_info hardcodes a lexicographic sort on the
branch name. Read the branch.sort git config (refname, committerdate,
authordate, with optional `-` prefix for descending) so users get the
order their git config already requests.

Falls back to the existing refname-ascending behaviour when the config
is unset or carries an unsupported value (e.g. version:refname).

Closes gitui-org#2024
@extrawurst
Copy link
Copy Markdown
Collaborator

extrawurst commented Apr 27, 2026

Screenshot 2026-04-27 at 08 58 29

Thanks for taking care of this. The only problem i see is that we make the remote branch list very hard to read if there are different remotes. I know this is exactly as git branch --remote lists them but there must be a better way.

I can see a better solution to do a hirarchical tree view first and only sort by this factor inside the same "folder". Is that something you could see yourself doing as a followup?

Right now this is likely still better than the status quo. Please add a changelog entry and rebase to current upstream master.

Also it would be great to update #2146 on top of this where we store the GUI selected sorting into the local git config and use that as the source of truth.

@extrawurst
Copy link
Copy Markdown
Collaborator

Git accepts a comma-separated list (e.g. -committerdate,refname). BranchSort::parse treats the whole string as one key, so -committerdate,refname falls through to the default. Either support it or document the subset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request for support branch.sort

2 participants