diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bdad9ba..6204ef8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Changed +* 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)) * use [tombi](https://github.com/tombi-toml/tombi) for all toml file formatting * open the external editor from the status diff view [[@WaterWhisperer](https://github.com/WaterWhisperer)] ([#2805](https://github.com/gitui-org/gitui/issues/2805)) diff --git a/asyncgit/src/sync/branch/mod.rs b/asyncgit/src/sync/branch/mod.rs index 967b9d65..edf34cd2 100644 --- a/asyncgit/src/sync/branch/mod.rs +++ b/asyncgit/src/sync/branch/mod.rs @@ -250,10 +250,12 @@ impl BranchSort { } fn parse(raw: &str) -> Self { - let trimmed = raw.trim(); - let (descending, key) = trimmed + // git accepts comma-separated lists (e.g. `-committerdate,refname`); + // honour only the primary (first) key. + let primary = raw.split(',').next().unwrap_or("").trim(); + let (descending, key) = primary .strip_prefix('-') - .map_or((false, trimmed), |rest| (true, rest)); + .map_or((false, primary), |rest| (true, rest)); match key { "committerdate" => Self { field: BranchSortField::CommitterDate, @@ -874,6 +876,26 @@ mod tests_branch_sort { ); } + #[test] + fn parse_comma_separated_uses_primary_key() { + // git allows multi-key sort like `-committerdate,refname`; we use + // only the first key and ignore the rest. + assert_eq!( + BranchSort::parse("-committerdate,refname"), + BranchSort { + field: BranchSortField::CommitterDate, + descending: true, + } + ); + assert_eq!( + BranchSort::parse("authordate,-refname"), + BranchSort { + field: BranchSortField::AuthorDate, + descending: false, + } + ); + } + #[test] fn applies_committerdate_descending_from_config() { let (_td, repo) = repo_init().unwrap();