Unified · Split
| @@ -67,6 +67,7 @@ fn trim() { · 66 unmodified lines | ||
| 67 | 67 | fn round_trip() -> Result<(), Box<dyn std::error::Error>> { |
| 68 | 68 | static DEFAULTS: &[&[u8]] = &[ |
| 69 | 69 | b"Sebastian Thiel <byronimo@gmail.com> 1 -0030", |
| 70 | + b"Sebastian Thiel <byronimo@gmail.com> -1500 -0030", | |
| 70 | 71 | ".. ☺️Sebastian 王知明 Thiel🙌 .. <byronimo@gmail.com> 1528473343 +0230".as_bytes(), |
| 71 | 72 | b".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere <byronimo@gmail.com> 1528473343 +0230" |
| 72 | 73 | ]; |
| @@ -134,6 +134,32 @@ fn with_encoding() -> crate::Result { · 133 unmodified lines | ||
| 134 | 134 | Ok(()) |
| 135 | 135 | } |
| 136 | 136 | |
| 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 | + | |
| 137 | 163 | #[test] |
| 138 | 164 | fn with_trailer() -> crate::Result { |
| 139 | 165 | let kim = SignatureRef { |
| @@ -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 | |
| @@ -0,0 +1,3 @@ | ||
| 1 | +version https://git-lfs.github.com/spec/v1 | |
| 2 | +oid sha256:b8aff9b7f7d17a890e2153a3fc378d5b3123534bb33b7e220351bd2225b046cf | |
| 3 | +size 10280 | |
| @@ -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 | |
| @@ -74,11 +74,11 @@ mod ancestors { · 73 unmodified lines | ||
| 74 | 74 | #[test] |
| 75 | 75 | fn all() -> crate::Result { |
| 76 | 76 | 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] { | |
| 78 | 78 | let head = repo.head()?.into_fully_peeled_id().expect("born")?; |
| 79 | 79 | let commits_graph_order = head |
| 80 | 80 | .ancestors() |
| 81 | − .use_commit_graph(toggle) | |
| 81 | + .use_commit_graph(use_commit_graph) | |
| 82 | 82 | .all()? |
| 83 | 83 | .map(|c| c.map(gix::revision::walk::Info::detach)) |
| 84 | 84 | .collect::<Result<Vec<_>, _>>()?; |
| @@ -86,7 +86,7 @@ mod ancestors { · 1 unmodified line | ||
| 86 | 86 | |
| 87 | 87 | let commits_by_commit_date = head |
| 88 | 88 | .ancestors() |
| 89 | − .use_commit_graph(!toggle) | |
| 89 | + .use_commit_graph(!use_commit_graph) | |
| 90 | 90 | .sorting(commit::Sorting::ByCommitTimeNewestFirst) |
| 91 | 91 | .all()? |
| 92 | 92 | .map(|c| c.map(gix::revision::walk::Info::detach)) |
| @@ -104,7 +104,7 @@ mod ancestors { · 11 unmodified lines | ||
| 104 | 104 | assert_eq!( |
| 105 | 105 | head.ancestors() |
| 106 | 106 | .first_parent_only() |
| 107 | − .use_commit_graph(toggle) | |
| 107 | + .use_commit_graph(use_commit_graph) | |
| 108 | 108 | .all()? |
| 109 | 109 | .count(), |
| 110 | 110 | 3, |
| @@ -114,6 +114,29 @@ mod ancestors { · 3 unmodified lines | ||
| 114 | 114 | Ok(()) |
| 115 | 115 | } |
| 116 | 116 | |
| 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 | + | |
| 117 | 140 | #[test] |
| 118 | 141 | fn filtered() -> crate::Result { |
| 119 | 142 | let repo = crate::repo("make_repo_with_fork_and_dates.sh")?.to_thread_local(); |