mirror of
https://github.com/o2sh/onefetch
synced 2024-06-30 22:54:20 +00:00
add a test for negative dates and see how onefetch handles it (#1100)
* add a test for negative dates and see how onefetch handles it. Currently there is an 'empty' error which probably is related to a failure to parse commits with negative dates. This should be fixed in future versions of `gitoxide`. * feat: support repositories with dates prior to UNIX epoch. Note that such repositories aren't easy to create in the first place and such pre-dated commits need to be created with tool-assistance. In any case, now `onefetch` is able to handle these as well. * update dependencies, also in the hopes to fix CI caches * add unit test --------- Co-authored-by: o2sh <ossama-hjaji@live.fr>
This commit is contained in:
parent
7328a35a99
commit
67cd11a3fe
1354
Cargo.lock
generated
1354
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
|
@ -24,10 +24,10 @@ bytecount = "0.6.3"
|
|||
clap = { version = "4.3.4", features = ["derive"] }
|
||||
clap_complete = "4.3.1"
|
||||
crossbeam-channel = "0.5.8"
|
||||
gix-features-for-configuration-only = { package = "gix-features", version = "0.30.0", features = [
|
||||
gix-features-for-configuration-only = { package = "gix-features", version = "0.31.0", features = [
|
||||
"zlib-ng",
|
||||
] }
|
||||
gix = { version = "0.47.0", default-features = false, features = [
|
||||
gix = { version = "0.48.0", default-features = false, features = [
|
||||
"max-performance-safe",
|
||||
] }
|
||||
git2 = { version = "0.17.2", default-features = false }
|
||||
|
|
|
@ -8,7 +8,7 @@ pub mod info_field;
|
|||
|
||||
pub fn format_time(time: Time, iso_time: bool) -> String {
|
||||
if iso_time {
|
||||
to_rfc3339(HumanTime::from(time.seconds as i64))
|
||||
to_rfc3339(HumanTime::from(time.seconds))
|
||||
} else {
|
||||
to_human_time(time)
|
||||
}
|
||||
|
@ -26,7 +26,10 @@ fn to_human_time(time: Time) -> String {
|
|||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap();
|
||||
|
||||
let ts = Duration::from_secs(time.seconds);
|
||||
let ts = Duration::from_secs(match time.seconds.try_into() {
|
||||
Ok(s) => s,
|
||||
Err(_) => return "<before UNIX epoch>".into(),
|
||||
});
|
||||
let duration = since_epoch_duration.checked_sub(ts).expect(
|
||||
"Achievement unlocked: time travel! \
|
||||
Check your system clock and commit dates.",
|
||||
|
@ -46,7 +49,10 @@ mod tests {
|
|||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap();
|
||||
|
||||
let time = Time::new(current_time.as_secs(), 0);
|
||||
let time = Time::new(
|
||||
current_time.as_secs() as gix::date::SecondsSinceUnixEpoch,
|
||||
0,
|
||||
);
|
||||
let result = format_time(time, false);
|
||||
assert_eq!(result, "now");
|
||||
}
|
||||
|
@ -59,7 +65,7 @@ mod tests {
|
|||
.unwrap();
|
||||
// NOTE 366 so that it's a year ago even with leap years.
|
||||
let year_ago = current_time - (day * 366);
|
||||
let time = Time::new(year_ago.as_secs(), 0);
|
||||
let time = Time::new(year_ago.as_secs() as gix::date::SecondsSinceUnixEpoch, 0);
|
||||
let result = format_time(time, false);
|
||||
assert_eq!(result, "a year ago");
|
||||
}
|
||||
|
@ -91,7 +97,14 @@ mod tests {
|
|||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap();
|
||||
let tomorrow = current_time + day;
|
||||
let time = Time::new(tomorrow.as_secs(), 0);
|
||||
let time = Time::new(tomorrow.as_secs() as gix::date::SecondsSinceUnixEpoch, 0);
|
||||
format_time(time, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_time_before_epoch() {
|
||||
let time = Time::new(gix::date::SecondsSinceUnixEpoch::MIN, 0);
|
||||
let result = to_human_time(time);
|
||||
assert_eq!(result, "<before UNIX epoch>");
|
||||
}
|
||||
}
|
||||
|
|
29
tests/fixtures/make_pre_epoch_repo.sh
vendored
Normal file
29
tests/fixtures/make_pre_epoch_repo.sh
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
set -eu -o pipefail
|
||||
|
||||
git init -q
|
||||
git checkout -b main
|
||||
|
||||
echo "hello\nworld" >> code.rs
|
||||
git add code.rs
|
||||
GIT_AUTHOR_DATE="@0 +0000" GIT_COMMITTER_DATE="@0 +0000" git commit -q -m c1
|
||||
git cat-file -p @ > to-be-patched.txt
|
||||
|
||||
patch -p1 <<EOF
|
||||
diff --git a/to-be-patched.txt b/to-be-patched.txt
|
||||
index 95ad1b1..3ea89af 100644
|
||||
--- a/to-be-patched.txt
|
||||
+++ b/to-be-patched.txt
|
||||
@@ -1,5 +1,5 @@
|
||||
tree 00d3a67028ba1004a04bd720eee966811102f0c3
|
||||
-author author <author@example.com> 0 +0000
|
||||
-committer committer <committer@example.com> 0 +0000
|
||||
+author author <author@example.com> -5263747740 +0009
|
||||
+committer committer <committer@example.com> -5263747740 +0009
|
||||
|
||||
c1
|
||||
EOF
|
||||
|
||||
new_commit=$(git hash-object -w -t commit to-be-patched.txt || git hash-object --literally -w -t commit to-be-patched.txt)
|
||||
git update-ref refs/heads/main $new_commit
|
||||
|
|
@ -83,3 +83,14 @@ fn test_partial_repo() -> Result<()> {
|
|||
let _info = build_info(&config).expect("no error");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repo_with_pre_epoch_dates() -> Result<()> {
|
||||
let repo = repo("make_pre_epoch_repo.sh")?;
|
||||
let config: CliOptions = CliOptions {
|
||||
input: repo.path().to_path_buf(),
|
||||
..Default::default()
|
||||
};
|
||||
let _info = build_info(&config).expect("no error");
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user