3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using System . Text ;
6
- using LibGit2Sharp . Core ;
7
6
using LibGit2Sharp . Tests . TestHelpers ;
8
7
using Xunit ;
9
- using Xunit . Extensions ;
10
8
11
9
namespace LibGit2Sharp . Tests
12
10
{
@@ -150,10 +148,10 @@ public void CanEnumerateCommitsWithReverseTimeSorting()
150
148
using ( var repo = new Repository ( path ) )
151
149
{
152
150
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
+ } ) )
157
155
{
158
156
Assert . NotNull ( commit ) ;
159
157
Assert . StartsWith ( reversedShas [ count ] , commit . Sha ) ;
@@ -170,10 +168,10 @@ public void CanEnumerateCommitsWithReverseTopoSorting()
170
168
using ( var repo = new Repository ( path ) )
171
169
{
172
170
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 ( ) ;
177
175
foreach ( Commit commit in commits )
178
176
{
179
177
Assert . NotNull ( commit ) ;
@@ -216,10 +214,10 @@ public void CanEnumerateCommitsWithTimeSorting()
216
214
using ( var repo = new Repository ( path ) )
217
215
{
218
216
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
+ } ) )
223
221
{
224
222
Assert . NotNull ( commit ) ;
225
223
Assert . StartsWith ( expectedShas [ count ] , commit . Sha ) ;
@@ -236,10 +234,10 @@ public void CanEnumerateCommitsWithTopoSorting()
236
234
using ( var repo = new Repository ( path ) )
237
235
{
238
236
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 ( ) ;
243
241
foreach ( Commit commit in commits )
244
242
{
245
243
Assert . NotNull ( commit ) ;
@@ -331,9 +329,12 @@ public void CanEnumerateCommitsFromTwoHeads()
331
329
public void CanEnumerateCommitsFromMixedStartingPoints ( )
332
330
{
333
331
AssertEnumerationOfCommits (
334
- repo => new CommitFilter { IncludeReachableFrom = new object [ ] { repo . Branches [ "br2" ] ,
332
+ repo => new CommitFilter
333
+ {
334
+ IncludeReachableFrom = new object [ ] { repo . Branches [ "br2" ] ,
335
335
"refs/heads/master" ,
336
- new ObjectId ( "e90810b8df3e80c413d903f631643c716887138d" ) } } ,
336
+ new ObjectId ( "e90810b8df3e80c413d903f631643c716887138d" ) }
337
+ } ,
337
338
new [ ]
338
339
{
339
340
"4c062a6" , "e90810b" , "6dcf9bf" , "a4a7dce" ,
@@ -389,9 +390,9 @@ public void CanEnumerateAllCommits()
389
390
{
390
391
AssertEnumerationOfCommits (
391
392
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
+ } ,
395
396
new [ ]
396
397
{
397
398
"44d5d18" , "bb65291" , "532740a" , "503a16f" , "3dfd6fd" ,
@@ -680,8 +681,12 @@ public void CanCommitALittleBit()
680
681
Assert . Equal ( identity . Name , reflogEntry . Committer . Name ) ;
681
682
Assert . Equal ( identity . Email , reflogEntry . Committer . Email ) ;
682
683
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 ) ;
685
690
686
691
Assert . Equal ( commit . Id , reflogEntry . To ) ;
687
692
Assert . Equal ( ObjectId . Zero , reflogEntry . From ) ;
@@ -859,21 +864,21 @@ public void CanRetrieveChildrenOfASpecificCommit()
859
864
const string parentSha = "5b5b025afb0b4c913b4c338a42934a3863bf3644" ;
860
865
861
866
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 ,
865
870
866
- /* ... and stop when the parent is reached */
867
- ExcludeReachableFrom = parentSha
868
- } ;
871
+ /* ... and stop when the parent is reached */
872
+ ExcludeReachableFrom = parentSha
873
+ } ;
869
874
870
875
var commits = repo . Commits . QueryBy ( filter ) ;
871
876
872
877
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 ;
877
882
878
883
var expectedChildren = new [ ] { "c47800c7266a2be04c571c04d5a6614691ea99bd" ,
879
884
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045" } ;
0 commit comments