Skip to content

feat: add --sort flag to list, prune, and sync commands#317

Merged
avihut merged 7 commits intomasterfrom
feat/list-sort
Mar 20, 2026
Merged

feat: add --sort flag to list, prune, and sync commands#317
avihut merged 7 commits intomasterfrom
feat/list-sort

Conversation

@avihut
Copy link
Owner

@avihut avihut commented Mar 20, 2026

Summary

  • Add --sort flag to list, prune, and sync commands with multi-column sort hierarchy (+col ascending, -col descending)
  • All 10 display columns are sortable: branch, path, size, base, changes, remote, age, owner, activity, commit
  • activity sort considers both last commit timestamp and uncommitted file modification times; commit/last-commit uses commit time only
  • Sort direction indicators (↑/↓) in column headers with brightness gradient showing sort priority rank
  • "Sorted by" summary line appears above the table when headers alone can't convey the sort (hidden columns or 4+ sort keys)
  • Base/changes/remote sort values respect --stat mode (commit/file counts vs line-level)
  • Configurable defaults via daft.list.sort, daft.sync.sort, daft.prune.sort
  • Renamed "Last Commit" column header to "Commit" for consistency with --sort commit

Test plan

  • mise run clippy — zero warnings
  • mise run test:unit — 700+ tests pass (37 new sort tests)
  • mise run test:manual -- --ci list:basic — integration tests pass
  • mise run man:verify — man pages up to date
  • mise run docs:cli:verify — CLI docs up to date
  • Manual testing: daft list --sort -activity, daft list --sort +owner,-size, daft list --sort -changes

Fixes #316

🤖 Generated with Claude Code

avihut and others added 7 commits March 20, 2026 00:52
Add the ability to sort worktree lists by column with configurable
direction. The --sort flag uses +col for ascending and -col for
descending (plain col defaults to ascending). Multiple columns can
be comma-separated for multi-level sort hierarchy.

Sortable columns: branch, path, size, age, owner, activity (aliases:
commit, last-commit). Sorting by columns not displayed is supported
(e.g., --sort -size without --columns +size). Default sort is +branch.

Sort direction indicators appear in column headers when sorting is
active. For time-based columns (age, activity), ascending means
"most recent first" to match terminal visual flow of displayed values.

Defaults can be configured via git config: daft.list.sort,
daft.sync.sort, daft.prune.sort. The CLI flag overrides config.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The activity sort column now considers both committed and uncommitted
work by comparing max(last_commit_timestamp, working_tree_mtime).
This means a worktree with recent file edits but an old commit sorts
as more active than one with a newer commit but no uncommitted changes.

The activity and commit sort columns are now distinct:
- activity: overall activity (commits + uncommitted file mtime)
- commit / last-commit: last commit timestamp only (pure git)

Working tree mtime is computed by stat-ing files from git status
--porcelain (already run for staged/unstaged counts), so the cost
is marginal. Clean worktrees skip the walk entirely.

The activity sort no longer shows a direction indicator on the
Last Commit column header since it's a composite signal not tied
to a single display column.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sort arrows in column headers now use descending brightness based on
their position in the sort key hierarchy. Primary sort column gets a
bright white arrow, secondary gets light gray, tertiary+ gets medium
gray. This visually communicates sort priority at a glance.

Applies to both the list command (ANSI 256-color grayscale) and the
TUI (ratatui Color::White / Gray / DarkGray).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Shorter header label that aligns with the --sort commit flag name.
The --columns CLI name (last-commit) and JSON field names are unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All display columns are now sortable. Base, changes, and remote sort
by their total magnitude:
- base: ahead + behind (commits in summary, lines in --stat lines)
- changes: staged + unstaged + untracked (files or lines)
- remote: remote_ahead + remote_behind (commits or lines)

The sort values respect the --stat mode: summary uses commit/file
counts, --stat lines uses line-level insertions + deletions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Display a "Sorted by X ↓, Y ↑" line above the table when the column
headers alone cannot convey the full sort specification. This appears
when:
- Any sort column is not displayed (e.g., --sort activity without a
  matching column, or --sort size without --columns +size)
- 4+ sort keys are used (the brightness gradient only has 3 levels)

The summary uses the same brightness gradient as column header arrows.
Applies to both the list command and the TUI (sync/prune).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avihut avihut added this to the Public Launch milestone Mar 20, 2026
@avihut avihut added the feat New feature label Mar 20, 2026
@avihut avihut self-assigned this Mar 20, 2026
@avihut avihut merged commit 573840a into master Mar 20, 2026
8 checks passed
@avihut avihut deleted the feat/list-sort branch March 20, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant