33using System . IO ;
44using System . Linq ;
55using System . Text ;
6- using LibGit2Sharp . Core ;
76using LibGit2Sharp . Tests . TestHelpers ;
87using Xunit ;
9- using Xunit . Extensions ;
108
119namespace LibGit2Sharp . Tests
1210{
@@ -150,10 +148,10 @@ public void CanEnumerateCommitsWithReverseTimeSorting()
150148 using ( var repo = new Repository ( path ) )
151149 {
152150 foreach ( Commit commit in repo . Commits . QueryBy ( new CommitFilter
153- {
154- IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f" ,
155- SortBy = CommitSortStrategies . Time | CommitSortStrategies . Reverse
156- } ) )
151+ {
152+ IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f" ,
153+ SortBy = CommitSortStrategies . Time | CommitSortStrategies . Reverse
154+ } ) )
157155 {
158156 Assert . NotNull ( commit ) ;
159157 Assert . StartsWith ( reversedShas [ count ] , commit . Sha ) ;
@@ -170,10 +168,10 @@ public void CanEnumerateCommitsWithReverseTopoSorting()
170168 using ( var repo = new Repository ( path ) )
171169 {
172170 List < Commit > commits = repo . Commits . QueryBy ( new CommitFilter
173- {
174- IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f" ,
175- SortBy = CommitSortStrategies . Time | CommitSortStrategies . Reverse
176- } ) . ToList ( ) ;
171+ {
172+ IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f" ,
173+ SortBy = CommitSortStrategies . Time | CommitSortStrategies . Reverse
174+ } ) . ToList ( ) ;
177175 foreach ( Commit commit in commits )
178176 {
179177 Assert . NotNull ( commit ) ;
@@ -216,10 +214,10 @@ public void CanEnumerateCommitsWithTimeSorting()
216214 using ( var repo = new Repository ( path ) )
217215 {
218216 foreach ( Commit commit in repo . Commits . QueryBy ( new CommitFilter
219- {
220- IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f" ,
221- SortBy = CommitSortStrategies . Time
222- } ) )
217+ {
218+ IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f" ,
219+ SortBy = CommitSortStrategies . Time
220+ } ) )
223221 {
224222 Assert . NotNull ( commit ) ;
225223 Assert . StartsWith ( expectedShas [ count ] , commit . Sha ) ;
@@ -236,10 +234,10 @@ public void CanEnumerateCommitsWithTopoSorting()
236234 using ( var repo = new Repository ( path ) )
237235 {
238236 List < Commit > commits = repo . Commits . QueryBy ( new CommitFilter
239- {
240- IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f" ,
241- SortBy = CommitSortStrategies . Topological
242- } ) . ToList ( ) ;
237+ {
238+ IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f" ,
239+ SortBy = CommitSortStrategies . Topological
240+ } ) . ToList ( ) ;
243241 foreach ( Commit commit in commits )
244242 {
245243 Assert . NotNull ( commit ) ;
@@ -331,9 +329,12 @@ public void CanEnumerateCommitsFromTwoHeads()
331329 public void CanEnumerateCommitsFromMixedStartingPoints ( )
332330 {
333331 AssertEnumerationOfCommits (
334- repo => new CommitFilter { IncludeReachableFrom = new object [ ] { repo . Branches [ "br2" ] ,
332+ repo => new CommitFilter
333+ {
334+ IncludeReachableFrom = new object [ ] { repo . Branches [ "br2" ] ,
335335 "refs/heads/master" ,
336- new ObjectId ( "e90810b8df3e80c413d903f631643c716887138d" ) } } ,
336+ new ObjectId ( "e90810b8df3e80c413d903f631643c716887138d" ) }
337+ } ,
337338 new [ ]
338339 {
339340 "4c062a6" , "e90810b" , "6dcf9bf" , "a4a7dce" ,
@@ -389,9 +390,9 @@ public void CanEnumerateAllCommits()
389390 {
390391 AssertEnumerationOfCommits (
391392 repo => new CommitFilter
392- {
393- IncludeReachableFrom = repo . Refs . OrderBy ( r => r . CanonicalName , StringComparer . Ordinal ) ,
394- } ,
393+ {
394+ IncludeReachableFrom = repo . Refs . OrderBy ( r => r . CanonicalName , StringComparer . Ordinal ) ,
395+ } ,
395396 new [ ]
396397 {
397398 "44d5d18" , "bb65291" , "532740a" , "503a16f" , "3dfd6fd" ,
@@ -680,8 +681,12 @@ public void CanCommitALittleBit()
680681 Assert . Equal ( identity . Name , reflogEntry . Committer . Name ) ;
681682 Assert . Equal ( identity . Email , reflogEntry . Committer . Email ) ;
682683
683- var now = DateTimeOffset . Now ;
684- Assert . InRange ( reflogEntry . Committer . When , before , now ) ;
684+ // When verifying the timestamp range, give a little more room on the range.
685+ // Git or file system datetime truncation seems to cause these stamps to jump up to a second earlier
686+ // than we expect. See https://github.com/libgit2/libgit2sharp/issues/1764
687+ var low = before - TimeSpan . FromSeconds ( 1 ) ;
688+ var high = DateTimeOffset . Now . TruncateMilliseconds ( ) + TimeSpan . FromSeconds ( 1 ) ;
689+ Assert . InRange ( reflogEntry . Committer . When , low , high ) ;
685690
686691 Assert . Equal ( commit . Id , reflogEntry . To ) ;
687692 Assert . Equal ( ObjectId . Zero , reflogEntry . From ) ;
@@ -859,21 +864,21 @@ public void CanRetrieveChildrenOfASpecificCommit()
859864 const string parentSha = "5b5b025afb0b4c913b4c338a42934a3863bf3644" ;
860865
861866 var filter = new CommitFilter
862- {
863- /* Revwalk from all the refs (git log --all) ... */
864- IncludeReachableFrom = repo . Refs ,
867+ {
868+ /* Revwalk from all the refs (git log --all) ... */
869+ IncludeReachableFrom = repo . Refs ,
865870
866- /* ... and stop when the parent is reached */
867- ExcludeReachableFrom = parentSha
868- } ;
871+ /* ... and stop when the parent is reached */
872+ ExcludeReachableFrom = parentSha
873+ } ;
869874
870875 var commits = repo . Commits . QueryBy ( filter ) ;
871876
872877 var children = from c in commits
873- from p in c . Parents
874- let pId = p . Id
875- where pId . Sha == parentSha
876- select c ;
878+ from p in c . Parents
879+ let pId = p . Id
880+ where pId . Sha == parentSha
881+ select c ;
877882
878883 var expectedChildren = new [ ] { "c47800c7266a2be04c571c04d5a6614691ea99bd" ,
879884 "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" } ;
0 commit comments