Skip to content

fix: correct git stash message argument and format_relative_time calendar dates#30

Open
JiayuuWang wants to merge 1 commit into
Kuberwastaken:mainfrom
JiayuuWang:contribot/fix-git-stash-and-relative-time
Open

fix: correct git stash message argument and format_relative_time calendar dates#30
JiayuuWang wants to merge 1 commit into
Kuberwastaken:mainfrom
JiayuuWang:contribot/fix-git-stash-and-relative-time

Conversation

@JiayuuWang
Copy link
Copy Markdown

Summary

Two bug fixes in cc-core utilities (src-rust/crates/core/src/):

1. git_utils::stash() — incorrect argument splitting

The stash message was formatted as a single string "-m hello world" and passed via args(). Rust's Command::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:

let msg_flag = format!("-m {}", m);
args.push(&msg_flag);          // git sees: ["stash", "push", "-m hello world"]

After:

cmd.arg("-m").arg(m);          // git sees: ["stash", "push", "-m", "hello world"]

2. format_relative_time() — "X days ago" instead of calendar date

The doc-comment promises "Mar 15" for timestamps older than 2 days, but the else branch 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 for days_to_month_day and format_relative_time_old_timestamp_returns_calendar_date
  • Manual: stash with a message containing spaces now works correctly

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant