Skip to content

Commit b81b6be

Browse files
committed
asyncgit: support comma-separated branch.sort keys; add changelog
git accepts multi-key sort values like `-committerdate,refname`. BranchSort::parse now splits on commas and honours the primary (first) key rather than falling back to the default. Add a test for the comma-separated case and a CHANGELOG entry.
1 parent 5586cf1 commit b81b6be

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

1010
### Changed
11+
* honour `branch.sort` git config when listing branches, including support for comma-separated multi-key values ([#2918](https://github.com/gitui-org/gitui/pull/2918))
1112
* use [tombi](https://github.com/tombi-toml/tombi) for all toml file formatting
1213
* open the external editor from the status diff view [[@WaterWhisperer](https://github.com/WaterWhisperer)] ([#2805](https://github.com/gitui-org/gitui/issues/2805))
1314

asyncgit/src/sync/branch/mod.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ impl BranchSort {
250250
}
251251

252252
fn parse(raw: &str) -> Self {
253-
let trimmed = raw.trim();
254-
let (descending, key) = trimmed
253+
// git accepts comma-separated lists (e.g. `-committerdate,refname`);
254+
// honour only the primary (first) key.
255+
let primary = raw.split(',').next().unwrap_or("").trim();
256+
let (descending, key) = primary
255257
.strip_prefix('-')
256-
.map_or((false, trimmed), |rest| (true, rest));
258+
.map_or((false, primary), |rest| (true, rest));
257259
match key {
258260
"committerdate" => Self {
259261
field: BranchSortField::CommitterDate,
@@ -874,6 +876,26 @@ mod tests_branch_sort {
874876
);
875877
}
876878

879+
#[test]
880+
fn parse_comma_separated_uses_primary_key() {
881+
// git allows multi-key sort like `-committerdate,refname`; we use
882+
// only the first key and ignore the rest.
883+
assert_eq!(
884+
BranchSort::parse("-committerdate,refname"),
885+
BranchSort {
886+
field: BranchSortField::CommitterDate,
887+
descending: true,
888+
}
889+
);
890+
assert_eq!(
891+
BranchSort::parse("authordate,-refname"),
892+
BranchSort {
893+
field: BranchSortField::AuthorDate,
894+
descending: false,
895+
}
896+
);
897+
}
898+
877899
#[test]
878900
fn applies_committerdate_descending_from_config() {
879901
let (_td, repo) = repo_init().unwrap();

0 commit comments

Comments
 (0)