Skip to content

Wrong chrono method in IndexEntry → git2::IndexEntry truncates ctime/mtime #200

@xxxxxxjun

Description

@xxxxxxjun

I think there's a bug at src/index.rs:61-62:

ctime: git2::IndexTime::new(value.ctime.second() as i32, value.ctime.nanosecond()),
mtime: git2::IndexTime::new(value.mtime.second() as i32, value.mtime.nanosecond()),

chrono::Timelike::second() returns the seconds-of-minute (0–59), but git2::IndexTime::new takes a Unix timestamp here — the forward direction on lines 35–37 reads it back via git2::IndexTime::seconds() (plural). So a round-tripped ctime/mtime ends up in the first minute of 1970-01-01 UTC.

No public API currently triggers this path, so nothing breaks today. It would only matter once something wraps git2::Index::add(&IndexEntry) or similar.

Happy to send a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions