fix: correct git stash message argument and format_relative_time calendar dates#30
Open
JiayuuWang wants to merge 1 commit into
Open
Conversation
…dates
Two bug fixes in cc-core utilities:
1. `git_utils::stash()`: The stash message was incorrectly formatted as
a single token `"-m hello world"` passed to `args()`. When Rust's
`Command` receives a single string via `arg()`, it passes it verbatim
as one OS argument. Git would then treat `"-m hello world"` as an
unknown flag rather than the message text. Fixed by calling
`.arg("-m").arg(m)` so the flag and value are separate tokens, as git
expects.
2. `format_utils::format_relative_time()`: The doc-comment promised
calendar-date output ("Mar 15") for timestamps older than 2 days, but
the implementation fell through to "X days ago". Fixed by computing
month/day from the Unix epoch using Howard Hinnant's civil-calendar
algorithm (no extra dependencies). Tests added for both fixes.
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
Two bug fixes in
cc-coreutilities (src-rust/crates/core/src/):1.
git_utils::stash()— incorrect argument splittingThe stash message was formatted as a single string
"-m hello world"and passed viaargs(). Rust'sCommand::args()passes each element as a separate OS-level argument, so"-m hello world"was handed to git as one token — git would reject it as an unknown flag and the stash would silently fail.Before:
After:
2.
format_relative_time()— "X days ago" instead of calendar dateThe doc-comment promises
"Mar 15"for timestamps older than 2 days, but theelsebranch returned"X days ago"instead. Fixed by computing month/day from the UNIX epoch using Howard Hinnant's civil-calendar algorithm (no new dependencies needed).Tests added for both fixes.
Test plan
cargo test -p cc-core— all existing tests pass; new tests added fordays_to_month_dayandformat_relative_time_old_timestamp_returns_calendar_date