History

add a test to see what happens if negative dates are used in commits

Sebastian Thiel committed 3 years ago

Commit 57a5cd11 parent 5af2cf36 files · +92 −4Browse files

Unified · Split

6 files
  1. gix-actor/tests/signature/mod.rs +1 −0
  2. gix-object/tests/commit/from_bytes.rs +26 −0
  3. gix-object/tests/fixtures/commit/pre-epoch.txt +5 −0
  4. gix/tests/fixtures/generated-archives/make_pre_epoch_repo.tar.xz +3 −0
  5. gix/tests/fixtures/make_pre_epoch_repo.sh +30 −0
  6. gix/tests/id/mod.rs +27 −4
gix-actor/tests/signature/mod.rs+1−0
@@ -67,6 +67,7 @@ fn trim() { · 66 unmodified lines
6767 fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
6868 static DEFAULTS: &[&[u8]] = &[
6969 b"Sebastian Thiel <byronimo@gmail.com> 1 -0030",
70+ b"Sebastian Thiel <byronimo@gmail.com> -1500 -0030",
7071 ".. ☺️Sebastian 王知明 Thiel🙌 .. <byronimo@gmail.com> 1528473343 +0230".as_bytes(),
7172 b".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere <byronimo@gmail.com> 1528473343 +0230"
7273 ];
gix-object/tests/commit/from_bytes.rs+26−0
@@ -134,6 +134,32 @@ fn with_encoding() -> crate::Result { · 133 unmodified lines
134134 Ok(())
135135 }
136136
137+#[test]
138+fn pre_epoch() -> crate::Result {
139+ let signature = || SignatureRef {
140+ name: "Législateur".into(),
141+ email: "".into(),
142+ time: Time {
143+ seconds: -5263834140,
144+ offset: 540,
145+ sign: Sign::Plus,
146+ },
147+ };
148+ assert_eq!(
149+ CommitRef::from_bytes(&fixture_name("commit", "pre-epoch.txt"))?,
150+ CommitRef {
151+ tree: b"71cdd4015386b764b178005cad4c88966bc9d61a".as_bstr(),
152+ parents: SmallVec::default(),
153+ author: signature(),
154+ committer: signature(),
155+ encoding: None,
156+ message: "Version consolidée au 14 mars 1803\n".into(),
157+ extra_headers: vec![]
158+ }
159+ );
160+ Ok(())
161+}
162+
137163 #[test]
138164 fn with_trailer() -> crate::Result {
139165 let kim = SignatureRef {
gix-object/tests/fixtures/commit/pre-epoch.txt+5−0
@@ -0,0 +1,5 @@
1+tree 71cdd4015386b764b178005cad4c88966bc9d61a
2+author Législateur <> -5263834140 +0009
3+committer Législateur <> -5263834140 +0009
4+
5+Version consolidée au 14 mars 1803
gix/tests/fixtures/generated-archives/make_pre_epoch_repo.tar.xz+3−0
@@ -0,0 +1,3 @@
1+version https://git-lfs.github.com/spec/v1
2+oid sha256:b8aff9b7f7d17a890e2153a3fc378d5b3123534bb33b7e220351bd2225b046cf
3+size 10280
gix/tests/fixtures/make_pre_epoch_repo.sh+30−0
@@ -0,0 +1,30 @@
1+#!/bin/bash
2+set -eu -o pipefail
3+
4+git init -q
5+git checkout -b main
6+
7+echo "hello\nworld" >> code.rs
8+git add code.rs
9+GIT_AUTHOR_DATE="@0 +0000" GIT_COMMITTER_DATE="@0 +0000" git commit -q -m c1
10+git cat-file -p @ > to-be-patched.txt
11+
12+patch -p1 <<EOF
13+diff --git a/to-be-patched.txt b/to-be-patched.txt
14+index 95ad1b1..3ea89af 100644
15+--- a/to-be-patched.txt
16++++ b/to-be-patched.txt
17+@@ -1,5 +1,5 @@
18+ tree 00d3a67028ba1004a04bd720eee966811102f0c3
19+-author author <author@example.com> 0 +0000
20+-committer committer <committer@example.com> 0 +0000
21++author author <author@example.com> -5263747740 +0009
22++committer committer <committer@example.com> -5263747740 +0009
23+
24+ c1
25+EOF
26+
27+new_commit=$(git hash-object -w -t commit to-be-patched.txt || git hash-object --literally -w -t commit to-be-patched.txt)
28+git update-ref refs/heads/main $new_commit
29+
30+git commit-graph write --no-progress --reachable
gix/tests/id/mod.rs+27−4
@@ -74,11 +74,11 @@ mod ancestors { · 73 unmodified lines
7474 #[test]
7575 fn all() -> crate::Result {
7676 let repo = crate::repo("make_repo_with_fork_and_dates.sh")?.to_thread_local();
77− for toggle in [false, true] {
77+ for use_commit_graph in [false, true] {
7878 let head = repo.head()?.into_fully_peeled_id().expect("born")?;
7979 let commits_graph_order = head
8080 .ancestors()
81− .use_commit_graph(toggle)
81+ .use_commit_graph(use_commit_graph)
8282 .all()?
8383 .map(|c| c.map(gix::revision::walk::Info::detach))
8484 .collect::<Result<Vec<_>, _>>()?;
@@ -86,7 +86,7 @@ mod ancestors { · 1 unmodified line
8686
8787 let commits_by_commit_date = head
8888 .ancestors()
89− .use_commit_graph(!toggle)
89+ .use_commit_graph(!use_commit_graph)
9090 .sorting(commit::Sorting::ByCommitTimeNewestFirst)
9191 .all()?
9292 .map(|c| c.map(gix::revision::walk::Info::detach))
@@ -104,7 +104,7 @@ mod ancestors { · 11 unmodified lines
104104 assert_eq!(
105105 head.ancestors()
106106 .first_parent_only()
107− .use_commit_graph(toggle)
107+ .use_commit_graph(use_commit_graph)
108108 .all()?
109109 .count(),
110110 3,
@@ -114,6 +114,29 @@ mod ancestors { · 3 unmodified lines
114114 Ok(())
115115 }
116116
117+ #[test]
118+ fn pre_epoch() -> crate::Result {
119+ let repo = crate::repo("make_pre_epoch_repo.sh")?.to_thread_local();
120+ for use_commit_graph in [false, true] {
121+ let head = repo.head()?.into_fully_peeled_id().expect("born")?;
122+ let commits = head
123+ .ancestors()
124+ .sorting(commit::Sorting::ByCommitTimeNewestFirst) // assure we have time set
125+ .use_commit_graph(use_commit_graph)
126+ .all()?
127+ .collect::<Result<Vec<_>, _>>()?;
128+ assert_eq!(commits.len(), 1, "only one commit");
129+
130+ let commit = &commits[0];
131+ assert_eq!(commit.id, hex_to_id("9902e3c3e8f0c569b4ab295ddf473e6de763e1e7"));
132+ assert_eq!(
133+ commit.commit_time(),
134+ 0 // TODO: actual time
135+ );
136+ }
137+ Ok(())
138+ }
139+
117140 #[test]
118141 fn filtered() -> crate::Result {
119142 let repo = crate::repo("make_repo_with_fork_and_dates.sh")?.to_thread_local();