feat: add --sort/-s flag to sort by date - #57
Merged
Conversation
Sort files by git commit timestamp (descending, most recent first). Files without a date (ignored, untracked, .git) are placed at the bottom in alphabetical order. Uses the unix timestamp (%at) from git log for precise sub-day ordering when multiple files share the same date.
Instead of using git's --date=format (which uses the author's local timezone), we now format the display date from the unix timestamp in UTC. This avoids confusing situations where a commit made later could show an earlier date due to timezone differences. Also simplifies the git log format string by removing %ad.
Extract sortFilesByDate and sortFilesByName into named functions for testability. Add tests covering: - Descending date sort with undated files at the bottom - Same-timestamp fallback to alphabetical order - Undated files (ignored, untracked, .git) grouped at bottom - Case-insensitive alphabetical sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
--sort/-sflag that sorts files by their last git commit timestamp, most recent first.Behavior
I, untracked??,.git*, newly addedA) are placed at the bottom, sorted alphabetically among themselves--sort, the existing alphabetical sort is unchangedImplementation
commitTime int64field to theFilestruct%at(author date as unix timestamp) to the git log format string — negligible parsing cost (strconv.ParseInt)Example