Use FILESYSTEM sort for repository tree entries
What does this MR do and why?
Contributes to #569650
Problem
Directories in the repository file browser are sorted in an
unconventional order. For example, Foo.A.Test appears before
Foo.A, and Foo appears last. This is because Gitaly's
GetTreeEntries RPC uses TREES_FIRST sort which relies on
git's internal tree sort order (appending / to directory
names), causing longer names to sort before shorter ones.
Solution
Switch from TREES_FIRST to TREES_FIRST_FILESYSTEM sort order when
calling Gitaly's GetTreeEntries RPC. The TREES_FIRST_FILESYSTEM sort
option (added in
gitaly!9089 (merged))
keeps directories first and sorts entries within each group
lexicographically by path using byte-order comparison,
mirroring the behavior of ls. The change is
gated behind the tree_entries_filesystem_sort feature flag
(disabled by default).
References
- Issue: #569650
- Gitaly MR (merged): gitaly!9089 (merged)
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
- Enable the feature flag:
Feature.enable(:tree_entries_filesystem_sort) - Navigate to a repository that has directories with names like
Foo,Foo.A,Foo.A.Test - Verify directories are sorted as
Foo→Foo.A→Foo.A.Test(shorter before longer) - Disable the flag (
Feature.disable(:tree_entries_filesystem_sort)) and verify the old order returns
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

