diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b44eb56b..fd91f040e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,23 @@ - CI server: - @libgit2sharp: +## v0.9.5 + +### Additions + + - Add support to create, retrieve, list and remove object notes (#140) + - Make Repository able to rely on specified global and system config files (#157) + +### Changes + + - Remove repo.Branches.Checkout() + - Remove Tree.Files + - Update libgit2 binaries to libgit2/libgit2@4c977a6 + +### Fixes + + - Allow initialization of a repository located on a network path (#153) + ## v0.9 ### Additions diff --git a/Lib/NativeBinaries/amd64/git2.dll b/Lib/NativeBinaries/amd64/git2.dll index e790610fe..e7cbb2c48 100644 Binary files a/Lib/NativeBinaries/amd64/git2.dll and b/Lib/NativeBinaries/amd64/git2.dll differ diff --git a/Lib/NativeBinaries/amd64/git2.pdb b/Lib/NativeBinaries/amd64/git2.pdb index c6c00e587..64c934f58 100644 Binary files a/Lib/NativeBinaries/amd64/git2.pdb and b/Lib/NativeBinaries/amd64/git2.pdb differ diff --git a/Lib/NativeBinaries/x86/git2.dll b/Lib/NativeBinaries/x86/git2.dll index 696ce60c4..043bbb09c 100644 Binary files a/Lib/NativeBinaries/x86/git2.dll and b/Lib/NativeBinaries/x86/git2.dll differ diff --git a/Lib/NativeBinaries/x86/git2.pdb b/Lib/NativeBinaries/x86/git2.pdb index d3fb9852c..bf6279749 100644 Binary files a/Lib/NativeBinaries/x86/git2.pdb and b/Lib/NativeBinaries/x86/git2.pdb differ diff --git a/LibGit2Sharp.Tests/BlobFixture.cs b/LibGit2Sharp.Tests/BlobFixture.cs index be8c10a3a..ec56f380f 100755 --- a/LibGit2Sharp.Tests/BlobFixture.cs +++ b/LibGit2Sharp.Tests/BlobFixture.cs @@ -15,7 +15,7 @@ public void CanGetBlobAsUtf8() var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6"); string text = blob.ContentAsUtf8(); - text.ShouldEqual("hey there\n"); + Assert.Equal("hey there\n", text); } } @@ -25,7 +25,7 @@ public void CanGetBlobSize() using (var repo = new Repository(BareTestRepoPath)) { var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6"); - blob.Size.ShouldEqual(10); + Assert.Equal(10, blob.Size); } } @@ -35,7 +35,7 @@ public void CanLookUpBlob() using (var repo = new Repository(BareTestRepoPath)) { var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6"); - blob.ShouldNotBeNull(); + Assert.NotNull(blob); } } @@ -46,10 +46,10 @@ public void CanReadBlobContent() { var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6"); byte[] bytes = blob.Content; - bytes.Length.ShouldEqual(10); + Assert.Equal(10, bytes.Length); string content = Encoding.UTF8.GetString(bytes); - content.ShouldEqual("hey there\n"); + Assert.Equal("hey there\n", content); } } @@ -63,7 +63,7 @@ public void CanReadBlobStream() using (var tr = new StreamReader(blob.ContentStream, Encoding.UTF8)) { string content = tr.ReadToEnd(); - content.ShouldEqual("hey there\n"); + Assert.Equal("hey there\n", content); } } } @@ -97,7 +97,7 @@ public void CanStageAFileGeneratedFromABlobContentStream() repo.Index.Stage("small.txt"); IndexEntry entry = repo.Index["small.txt"]; - entry.Id.Sha.ShouldEqual("baae1fb3760a73481ced1fa03dc15614142c19ef"); + Assert.Equal("baae1fb3760a73481ced1fa03dc15614142c19ef", entry.Id.Sha); var blob = repo.Lookup(entry.Id.Sha); @@ -110,7 +110,7 @@ public void CanStageAFileGeneratedFromABlobContentStream() repo.Index.Stage("small.fromblob.txt"); IndexEntry newentry = repo.Index["small.fromblob.txt"]; - newentry.Id.Sha.ShouldEqual("baae1fb3760a73481ced1fa03dc15614142c19ef"); + Assert.Equal("baae1fb3760a73481ced1fa03dc15614142c19ef", newentry.Id.Sha); } } } diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index 5e29d7401..60c1126a5 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -19,12 +19,12 @@ public void CanCreateBranch(string name) using (var repo = new Repository(path.RepositoryPath)) { Branch newBranch = repo.CreateBranch(name, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); - newBranch.ShouldNotBeNull(); - newBranch.Name.ShouldEqual(name); - newBranch.CanonicalName.ShouldEqual("refs/heads/" + name); - newBranch.Tip.ShouldNotBeNull(); - newBranch.Tip.Sha.ShouldEqual("be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); - repo.Branches.SingleOrDefault(p => p.Name == name).ShouldNotBeNull(); + Assert.NotNull(newBranch); + Assert.Equal(name, newBranch.Name); + Assert.Equal("refs/heads/" + name, newBranch.CanonicalName); + Assert.NotNull(newBranch.Tip); + Assert.Equal("be3563ae3f795b2b4353bcce3a527ad0a4f7f644", newBranch.Tip.Sha); + Assert.NotNull(repo.Branches.SingleOrDefault(p => p.Name == name)); repo.Branches.Delete(newBranch.Name); } @@ -38,8 +38,8 @@ public void CanCreateBranchUsingAbbreviatedSha() { const string name = "unit_test"; Branch newBranch = repo.CreateBranch(name, "be3563a"); - newBranch.CanonicalName.ShouldEqual("refs/heads/" + name); - newBranch.Tip.Sha.ShouldEqual("be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + Assert.Equal("refs/heads/" + name, newBranch.CanonicalName); + Assert.Equal("be3563ae3f795b2b4353bcce3a527ad0a4f7f644", newBranch.Tip.Sha); } } @@ -51,13 +51,13 @@ public void CanCreateBranchFromImplicitHead() { const string name = "unit_test"; Branch newBranch = repo.CreateBranch(name); - newBranch.ShouldNotBeNull(); - newBranch.Name.ShouldEqual(name); - newBranch.CanonicalName.ShouldEqual("refs/heads/" + name); - newBranch.IsCurrentRepositoryHead.ShouldBeFalse(); - newBranch.Tip.ShouldNotBeNull(); - newBranch.Tip.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345"); - repo.Branches.SingleOrDefault(p => p.Name == name).ShouldNotBeNull(); + Assert.NotNull(newBranch); + Assert.Equal(name, newBranch.Name); + Assert.Equal("refs/heads/" + name, newBranch.CanonicalName); + Assert.False(newBranch.IsCurrentRepositoryHead); + Assert.NotNull(newBranch.Tip); + Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", newBranch.Tip.Sha); + Assert.NotNull(repo.Branches.SingleOrDefault(p => p.Name == name)); } } @@ -69,8 +69,8 @@ public void CanCreateBranchFromExplicitHead() { const string name = "unit_test"; Branch newBranch = repo.CreateBranch(name, "HEAD"); - newBranch.ShouldNotBeNull(); - newBranch.Tip.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345"); + Assert.NotNull(newBranch); + Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", newBranch.Tip.Sha); } } @@ -83,8 +83,8 @@ public void CanCreateBranchFromCommit() const string name = "unit_test"; var commit = repo.Lookup("HEAD"); Branch newBranch = repo.CreateBranch(name, commit); - newBranch.ShouldNotBeNull(); - newBranch.Tip.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345"); + Assert.NotNull(newBranch); + Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", newBranch.Tip.Sha); } } @@ -96,8 +96,8 @@ public void CreatingABranchFromATagPeelsToTheCommit() { const string name = "i-peel-tag"; Branch newBranch = repo.CreateBranch(name, "refs/tags/test"); - newBranch.ShouldNotBeNull(); - newBranch.Tip.Sha.ShouldEqual("e90810b8df3e80c413d903f631643c716887138d"); + Assert.NotNull(newBranch); + Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", newBranch.Tip.Sha); } } @@ -108,13 +108,13 @@ public void CreatingABranchTriggersTheCreationOfADirectReference() using (var repo = new Repository(path.RepositoryPath)) { Branch newBranch = repo.CreateBranch("clone-of-master"); - newBranch.IsCurrentRepositoryHead.ShouldBeFalse(); + Assert.False(newBranch.IsCurrentRepositoryHead); ObjectId commitId = repo.Head.Tip.Id; - newBranch.Tip.Id.ShouldEqual(commitId); + Assert.Equal(commitId, newBranch.Tip.Id); Reference reference = repo.Refs[newBranch.CanonicalName]; - reference.ShouldNotBeNull(); + Assert.NotNull(reference); Assert.IsType(typeof(DirectReference), reference); } } @@ -179,7 +179,7 @@ public void CanListAllBranches() { Assert.Equal(expectedBranches, repo.Branches.Select(b => b.Name).ToArray()); - repo.Branches.Count().ShouldEqual(5); + Assert.Equal(5, repo.Branches.Count()); } } @@ -221,15 +221,15 @@ public void CanLookupABranchByItsCanonicalName() using (var repo = new Repository(BareTestRepoPath)) { Branch branch = repo.Branches["refs/heads/br2"]; - branch.ShouldNotBeNull(); - branch.Name.ShouldEqual("br2"); + Assert.NotNull(branch); + Assert.Equal("br2", branch.Name); Branch branch2 = repo.Branches["refs/heads/br2"]; - branch2.ShouldNotBeNull(); - branch2.Name.ShouldEqual("br2"); + Assert.NotNull(branch2); + Assert.Equal("br2", branch2.Name); - branch2.ShouldEqual(branch); - (branch2 == branch).ShouldBeTrue(); + Assert.Equal(branch, branch2); + Assert.True((branch2 == branch)); } } @@ -239,12 +239,12 @@ public void CanLookupLocalBranch() using (var repo = new Repository(BareTestRepoPath)) { Branch master = repo.Branches["master"]; - master.ShouldNotBeNull(); - master.IsRemote.ShouldBeFalse(); - master.Name.ShouldEqual("master"); - master.CanonicalName.ShouldEqual("refs/heads/master"); - master.IsCurrentRepositoryHead.ShouldBeTrue(); - master.Tip.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345"); + Assert.NotNull(master); + Assert.False(master.IsRemote); + Assert.Equal("master", master.Name); + Assert.Equal("refs/heads/master", master.CanonicalName); + Assert.True(master.IsCurrentRepositoryHead); + Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", master.Tip.Sha); } } @@ -256,11 +256,11 @@ public void CanLookupABranchWhichNameIsMadeOfNon7BitsAsciiCharacters() { const string name = "Ångström"; Branch newBranch = repo.CreateBranch(name, "be3563a"); - newBranch.ShouldNotBeNull(); + Assert.NotNull(newBranch); Branch retrieved = repo.Branches["Ångström"]; - retrieved.ShouldNotBeNull(); - retrieved.Tip.ShouldEqual(newBranch.Tip); + Assert.NotNull(retrieved); + Assert.Equal(newBranch.Tip, retrieved.Tip); } } @@ -281,10 +281,10 @@ public void TrackingInformationIsEmptyForNonTrackingBranch() using (var repo = new Repository(BareTestRepoPath)) { Branch branch = repo.Branches["test"]; - branch.IsTracking.ShouldBeFalse(); - branch.TrackedBranch.ShouldBeNull(); - branch.AheadBy.ShouldEqual(0); - branch.BehindBy.ShouldEqual(0); + Assert.False(branch.IsTracking); + Assert.Null(branch.TrackedBranch); + Assert.Equal(0, branch.AheadBy); + Assert.Equal(0, branch.BehindBy); } } @@ -294,10 +294,10 @@ public void CanGetTrackingInformationForTrackingBranch() using (var repo = new Repository(StandardTestRepoPath)) { Branch master = repo.Branches["master"]; - master.IsTracking.ShouldBeTrue(); - master.TrackedBranch.ShouldEqual(repo.Branches["refs/remotes/origin/master"]); - master.AheadBy.ShouldEqual(2); - master.BehindBy.ShouldEqual(2); + Assert.True(master.IsTracking); + Assert.Equal(repo.Branches["refs/remotes/origin/master"], master.TrackedBranch); + Assert.Equal(2, master.AheadBy); + Assert.Equal(2, master.BehindBy); } } @@ -307,10 +307,10 @@ public void CanGetTrackingInformationForLocalTrackingBranch() using (var repo = new Repository(StandardTestRepoPath)) { var branch = repo.Branches["track-local"]; - branch.IsTracking.ShouldBeTrue(); - branch.TrackedBranch.ShouldEqual(repo.Branches["master"]); - branch.AheadBy.ShouldEqual(2); - branch.BehindBy.ShouldEqual(2); + Assert.True(branch.IsTracking); + Assert.Equal(repo.Branches["master"], branch.TrackedBranch); + Assert.Equal(2, branch.AheadBy); + Assert.Equal(2, branch.BehindBy); } } @@ -320,7 +320,7 @@ public void CanWalkCommitsFromAnotherBranch() using (var repo = new Repository(BareTestRepoPath)) { Branch master = repo.Branches["test"]; - master.Commits.Count().ShouldEqual(2); + Assert.Equal(2, master.Commits.Count()); } } @@ -330,7 +330,7 @@ public void CanWalkCommitsFromBranch() using (var repo = new Repository(BareTestRepoPath)) { Branch master = repo.Branches["master"]; - master.Commits.Count().ShouldEqual(7); + Assert.Equal(7, master.Commits.Count()); } } @@ -343,19 +343,19 @@ public void CanCheckoutAnExistingBranch(string name) using (var repo = new Repository(path.RepositoryPath)) { Branch master = repo.Branches["master"]; - master.IsCurrentRepositoryHead.ShouldBeTrue(); + Assert.True(master.IsCurrentRepositoryHead); Branch branch = repo.Branches[name]; - branch.ShouldNotBeNull(); + Assert.NotNull(branch); Branch test = repo.Checkout(branch); - repo.Info.IsHeadDetached.ShouldBeFalse(); + Assert.False(repo.Info.IsHeadDetached); - test.IsRemote.ShouldBeFalse(); - test.IsCurrentRepositoryHead.ShouldBeTrue(); - test.ShouldEqual(repo.Head); + Assert.False(test.IsRemote); + Assert.True(test.IsCurrentRepositoryHead); + Assert.Equal(repo.Head, test); - master.IsCurrentRepositoryHead.ShouldBeFalse(); + Assert.False(master.IsCurrentRepositoryHead); } } @@ -368,16 +368,16 @@ public void CanCheckoutAnExistingBranchByName(string name) using (var repo = new Repository(path.RepositoryPath)) { Branch master = repo.Branches["master"]; - master.IsCurrentRepositoryHead.ShouldBeTrue(); + Assert.True(master.IsCurrentRepositoryHead); Branch test = repo.Checkout(name); - repo.Info.IsHeadDetached.ShouldBeFalse(); + Assert.False(repo.Info.IsHeadDetached); - test.IsRemote.ShouldBeFalse(); - test.IsCurrentRepositoryHead.ShouldBeTrue(); - test.ShouldEqual(repo.Head); + Assert.False(test.IsRemote); + Assert.True(test.IsCurrentRepositoryHead); + Assert.Equal(repo.Head, test); - master.IsCurrentRepositoryHead.ShouldBeFalse(); + Assert.False(master.IsCurrentRepositoryHead); } } @@ -390,22 +390,22 @@ public void CanCheckoutAnArbitraryCommit(string commitPointer) using (var repo = new Repository(path.RepositoryPath)) { Branch master = repo.Branches["master"]; - master.IsCurrentRepositoryHead.ShouldBeTrue(); + Assert.True(master.IsCurrentRepositoryHead); Branch detachedHead = repo.Checkout(commitPointer); - repo.Info.IsHeadDetached.ShouldBeTrue(); + Assert.True(repo.Info.IsHeadDetached); - detachedHead.IsRemote.ShouldBeFalse(); - detachedHead.CanonicalName.ShouldEqual(detachedHead.Name); - detachedHead.CanonicalName.ShouldEqual("(no branch)"); - detachedHead.Tip.Sha.ShouldEqual(repo.Lookup(commitPointer).Sha); + Assert.False(detachedHead.IsRemote); + Assert.Equal(detachedHead.Name, detachedHead.CanonicalName); + Assert.Equal("(no branch)", detachedHead.CanonicalName); + Assert.Equal(repo.Lookup(commitPointer).Sha, detachedHead.Tip.Sha); - detachedHead.ShouldEqual(repo.Head); + Assert.Equal(repo.Head, detachedHead); - master.IsCurrentRepositoryHead.ShouldBeFalse(); - detachedHead.IsCurrentRepositoryHead.ShouldBeTrue(); - repo.Head.IsCurrentRepositoryHead.ShouldBeTrue(); + Assert.False(master.IsCurrentRepositoryHead); + Assert.True(detachedHead.IsCurrentRepositoryHead); + Assert.True(repo.Head.IsCurrentRepositoryHead); } } @@ -507,7 +507,7 @@ public void OnlyOneBranchIsTheHead() Assert.True(false, string.Format("Both '{0}' and '{1}' appear to be Head.", head.CanonicalName, branch.CanonicalName)); } - head.ShouldNotBeNull(); + Assert.NotNull(head); } } @@ -520,7 +520,7 @@ public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent() Branch master = repo.Branches["refs/heads/master"]; Branch newBranch = repo.Branches.Create("clone-of-master", master.Tip.Sha); - newBranch.IsCurrentRepositoryHead.ShouldBeFalse(); + Assert.False(newBranch.IsCurrentRepositoryHead); } } @@ -530,13 +530,13 @@ public void CanMoveABranch() TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); using (var repo = new Repository(path.RepositoryPath)) { - repo.Branches["br3"].ShouldBeNull(); + Assert.Null(repo.Branches["br3"]); Branch newBranch = repo.Branches.Move("br2", "br3"); - newBranch.Name.ShouldEqual("br3"); + Assert.Equal("br3", newBranch.Name); - repo.Branches["br2"].ShouldBeNull(); - repo.Branches["br3"].ShouldNotBeNull(); + Assert.Null(repo.Branches["br2"]); + Assert.NotNull(repo.Branches["br3"]); } } @@ -556,21 +556,21 @@ public void CanMoveABranchWhileOverwritingAnExistingOne() using (var repo = new Repository(path.RepositoryPath)) { Branch test = repo.Branches["test"]; - test.ShouldNotBeNull(); + Assert.NotNull(test); Branch br2 = repo.Branches["br2"]; - br2.ShouldNotBeNull(); + Assert.NotNull(br2); Branch newBranch = repo.Branches.Move("br2", "test", true); - newBranch.Name.ShouldEqual("test"); + Assert.Equal("test", newBranch.Name); - repo.Branches["br2"].ShouldBeNull(); + Assert.Null(repo.Branches["br2"]); Branch newTest = repo.Branches["test"]; - newTest.ShouldNotBeNull(); - newTest.ShouldEqual(newBranch); + Assert.NotNull(newTest); + Assert.Equal(newBranch, newTest); - newTest.Tip.ShouldEqual(br2.Tip); + Assert.Equal(br2.Tip, newTest.Tip); } } } diff --git a/LibGit2Sharp.Tests/CommitAncestorFixture.cs b/LibGit2Sharp.Tests/CommitAncestorFixture.cs index d8e523c18..af408ad67 100644 --- a/LibGit2Sharp.Tests/CommitAncestorFixture.cs +++ b/LibGit2Sharp.Tests/CommitAncestorFixture.cs @@ -39,7 +39,7 @@ public void CanFindCommonAncestorForTwoCommits() Commit ancestor = repo.Commits.FindCommonAncestor(first, second); Assert.NotNull(ancestor); - ancestor.Id.Sha.ShouldEqual("5b5b025afb0b4c913b4c338a42934a3863bf3644"); + Assert.Equal("5b5b025afb0b4c913b4c338a42934a3863bf3644", ancestor.Id.Sha); } } @@ -54,7 +54,7 @@ public void CanFindCommonAncestorForTwoCommitsAsEnumerable() Commit ancestor = repo.Commits.FindCommonAncestor(new[] { first, second }); Assert.NotNull(ancestor); - ancestor.Id.Sha.ShouldEqual("5b5b025afb0b4c913b4c338a42934a3863bf3644"); + Assert.Equal("5b5b025afb0b4c913b4c338a42934a3863bf3644", ancestor.Id.Sha); } } @@ -71,7 +71,7 @@ public void CanFindCommonAncestorForSeveralCommits() Commit ancestor = repo.Commits.FindCommonAncestor(new[] { first, second, third, fourth }); Assert.NotNull(ancestor); - ancestor.Id.Sha.ShouldEqual("5b5b025afb0b4c913b4c338a42934a3863bf3644"); + Assert.Equal("5b5b025afb0b4c913b4c338a42934a3863bf3644", ancestor.Id.Sha); } } diff --git a/LibGit2Sharp.Tests/CommitFixture.cs b/LibGit2Sharp.Tests/CommitFixture.cs index 76db42468..7ac93d1e5 100644 --- a/LibGit2Sharp.Tests/CommitFixture.cs +++ b/LibGit2Sharp.Tests/CommitFixture.cs @@ -18,7 +18,7 @@ public void CanCountCommits() { using (var repo = new Repository(BareTestRepoPath)) { - repo.Commits.Count().ShouldEqual(7); + Assert.Equal(7, repo.Commits.Count()); } } @@ -28,12 +28,12 @@ public void CanCorrectlyCountCommitsWhenSwitchingToAnotherBranch() using (var repo = new Repository(BareTestRepoPath)) { repo.Checkout("test"); - repo.Commits.Count().ShouldEqual(2); - repo.Commits.First().Id.Sha.ShouldEqual("e90810b8df3e80c413d903f631643c716887138d"); + Assert.Equal(2, repo.Commits.Count()); + Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", repo.Commits.First().Id.Sha); repo.Checkout("master"); - repo.Commits.Count().ShouldEqual(7); - repo.Commits.First().Id.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345"); + Assert.Equal(7, repo.Commits.Count()); + Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", repo.Commits.First().Id.Sha); } } @@ -45,11 +45,11 @@ public void CanEnumerateCommits() { foreach (Commit commit in repo.Commits) { - commit.ShouldNotBeNull(); + Assert.NotNull(commit); count++; } } - count.ShouldEqual(7); + Assert.Equal(7, count); } [Fact] @@ -63,7 +63,7 @@ public void CanEnumerateCommitsInDetachedHeadState() repo.Refs.Create("HEAD", parentOfHead.Sha, true); Assert.Equal(true, repo.Info.IsHeadDetached); - repo.Commits.Count().ShouldEqual(6); + Assert.Equal(6, repo.Commits.Count()); } } @@ -72,7 +72,7 @@ public void DefaultOrderingWhenEnumeratingCommitsIsTimeBased() { using (var repo = new Repository(BareTestRepoPath)) { - repo.Commits.SortedBy.ShouldEqual(GitSortOptions.Time); + Assert.Equal(GitSortOptions.Time, repo.Commits.SortedBy); } } @@ -84,11 +84,11 @@ public void CanEnumerateCommitsFromSha() { foreach (Commit commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f" })) { - commit.ShouldNotBeNull(); + Assert.NotNull(commit); count++; } } - count.ShouldEqual(6); + Assert.Equal(6, count); } [Fact] @@ -137,12 +137,12 @@ public void CanEnumerateCommitsWithReverseTimeSorting() { foreach (Commit commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time | GitSortOptions.Reverse })) { - commit.ShouldNotBeNull(); - commit.Sha.StartsWith(reversedShas[count]).ShouldBeTrue(); + Assert.NotNull(commit); + Assert.True(commit.Sha.StartsWith(reversedShas[count])); count++; } } - count.ShouldEqual(6); + Assert.Equal(6, count); } [Fact] @@ -153,7 +153,7 @@ public void CanEnumerateCommitsWithReverseTopoSorting() List commits = repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time | GitSortOptions.Reverse }).ToList(); foreach (Commit commit in commits) { - commit.ShouldNotBeNull(); + Assert.NotNull(commit); foreach (Commit p in commit.Parents) { Commit parent = commits.Single(x => x.Id == p.Id); @@ -168,7 +168,7 @@ public void CanGetParentsCount() { using (var repo = new Repository(BareTestRepoPath)) { - repo.Commits.First().ParentsCount.ShouldEqual(1); + Assert.Equal(1, repo.Commits.First().ParentsCount); } } @@ -180,12 +180,12 @@ public void CanEnumerateCommitsWithTimeSorting() { foreach (Commit commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time })) { - commit.ShouldNotBeNull(); - commit.Sha.StartsWith(expectedShas[count]).ShouldBeTrue(); + Assert.NotNull(commit); + Assert.True(commit.Sha.StartsWith(expectedShas[count])); count++; } } - count.ShouldEqual(6); + Assert.Equal(6, count); } [Fact] @@ -196,7 +196,7 @@ public void CanEnumerateCommitsWithTopoSorting() List commits = repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Topological }).ToList(); foreach (Commit commit in commits) { - commit.ShouldNotBeNull(); + Assert.NotNull(commit); foreach (Commit p in commit.Parents) { Commit parent = commits.Single(x => x.Id == p.Id); @@ -316,8 +316,9 @@ public void CanEnumerateAllCommits() repo => new Filter { Since = repo.Refs }, new[] { - "4c062a6", "e90810b", "6dcf9bf", "a4a7dce", - "be3563a", "c47800c", "9fd738e", "4a202b3", + "44d5d18", "bb65291", "532740a", "503a16f", "3dfd6fd", + "4409de1", "902c60b", "4c062a6", "e90810b", "6dcf9bf", + "a4a7dce", "be3563a", "c47800c", "9fd738e", "4a202b3", "41bc8c6", "5001298", "5b5b025", "8496071", }); } @@ -353,9 +354,9 @@ public void CanLookupCommitGeneric() using (var repo = new Repository(BareTestRepoPath)) { var commit = repo.Lookup(sha); - commit.Message.ShouldEqual("testing\n"); - commit.MessageShort.ShouldEqual("testing"); - commit.Sha.ShouldEqual(sha); + Assert.Equal("testing\n", commit.Message); + Assert.Equal("testing", commit.MessageShort); + Assert.Equal(sha, commit.Sha); } } @@ -365,28 +366,28 @@ public void CanReadCommitData() using (var repo = new Repository(BareTestRepoPath)) { GitObject obj = repo.Lookup(sha); - obj.ShouldNotBeNull(); - obj.GetType().ShouldEqual(typeof(Commit)); + Assert.NotNull(obj); + Assert.Equal(typeof(Commit), obj.GetType()); var commit = (Commit)obj; - commit.Message.ShouldEqual("testing\n"); - commit.MessageShort.ShouldEqual("testing"); - commit.Encoding.ShouldEqual("UTF-8"); - commit.Sha.ShouldEqual(sha); + Assert.Equal("testing\n", commit.Message); + Assert.Equal("testing", commit.MessageShort); + Assert.Equal("UTF-8", commit.Encoding); + Assert.Equal(sha, commit.Sha); - commit.Author.ShouldNotBeNull(); - commit.Author.Name.ShouldEqual("Scott Chacon"); - commit.Author.Email.ShouldEqual("schacon@gmail.com"); - commit.Author.When.ToSecondsSinceEpoch().ShouldEqual(1273360386); + Assert.NotNull(commit.Author); + Assert.Equal("Scott Chacon", commit.Author.Name); + Assert.Equal("schacon@gmail.com", commit.Author.Email); + Assert.Equal(1273360386, commit.Author.When.ToSecondsSinceEpoch()); - commit.Committer.ShouldNotBeNull(); - commit.Committer.Name.ShouldEqual("Scott Chacon"); - commit.Committer.Email.ShouldEqual("schacon@gmail.com"); - commit.Committer.When.ToSecondsSinceEpoch().ShouldEqual(1273360386); + Assert.NotNull(commit.Committer); + Assert.Equal("Scott Chacon", commit.Committer.Name); + Assert.Equal("schacon@gmail.com", commit.Committer.Email); + Assert.Equal(1273360386, commit.Committer.When.ToSecondsSinceEpoch()); - commit.Tree.Sha.ShouldEqual("181037049a54a1eb5fab404658a3a250b44335d7"); + Assert.Equal("181037049a54a1eb5fab404658a3a250b44335d7", commit.Tree.Sha); - commit.ParentsCount.ShouldEqual(0); + Assert.Equal(0, commit.ParentsCount); } } @@ -396,8 +397,8 @@ public void CanReadCommitWithMultipleParents() using (var repo = new Repository(BareTestRepoPath)) { var commit = repo.Lookup("a4a7dce85cf63874e984719f4fdd239f5145052f"); - commit.Parents.Count().ShouldEqual(2); - commit.ParentsCount.ShouldEqual(2); + Assert.Equal(2, commit.Parents.Count()); + Assert.Equal(2, commit.ParentsCount); } } @@ -409,9 +410,9 @@ public void CanDirectlyAccessABlobOfTheCommit() var commit = repo.Lookup("4c062a6"); var blob = commit["1/branch_file.txt"].Target as Blob; - blob.ShouldNotBeNull(); + Assert.NotNull(blob); - blob.ContentAsUtf8().ShouldEqual("hi\n"); + Assert.Equal("hi\n", blob.ContentAsUtf8()); } } @@ -423,7 +424,7 @@ public void CanDirectlyAccessATreeOfTheCommit() var commit = repo.Lookup("4c062a6"); var tree1 = commit["1"].Target as Tree; - tree1.ShouldNotBeNull(); + Assert.NotNull(tree1); } } @@ -434,7 +435,7 @@ public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull() { var commit = repo.Lookup("4c062a6"); - commit["I-am-not-here"].ShouldBeNull(); + Assert.Null(commit["I-am-not-here"]); } } @@ -446,8 +447,8 @@ public void CanCommitWithSignatureFromConfig() using (var repo = Repository.Init(scd.DirectoryPath)) { string dir = repo.Info.Path; - Path.IsPathRooted(dir).ShouldBeTrue(); - Directory.Exists(dir).ShouldBeTrue(); + Assert.True(Path.IsPathRooted(dir)); + Assert.True(Directory.Exists(dir)); InconclusiveIf(() => !repo.Config.HasGlobalConfig, "No Git global configuration available"); @@ -459,7 +460,7 @@ public void CanCommitWithSignatureFromConfig() File.AppendAllText(filePath, "token\n"); repo.Index.Stage(relativeFilepath); - repo.Head[relativeFilepath].ShouldBeNull(); + Assert.Null(repo.Head[relativeFilepath]); Commit commit = repo.Commit("Initial egotistic commit"); @@ -483,8 +484,8 @@ public void CanCommitALittleBit() using (var repo = Repository.Init(scd.DirectoryPath)) { string dir = repo.Info.Path; - Path.IsPathRooted(dir).ShouldBeTrue(); - Directory.Exists(dir).ShouldBeTrue(); + Assert.True(Path.IsPathRooted(dir)); + Assert.True(Directory.Exists(dir)); const string relativeFilepath = "new.txt"; string filePath = Path.Combine(repo.Info.WorkingDirectory, relativeFilepath); @@ -494,7 +495,7 @@ public void CanCommitALittleBit() File.AppendAllText(filePath, "token\n"); repo.Index.Stage(relativeFilepath); - repo.Head[relativeFilepath].ShouldBeNull(); + Assert.Null(repo.Head[relativeFilepath]); var author = DummySignature; Commit commit = repo.Commit("Initial egotistic commit", author, author); @@ -502,8 +503,8 @@ public void CanCommitALittleBit() AssertBlobContent(repo.Head[relativeFilepath], "nulltoken\n"); AssertBlobContent(commit[relativeFilepath], "nulltoken\n"); - commit.ParentsCount.ShouldEqual(0); - repo.Info.IsEmpty.ShouldBeFalse(); + Assert.Equal(0, commit.ParentsCount); + Assert.False(repo.Info.IsEmpty); File.WriteAllText(filePath, "nulltoken commits!\n"); repo.Index.Stage(relativeFilepath); @@ -514,8 +515,8 @@ public void CanCommitALittleBit() AssertBlobContent(repo.Head[relativeFilepath], "nulltoken commits!\n"); AssertBlobContent(commit2[relativeFilepath], "nulltoken commits!\n"); - commit2.ParentsCount.ShouldEqual(1); - commit2.Parents.First().Id.ShouldEqual(commit.Id); + Assert.Equal(1, commit2.ParentsCount); + Assert.Equal(commit.Id, commit2.Parents.First().Id); Branch firstCommitBranch = repo.CreateBranch("davidfowl-rules", commit); repo.Checkout(firstCommitBranch); @@ -530,8 +531,8 @@ public void CanCommitALittleBit() AssertBlobContent(repo.Head[relativeFilepath], "davidfowl commits!\n"); AssertBlobContent(commit3[relativeFilepath], "davidfowl commits!\n"); - commit3.ParentsCount.ShouldEqual(1); - commit3.Parents.First().Id.ShouldEqual(commit.Id); + Assert.Equal(1, commit3.ParentsCount); + Assert.Equal(commit.Id, commit3.Parents.First().Id); AssertBlobContent(firstCommitBranch[relativeFilepath], "nulltoken\n"); } @@ -539,8 +540,8 @@ public void CanCommitALittleBit() private static void AssertBlobContent(TreeEntry entry, string expectedContent) { - entry.Type.ShouldEqual(GitObjectType.Blob); - ((Blob)(entry.Target)).ContentAsUtf8().ShouldEqual(expectedContent); + Assert.Equal(GitObjectType.Blob, entry.Type); + Assert.Equal(expectedContent, ((Blob)(entry.Target)).ContentAsUtf8()); } private static void CommitToANewRepository(string path) @@ -568,12 +569,12 @@ public void CanGeneratePredictableObjectShas() using (var repo = new Repository(scd.DirectoryPath)) { Commit commit = repo.Commits.Single(); - commit.Sha.ShouldEqual("1fe3126578fc4eca68c193e4a3a0a14a0704624d"); + Assert.Equal("1fe3126578fc4eca68c193e4a3a0a14a0704624d", commit.Sha); Tree tree = commit.Tree; - tree.Sha.ShouldEqual("2b297e643c551e76cfa1f93810c50811382f9117"); + Assert.Equal("2b297e643c551e76cfa1f93810c50811382f9117", tree.Sha); Blob blob = tree.Blobs.Single(); - blob.Sha.ShouldEqual("9daeafb9864cf43055ae93beb0afd6c7d144bfa4"); + Assert.Equal("9daeafb9864cf43055ae93beb0afd6c7d144bfa4", blob.Sha); } } @@ -586,16 +587,16 @@ public void CanAmendARootCommit() using (var repo = new Repository(scd.DirectoryPath)) { - repo.Head.Commits.Count().ShouldEqual(1); + Assert.Equal(1, repo.Head.Commits.Count()); Commit originalCommit = repo.Head.Tip; - originalCommit.ParentsCount.ShouldEqual(0); + Assert.Equal(0, originalCommit.ParentsCount); CreateAndStageANewFile(repo); Commit amendedCommit = repo.Commit("I'm rewriting the history!", DummySignature, DummySignature, true); - repo.Head.Commits.Count().ShouldEqual(1); + Assert.Equal(1, repo.Head.Commits.Count()); AssertCommitHasBeenAmended(repo, amendedCommit, originalCommit); } @@ -608,8 +609,8 @@ public void CanAmendACommitWithMoreThanOneParent() using (var repo = new Repository(path.RepositoryPath)) { var mergedCommit = repo.Lookup("be3563a"); - mergedCommit.ShouldNotBeNull(); - mergedCommit.ParentsCount.ShouldEqual(2); + Assert.NotNull(mergedCommit); + Assert.Equal(2, mergedCommit.ParentsCount); repo.Reset(ResetOptions.Soft, mergedCommit.Sha); @@ -633,9 +634,9 @@ private static void CreateAndStageANewFile(Repository repo) private void AssertCommitHasBeenAmended(Repository repo, Commit amendedCommit, Commit originalCommit) { Commit headCommit = repo.Head.Tip; - headCommit.ShouldEqual(amendedCommit); + Assert.Equal(amendedCommit, headCommit); - amendedCommit.Sha.ShouldNotEqual(originalCommit.Sha); + Assert.NotEqual(originalCommit.Sha, amendedCommit.Sha); Assert.Equal(originalCommit.Parents, amendedCommit.Parents); } diff --git a/LibGit2Sharp.Tests/ConfigurationFixture.cs b/LibGit2Sharp.Tests/ConfigurationFixture.cs index e36c114b5..7e1ebd908 100644 --- a/LibGit2Sharp.Tests/ConfigurationFixture.cs +++ b/LibGit2Sharp.Tests/ConfigurationFixture.cs @@ -14,13 +14,6 @@ private static void AssertValueInLocalConfigFile(string repoPath, string regex) AssertValueInConfigFile(configFilePath, regex); } - private static void AssertValueInConfigFile(string configFilePath, string regex) - { - var text = File.ReadAllText(configFilePath); - var r = new Regex(regex, RegexOptions.Multiline).Match(text); - Assert.True(r.Success, text); - } - private static string RetrieveGlobalConfigLocation() { string[] variables = { "HOME", "USERPROFILE", }; @@ -56,14 +49,14 @@ public void CanDeleteConfiguration() var path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath); using (var repo = new Repository(path.RepositoryPath)) { - repo.Config.Get("unittests.boolsetting", false).ShouldBeFalse(); + Assert.False(repo.Config.Get("unittests.boolsetting", false)); repo.Config.Set("unittests.boolsetting", true); - repo.Config.Get("unittests.boolsetting", false).ShouldBeTrue(); + Assert.True(repo.Config.Get("unittests.boolsetting", false)); repo.Config.Delete("unittests.boolsetting"); - repo.Config.Get("unittests.boolsetting", false).ShouldBeFalse(); + Assert.False(repo.Config.Get("unittests.boolsetting", false)); } } @@ -74,7 +67,7 @@ public void CanGetGlobalStringValue() { InconclusiveIf(() => !repo.Config.HasGlobalConfig, "No Git global configuration available"); - repo.Config.Get("user.name", null).ShouldNotBeNull(); + Assert.NotNull(repo.Config.Get("user.name", null)); } } @@ -84,7 +77,7 @@ public void CanGetGlobalStringValueWithoutRepo() using (var config = new Configuration()) { InconclusiveIf(() => !config.HasGlobalConfig, "No Git global configuration available"); - config.Get("user.name", null).ShouldNotBeNull(); + Assert.NotNull(config.Get("user.name", null)); } } @@ -148,7 +141,7 @@ public void CanSetGlobalStringValue() InconclusiveIf(() => !repo.Config.HasGlobalConfig, "No Git global configuration available"); var existing = repo.Config.Get("user.name", null); - existing.ShouldNotBeNull(); + Assert.NotNull(existing); try { @@ -171,7 +164,7 @@ public void CanSetGlobalStringValueWithoutRepo() InconclusiveIf(() => !config.HasGlobalConfig, "No Git global configuration available"); var existing = config.Get("user.name", null); - existing.ShouldNotBeNull(); + Assert.NotNull(existing); try { @@ -242,14 +235,14 @@ public void CanSetAndReadUnicodeStringValue() AssertValueInLocalConfigFile(path.RepositoryPath, "stringsetting = Juliën$"); string val = repo.Config.Get("unittests.stringsetting", ""); - val.ShouldEqual("Juliën"); + Assert.Equal("Juliën", val); } // Make sure the change is permanent using (var repo = new Repository(path.RepositoryPath)) { string val = repo.Config.Get("unittests.stringsetting", ""); - val.ShouldEqual("Juliën"); + Assert.Equal("Juliën", val); } } @@ -268,14 +261,14 @@ public void ReadingValueThatDoesntExistReturnsDefault() { using (var repo = new Repository(StandardTestRepoPath)) { - repo.Config.Get("unittests.ghostsetting", null).ShouldBeNull(); - repo.Config.Get("unittests.ghostsetting", 0).ShouldEqual(0); - repo.Config.Get("unittests.ghostsetting", 0L).ShouldEqual(0L); - repo.Config.Get("unittests.ghostsetting", false).ShouldBeFalse(); - repo.Config.Get("unittests.ghostsetting", "42").ShouldEqual("42"); - repo.Config.Get("unittests.ghostsetting", 42).ShouldEqual(42); - repo.Config.Get("unittests.ghostsetting", 42L).ShouldEqual(42L); - repo.Config.Get("unittests.ghostsetting", true).ShouldBeTrue(); + Assert.Null(repo.Config.Get("unittests.ghostsetting", null)); + Assert.Equal(0, repo.Config.Get("unittests.ghostsetting", 0)); + Assert.Equal(0L, repo.Config.Get("unittests.ghostsetting", 0L)); + Assert.False(repo.Config.Get("unittests.ghostsetting", false)); + Assert.Equal("42", repo.Config.Get("unittests.ghostsetting", "42")); + Assert.Equal(42, repo.Config.Get("unittests.ghostsetting", 42)); + Assert.Equal(42L, repo.Config.Get("unittests.ghostsetting", 42L)); + Assert.True(repo.Config.Get("unittests.ghostsetting", true)); } } diff --git a/LibGit2Sharp.Tests/IndexFixture.cs b/LibGit2Sharp.Tests/IndexFixture.cs index 8ece28bfe..bd51d91eb 100644 --- a/LibGit2Sharp.Tests/IndexFixture.cs +++ b/LibGit2Sharp.Tests/IndexFixture.cs @@ -31,7 +31,7 @@ public void CanCountEntriesInIndex() { using (var repo = new Repository(StandardTestRepoPath)) { - repo.Index.Count.ShouldEqual(expectedEntries.Count()); + Assert.Equal(expectedEntries.Count(), repo.Index.Count); } } @@ -50,15 +50,15 @@ public void CanFetchAnIndexEntryByItsName() using (var repo = new Repository(StandardTestRepoPath)) { IndexEntry entry = repo.Index["README"]; - entry.Path.ShouldEqual("README"); + Assert.Equal("README", entry.Path); // Expressed in Posix format... IndexEntry entryWithPath = repo.Index["1/branch_file.txt"]; - entryWithPath.Path.ShouldEqual(subBranchFile); + Assert.Equal(subBranchFile, entryWithPath.Path); //...or in native format IndexEntry entryWithPath2 = repo.Index[subBranchFile]; - entryWithPath2.ShouldEqual(entryWithPath); + Assert.Equal(entryWithPath, entryWithPath2); } } @@ -68,7 +68,7 @@ public void FetchingAnUnknownIndexEntryReturnsNull() using (var repo = new Repository(StandardTestRepoPath)) { IndexEntry entry = repo.Index["I-do-not-exist.txt"]; - entry.ShouldBeNull(); + Assert.Null(entry); } } @@ -95,14 +95,14 @@ public void CanStage(string relativePath, FileStatus currentStatus, bool doesCur using (var repo = new Repository(path.RepositoryPath)) { int count = repo.Index.Count; - (repo.Index[relativePath] != null).ShouldEqual(doesCurrentlyExistInTheIndex); - repo.Index.RetrieveStatus(relativePath).ShouldEqual(currentStatus); + Assert.Equal(doesCurrentlyExistInTheIndex, (repo.Index[relativePath] != null)); + Assert.Equal(currentStatus, repo.Index.RetrieveStatus(relativePath)); repo.Index.Stage(relativePath); - repo.Index.Count.ShouldEqual(count + expectedIndexCountVariation); - (repo.Index[relativePath] != null).ShouldEqual(doesExistInTheIndexOnceStaged); - repo.Index.RetrieveStatus(relativePath).ShouldEqual(expectedStatusOnceStaged); + Assert.Equal(count + expectedIndexCountVariation, repo.Index.Count); + Assert.Equal(doesExistInTheIndexOnceStaged, (repo.Index[relativePath] != null)); + Assert.Equal(expectedStatusOnceStaged, repo.Index.RetrieveStatus(relativePath)); } } @@ -116,17 +116,17 @@ public void CanStageTheUpdationOfAStagedFile() const string filename = "new_tracked_file.txt"; IndexEntry blob = repo.Index[filename]; - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added); + Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(filename)); File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, filename), "brand new content"); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added | FileStatus.Modified); + Assert.Equal(FileStatus.Added | FileStatus.Modified, repo.Index.RetrieveStatus(filename)); repo.Index.Stage(filename); IndexEntry newBlob = repo.Index[filename]; - repo.Index.Count.ShouldEqual(count); - blob.Id.ShouldNotEqual(newBlob.Id); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added); + Assert.Equal(count, repo.Index.Count); + Assert.NotEqual(newBlob.Id, blob.Id); + Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(filename)); } } @@ -137,8 +137,8 @@ public void StagingAnUnknownFileThrows(string relativePath, FileStatus status) { using (var repo = new Repository(StandardTestRepoPath)) { - repo.Index[relativePath].ShouldBeNull(); - repo.Index.RetrieveStatus(relativePath).ShouldEqual(status); + Assert.Null(repo.Index[relativePath]); + Assert.Equal(status, repo.Index.RetrieveStatus(relativePath)); Assert.Throws(() => repo.Index.Stage(relativePath)); } @@ -152,18 +152,18 @@ public void CanStageTheRemovalOfAStagedFile() { int count = repo.Index.Count; const string filename = "new_tracked_file.txt"; - repo.Index[filename].ShouldNotBeNull(); + Assert.NotNull(repo.Index[filename]); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added); + Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(filename)); File.Delete(Path.Combine(repo.Info.WorkingDirectory, filename)); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added | FileStatus.Missing); + Assert.Equal(FileStatus.Added | FileStatus.Missing, repo.Index.RetrieveStatus(filename)); repo.Index.Stage(filename); - repo.Index[filename].ShouldBeNull(); + Assert.Null(repo.Index[filename]); - repo.Index.Count.ShouldEqual(count - 1); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Nonexistent); + Assert.Equal(count - 1, repo.Index.Count); + Assert.Equal(FileStatus.Nonexistent, repo.Index.RetrieveStatus(filename)); } } @@ -184,12 +184,12 @@ public void StagingANewVersionOfAFileThenUnstagingItRevertsTheBlobToTheVersionOf File.AppendAllText(fullpath, "Is there there anybody out there?"); repo.Index.Stage(filename); - repo.Index.Count.ShouldEqual(count); - repo.Index[posixifiedFileName].Id.ShouldNotEqual((blobId)); + Assert.Equal(count, repo.Index.Count); + Assert.NotEqual((blobId), repo.Index[posixifiedFileName].Id); repo.Index.Unstage(posixifiedFileName); - repo.Index.Count.ShouldEqual(count); - repo.Index[posixifiedFileName].Id.ShouldEqual((blobId)); + Assert.Equal(count, repo.Index.Count); + Assert.Equal(blobId, repo.Index[posixifiedFileName].Id); } } @@ -200,25 +200,25 @@ public void CanStageANewFileInAPersistentManner() using (var repo = new Repository(path.RepositoryPath)) { const string filename = "unit_test.txt"; - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Nonexistent); - repo.Index[filename].ShouldBeNull(); + Assert.Equal(FileStatus.Nonexistent, repo.Index.RetrieveStatus(filename)); + Assert.Null(repo.Index[filename]); File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, filename), "some contents"); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Untracked); - repo.Index[filename].ShouldBeNull(); + Assert.Equal(FileStatus.Untracked, repo.Index.RetrieveStatus(filename)); + Assert.Null(repo.Index[filename]); repo.Index.Stage(filename); - repo.Index[filename].ShouldNotBeNull(); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added); - repo.Index[filename].State.ShouldEqual(FileStatus.Added); + Assert.NotNull(repo.Index[filename]); + Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(filename)); + Assert.Equal(FileStatus.Added, repo.Index[filename].State); } using (var repo = new Repository(path.RepositoryPath)) { const string filename = "unit_test.txt"; - repo.Index[filename].ShouldNotBeNull(); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added); - repo.Index[filename].State.ShouldEqual(FileStatus.Added); + Assert.NotNull(repo.Index[filename]); + Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(filename)); + Assert.Equal(FileStatus.Added, repo.Index[filename].State); } } @@ -232,12 +232,12 @@ public void CanStageANewFileWithAFullPath() const string filename = "new_untracked_file.txt"; string fullPath = Path.Combine(repo.Info.WorkingDirectory, filename); - File.Exists(fullPath).ShouldBeTrue(); + Assert.True(File.Exists(fullPath)); repo.Index.Stage(fullPath); - repo.Index.Count.ShouldEqual(count + 1); - repo.Index[filename].ShouldNotBeNull(); + Assert.Equal(count + 1, repo.Index.Count); + Assert.NotNull(repo.Index[filename]); } } @@ -256,11 +256,11 @@ public void CanStageANewFileWithARelativePathContainingNativeDirectorySeparatorC repo.Index.Stage(file); - repo.Index.Count.ShouldEqual(count + 1); + Assert.Equal(count + 1, repo.Index.Count); const string posixifiedPath = "Project/a_file.txt"; - repo.Index[posixifiedPath].ShouldNotBeNull(); - repo.Index[posixifiedPath].Path.ShouldEqual(file); + Assert.NotNull(repo.Index[posixifiedPath]); + Assert.Equal(file, repo.Index[posixifiedPath].Path); } } @@ -306,14 +306,14 @@ public void CanUnStage(string relativePath, FileStatus currentStatus, bool doesC using (var repo = new Repository(path.RepositoryPath)) { int count = repo.Index.Count; - (repo.Index[relativePath] != null).ShouldEqual(doesCurrentlyExistInTheIndex); - repo.Index.RetrieveStatus(relativePath).ShouldEqual(currentStatus); + Assert.Equal(doesCurrentlyExistInTheIndex, (repo.Index[relativePath] != null)); + Assert.Equal(currentStatus, repo.Index.RetrieveStatus(relativePath)); repo.Index.Unstage(relativePath); - repo.Index.Count.ShouldEqual(count + expectedIndexCountVariation); - (repo.Index[relativePath] != null).ShouldEqual(doesExistInTheIndexOnceStaged); - repo.Index.RetrieveStatus(relativePath).ShouldEqual(expectedStatusOnceStaged); + Assert.Equal(count + expectedIndexCountVariation, repo.Index.Count); + Assert.Equal(doesExistInTheIndexOnceStaged, (repo.Index[relativePath] != null)); + Assert.Equal(expectedStatusOnceStaged, repo.Index.RetrieveStatus(relativePath)); } } @@ -328,14 +328,14 @@ public void CanUnstageTheRemovalOfAFile() const string filename = "deleted_staged_file.txt"; string fullPath = Path.Combine(repo.Info.WorkingDirectory, filename); - File.Exists(fullPath).ShouldBeFalse(); + Assert.False(File.Exists(fullPath)); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Removed); + Assert.Equal(FileStatus.Removed, repo.Index.RetrieveStatus(filename)); repo.Index.Unstage(filename); - repo.Index.Count.ShouldEqual(count + 1); + Assert.Equal(count + 1, repo.Index.Count); - repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Missing); + Assert.Equal(FileStatus.Missing, repo.Index.RetrieveStatus(filename)); } } @@ -358,47 +358,47 @@ public void CanRenameAFile() using (var repo = Repository.Init(scd.DirectoryPath)) { - repo.Index.Count.ShouldEqual(0); + Assert.Equal(0, repo.Index.Count); const string oldName = "polite.txt"; string oldPath = Path.Combine(repo.Info.WorkingDirectory, oldName); - repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Nonexistent); + Assert.Equal(FileStatus.Nonexistent, repo.Index.RetrieveStatus(oldName)); File.WriteAllText(oldPath, "hello test file\n", Encoding.ASCII); - repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Untracked); + Assert.Equal(FileStatus.Untracked, repo.Index.RetrieveStatus(oldName)); repo.Index.Stage(oldName); - repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Added); + Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(oldName)); // Generated through // $ echo "hello test file" | git hash-object --stdin const string expectedHash = "88df547706c30fa19f02f43cb2396e8129acfd9b"; - repo.Index[oldName].Id.Sha.ShouldEqual((expectedHash)); + Assert.Equal(expectedHash, repo.Index[oldName].Id.Sha); - repo.Index.Count.ShouldEqual(1); + Assert.Equal(1, repo.Index.Count); Signature who = Constants.Signature; repo.Commit("Initial commit", who, who); - repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Unaltered); + Assert.Equal(FileStatus.Unaltered, repo.Index.RetrieveStatus(oldName)); const string newName = "being.frakking.polite.txt"; repo.Index.Move(oldName, newName); - repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Removed); - repo.Index.RetrieveStatus(newName).ShouldEqual(FileStatus.Added); + Assert.Equal(FileStatus.Removed, repo.Index.RetrieveStatus(oldName)); + Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(newName)); - repo.Index.Count.ShouldEqual(1); - repo.Index[newName].Id.Sha.ShouldEqual((expectedHash)); + Assert.Equal(1, repo.Index.Count); + Assert.Equal(expectedHash, repo.Index[newName].Id.Sha); who = who.TimeShift(TimeSpan.FromMinutes(5)); Commit commit = repo.Commit("Fix file name", who, who); - repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Nonexistent); - repo.Index.RetrieveStatus(newName).ShouldEqual(FileStatus.Unaltered); + Assert.Equal(FileStatus.Nonexistent, repo.Index.RetrieveStatus(oldName)); + Assert.Equal(FileStatus.Unaltered, repo.Index.RetrieveStatus(newName)); - commit.Tree[newName].Target.Id.Sha.ShouldEqual(expectedHash); + Assert.Equal(expectedHash, commit.Tree[newName].Target.Id.Sha); } } @@ -412,13 +412,13 @@ public void CanMoveAnExistingFileOverANonExistingFile(string sourcePath, FileSta TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath); using (var repo = new Repository(path.RepositoryPath)) { - repo.Index.RetrieveStatus(sourcePath).ShouldEqual(sourceStatus); - repo.Index.RetrieveStatus(destPath).ShouldEqual(destStatus); + Assert.Equal(sourceStatus, repo.Index.RetrieveStatus(sourcePath)); + Assert.Equal(destStatus, repo.Index.RetrieveStatus(destPath)); repo.Index.Move(sourcePath, destPath); - repo.Index.RetrieveStatus(sourcePath).ShouldEqual(sourcePostStatus); - repo.Index.RetrieveStatus(destPath).ShouldEqual(destPostStatus); + Assert.Equal(sourcePostStatus, repo.Index.RetrieveStatus(sourcePath)); + Assert.Equal(destPostStatus, repo.Index.RetrieveStatus(destPath)); } } @@ -452,7 +452,7 @@ private static void InvalidMoveUseCases(string sourcePath, FileStatus sourceStat { using (var repo = new Repository(StandardTestRepoPath)) { - repo.Index.RetrieveStatus(sourcePath).ShouldEqual(sourceStatus); + Assert.Equal(sourceStatus, repo.Index.RetrieveStatus(sourcePath)); foreach (var destPath in destPaths) { @@ -474,14 +474,14 @@ public void CanRemoveAFile(string filename, FileStatus initialStatus, bool shoul string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename); - File.Exists(fullpath).ShouldEqual(shouldInitiallyExist); - repo.Index.RetrieveStatus(filename).ShouldEqual(initialStatus); + Assert.Equal(shouldInitiallyExist, File.Exists(fullpath)); + Assert.Equal(initialStatus, repo.Index.RetrieveStatus(filename)); repo.Index.Remove(filename); - repo.Index.Count.ShouldEqual(count - 1); - File.Exists(fullpath).ShouldBeFalse(); - repo.Index.RetrieveStatus(filename).ShouldEqual(finalStatus); + Assert.Equal(count - 1, repo.Index.Count); + Assert.False(File.Exists(fullpath)); + Assert.Equal(finalStatus, repo.Index.RetrieveStatus(filename)); } } @@ -541,10 +541,10 @@ public void PathsOfIndexEntriesAreExpressedInNativeFormat() IndexEntry ie = index[relFilePath]; // Make sure the IndexEntry has been found - ie.ShouldNotBeNull(); - + Assert.NotNull(ie); + // Make sure that the (native) relFilePath and ie.Path are equal - ie.Path.ShouldEqual(relFilePath); + Assert.Equal(relFilePath, ie.Path); } } } diff --git a/LibGit2Sharp.Tests/LazyFixture.cs b/LibGit2Sharp.Tests/LazyFixture.cs index a79ec43ce..b3125e501 100644 --- a/LibGit2Sharp.Tests/LazyFixture.cs +++ b/LibGit2Sharp.Tests/LazyFixture.cs @@ -11,7 +11,7 @@ public class LazyFixture public void CanReturnTheValue() { var lazy = new Lazy(() => 2); - lazy.Value.ShouldEqual(2); + Assert.Equal(2, lazy.Value); } [Fact] @@ -22,7 +22,7 @@ public void IsLazilyEvaluated() var evaluator = new Func(() => ++i); var lazy = new Lazy(evaluator); - lazy.Value.ShouldEqual(1); + Assert.Equal(1, lazy.Value); } [Fact] @@ -34,8 +34,8 @@ public void IsEvaluatedOnlyOnce() var lazy = new Lazy(evaluator); - lazy.Value.ShouldEqual(1); - lazy.Value.ShouldEqual(1); + Assert.Equal(1, lazy.Value); + Assert.Equal(1, lazy.Value); } } } diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index 13ffcb6b7..7020fd388 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -32,6 +32,16 @@ 4 + + true + full + false + bin\Leaks\ + TRACE;DEBUG;NET35 + prompt + 4 + + @@ -46,6 +56,7 @@ + @@ -67,7 +78,6 @@ - diff --git a/LibGit2Sharp.Tests/NoteFixture.cs b/LibGit2Sharp.Tests/NoteFixture.cs new file mode 100644 index 000000000..79233fcb3 --- /dev/null +++ b/LibGit2Sharp.Tests/NoteFixture.cs @@ -0,0 +1,243 @@ +using System; +using System.Linq; +using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; +using LibGit2Sharp.Tests.TestHelpers; +using Xunit; + +namespace LibGit2Sharp.Tests +{ + public class NoteFixture : BaseFixture + { + private static readonly Signature signatureNullToken = new Signature("nulltoken", "emeric.fermas@gmail.com", DateTimeOffset.UtcNow); + private static readonly Signature signatureYorah = new Signature("yorah", "yoram.harmelin@gmail.com", Epoch.ToDateTimeOffset(1300557894, 60)); + + [Fact] + public void RetrievingNotesFromANonExistingGitObjectYieldsNoResult() + { + using (var repo = new Repository(BareTestRepoPath)) + { + var notes = repo.Notes[ObjectId.Zero]; + + Assert.Equal(0, notes.Count()); + } + } + + [Fact] + public void RetrievingNotesFromAGitObjectWhichHasNoNoteYieldsNoResult() + { + using (var repo = new Repository(BareTestRepoPath)) + { + var notes = repo.Notes[new ObjectId("4c062a6361ae6959e06292c1fa5e2822d9c96345")]; + + Assert.Equal(0, notes.Count()); + } + } + + /* + * $ git show 4a202 --show-notes=* + * commit 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 + * Author: Scott Chacon + * Date: Mon May 24 10:19:04 2010 -0700 + * + * a third commit + * + * Notes: + * Just Note, don't you understand? + * + * Notes (answer): + * Nope + * + * Notes (answer2): + * Not Nope, Note! + */ + [Fact] + public void CanRetrieveNotesFromAGitObject() + { + var expectedMessages = new [] { "Just Note, don't you understand?\n", "Nope\n", "Not Nope, Note!\n" }; + + using (var repo = new Repository(BareTestRepoPath)) + { + var notes = repo.Notes[new ObjectId("4a202b346bb0fb0db7eff3cffeb3c70babbd2045")]; + + Assert.NotNull(notes); + Assert.Equal(3, notes.Count()); + Assert.Equal(expectedMessages, notes.Select(n => n.Message)); + } + } + + [Fact] + public void CanGetListOfNotesNamespaces() + { + var expectedNamespaces = new[] { "commits", "answer", "answer2" }; + + using (var repo = new Repository(BareTestRepoPath)) + { + Assert.Equal(expectedNamespaces, repo.Notes.Namespaces); + Assert.Equal(repo.Notes.DefaultNamespace, repo.Notes.Namespaces.First()); + } + } + + /* + * $ git show 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 --show-notes=* + * commit 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 + * Author: Scott Chacon + * Date: Mon May 24 10:19:04 2010 -0700 + * + * a third commit + * + * Notes: + * Just Note, don't you understand? + * + * Notes (answer): + * Nope + * + * Notes (answer2): + * Not Nope, Note! + */ + [Fact] + public void CanAccessNotesFromACommit() + { + var expectedNamespaces = new[] { "Just Note, don't you understand?\n", "Nope\n", "Not Nope, Note!\n" }; + + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); + using (var repo = new Repository(path.RepositoryPath)) + { + var commit = repo.Lookup("4a202b346bb0fb0db7eff3cffeb3c70babbd2045"); + + Assert.Equal(expectedNamespaces, commit.Notes.Select(n => n.Message)); + + // Make sure that Commit.Notes is not refreshed automatically + repo.Notes.Create(commit.Id, "I'm batman!\n", signatureNullToken, signatureYorah, "batmobile"); + + Assert.Equal(expectedNamespaces, commit.Notes.Select(n => n.Message)); + } + } + + [Fact] + public void CanCreateANoteOnAGitObject() + { + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); + using (var repo = new Repository(path.RepositoryPath)) + { + var commit = repo.Lookup("9fd738e8f7967c078dceed8190330fc8648ee56a"); + var note = repo.Notes.Create(commit.Id, "I'm batman!\n", signatureNullToken, signatureYorah, "batmobile"); + + var newNote = commit.Notes.Single(); + Assert.Equal(note, newNote); + + Assert.Equal("I'm batman!\n", newNote.Message); + Assert.Equal("batmobile", newNote.Namespace); + } + } + + [Fact] + public void CreatingANoteWhichAlreadyExistsOverwritesThePreviousNote() + { + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); + using (var repo = new Repository(path.RepositoryPath)) + { + var commit = repo.Lookup("5b5b025afb0b4c913b4c338a42934a3863bf3644"); + Assert.NotNull(commit.Notes.FirstOrDefault(x => x.Namespace == "answer")); + + repo.Notes.Create(commit.Id, "I'm batman!\n", signatureNullToken, signatureYorah, "answer"); + var note = repo.Notes[new ObjectId("5b5b025afb0b4c913b4c338a42934a3863bf3644")].FirstOrDefault(x => x.Namespace == "answer"); + + Assert.NotNull(note); + + Assert.Equal("I'm batman!\n", note.Message); + Assert.Equal("answer", note.Namespace); + } + } + + [Fact] + public void CanCompareTwoUniqueNotes() + { + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); + using (var repo = new Repository(path.RepositoryPath)) + { + var commit = repo.Lookup("9fd738e8f7967c078dceed8190330fc8648ee56a"); + + var firstNote = repo.Notes.Create(commit.Id, "I'm batman!\n", signatureNullToken, signatureYorah, "batmobile"); + var secondNote = repo.Notes.Create(commit.Id, "I'm batman!\n", signatureNullToken, signatureYorah, "batmobile"); + Assert.Equal(firstNote, secondNote); + + var firstNoteWithAnotherNamespace = repo.Notes.Create(commit.Id, "I'm batman!\n", signatureNullToken, signatureYorah, "batmobile2"); + Assert.NotEqual(firstNote, firstNoteWithAnotherNamespace); + + var firstNoteWithAnotherMessage = repo.Notes.Create(commit.Id, "I'm ironman!\n", signatureNullToken, signatureYorah, "batmobile"); + Assert.NotEqual(firstNote, firstNoteWithAnotherMessage); + + var anotherCommit = repo.Lookup("c47800c7266a2be04c571c04d5a6614691ea99bd"); + var firstNoteOnAnotherCommit = repo.Notes.Create(anotherCommit.Id, "I'm batman!\n", signatureNullToken, signatureYorah, "batmobile"); + Assert.NotEqual(firstNote, firstNoteOnAnotherCommit); + } + } + + /* + * $ git log 8496071c1b46c854b31185ea97743be6a8774479 + * commit 8496071c1b46c854b31185ea97743be6a8774479 + * Author: Scott Chacon + * Date: Sat May 8 16:13:06 2010 -0700 + * + * testing + * + * Notes: + * Hi, I'm Note. + */ + [Fact] + public void CanRemoveANoteFromAGitObject() + { + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); + using (var repo = new Repository(path.RepositoryPath)) + { + var commit = repo.Lookup("8496071c1b46c854b31185ea97743be6a8774479"); + var notes = repo.Notes[commit.Id]; + + Assert.NotEmpty(notes); + + repo.Notes.Delete(commit.Id, signatureNullToken, signatureYorah, repo.Notes.DefaultNamespace); + + Assert.Empty(notes); + } + } + + /* + * $ git show 5b5b025afb0b4c913b4c338a42934a3863bf3644 --notes=answer + * commit 5b5b025afb0b4c913b4c338a42934a3863bf3644 + * Author: Scott Chacon + * Date: Tue May 11 13:38:42 2010 -0700 + * + * another commit + * + * Notes (answer): + * Not what? + */ + [Fact] + public void RemovingANonExistingNoteDoesntThrow() + { + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); + using (var repo = new Repository(path.RepositoryPath)) + { + var commit = repo.Lookup("5b5b025afb0b4c913b4c338a42934a3863bf3644"); + + repo.Notes.Delete(commit.Id, signatureNullToken, signatureYorah, "answer2"); + } + } + + [Fact] + public void CanRetrieveTheListOfNotesForAGivenNamespace() + { + var expectedNotes = new[] { new Tuple("1a550e416326cdb4a8e127a04dd69d7a01b11cf4", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"), + new Tuple("272a41cf2b22e57f2bc5bf6ef37b63568cd837e4", "8496071c1b46c854b31185ea97743be6a8774479") }; + + using (var repo = new Repository(BareTestRepoPath)) + { + Assert.Equal(expectedNotes, repo.Notes["commits"].Select(n => new Tuple(n.BlobId.Sha, n.TargetObjectId.Sha)).ToArray()); + + Assert.Equal("commits", repo.Notes.DefaultNamespace); + Assert.Equal(expectedNotes, repo.Notes.Select(n => new Tuple(n.BlobId.Sha, n.TargetObjectId.Sha)).ToArray()); + } + } + } +} diff --git a/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs b/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs index 531b63e70..f60c4b756 100644 --- a/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs +++ b/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs @@ -139,7 +139,7 @@ public void RemovingANonExistingEntryFromATreeDefinitionHasNoSideEffect() Tree tree = repo.ObjectDatabase.CreateTree(td); Assert.NotNull(tree); - tree.ShouldEqual(head); + Assert.Equal(head, tree); } } diff --git a/LibGit2Sharp.Tests/ObjectIdFixture.cs b/LibGit2Sharp.Tests/ObjectIdFixture.cs index 065e11198..a78647e2a 100644 --- a/LibGit2Sharp.Tests/ObjectIdFixture.cs +++ b/LibGit2Sharp.Tests/ObjectIdFixture.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using LibGit2Sharp.Tests.TestHelpers; using Xunit; using Xunit.Extensions; @@ -10,6 +11,8 @@ public class ObjectIdFixture private const string validSha1 = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"; private const string validSha2 = "de08fe4884650f067bd5703b6a59a8b3b3c99a09"; + private static byte[] bytes = new byte[] { 206, 8, 254, 72, 132, 101, 15, 6, 123, 213, 112, 59, 106, 89, 168, 179, 179, 201, 154, 9 }; + [Theory] [InlineData("Dummy", typeof(ArgumentException))] [InlineData("", typeof(ArgumentException))] @@ -24,12 +27,10 @@ public void PreventsFromBuildingWithAnInvalidSha(string malformedSha, Type expec [Fact] public void CanConvertOidToSha() { - var bytes = new byte[] { 206, 8, 254, 72, 132, 101, 15, 6, 123, 213, 112, 59, 106, 89, 168, 179, 179, 201, 154, 9 }; - var id = new ObjectId(bytes); - id.Sha.ShouldEqual(validSha1); - id.ToString().ShouldEqual(validSha1); + Assert.Equal(validSha1, id.Sha); + Assert.Equal(validSha1, id.ToString()); } [Fact] @@ -37,15 +38,15 @@ public void CanConvertShaToOid() { var id = new ObjectId(validSha1); - id.RawId.ShouldEqual(new byte[] { 206, 8, 254, 72, 132, 101, 15, 6, 123, 213, 112, 59, 106, 89, 168, 179, 179, 201, 154, 9 }); + Assert.Equal(bytes, id.RawId); } [Fact] public void CreatingObjectIdWithWrongNumberOfBytesThrows() { - var bytes = new byte[] { 206, 8, 254, 72, 132, 101, 15, 6, 123, 213, 112, 59, 106, 89, 168, 179, 179, 201, 154 }; + var invalidBytes = new byte[] { 206, 8, 254, 72, 132, 101, 15, 6, 123, 213, 112, 59, 106, 89, 168, 179, 179, 201, 154 }; - Assert.Throws(() => { new ObjectId(bytes); }); + Assert.Throws(() => { new ObjectId(invalidBytes); }); } [Fact] @@ -54,11 +55,11 @@ public void DifferentObjectIdsAreEqual() var a = new ObjectId(validSha1); var b = new ObjectId(validSha2); - (a.Equals(b)).ShouldBeFalse(); - (b.Equals(a)).ShouldBeFalse(); + Assert.False((a.Equals(b))); + Assert.False((b.Equals(a))); - (a == b).ShouldBeFalse(); - (a != b).ShouldBeTrue(); + Assert.False((a == b)); + Assert.True((a != b)); } [Fact] @@ -67,7 +68,7 @@ public void DifferentObjectIdsDoesNotHaveSameHashCode() var a = new ObjectId(validSha1); var b = new ObjectId(validSha2); - a.GetHashCode().ShouldNotEqual(b.GetHashCode()); + Assert.NotEqual(b.GetHashCode(), a.GetHashCode()); } [Fact] @@ -76,11 +77,11 @@ public void SimilarObjectIdsAreEqual() var a = new ObjectId(validSha1); var b = new ObjectId(validSha1); - (a.Equals(b)).ShouldBeTrue(); - (b.Equals(a)).ShouldBeTrue(); + Assert.True((a.Equals(b))); + Assert.True((b.Equals(a))); - (a == b).ShouldBeTrue(); - (a != b).ShouldBeFalse(); + Assert.True((a == b)); + Assert.False((a != b)); } [Fact] @@ -89,7 +90,7 @@ public void SimilarObjectIdsHaveSameHashCode() var a = new ObjectId(validSha1); var b = new ObjectId(validSha1); - a.GetHashCode().ShouldEqual(b.GetHashCode()); + Assert.Equal(b.GetHashCode(), a.GetHashCode()); } [Theory] @@ -107,17 +108,17 @@ public void TryParse(string maybeSha, bool isValidSha) { ObjectId parsedObjectId; bool result = ObjectId.TryParse(maybeSha, out parsedObjectId); - result.ShouldEqual(isValidSha); + Assert.Equal(isValidSha, result); if (!result) { return; } - parsedObjectId.ShouldNotBeNull(); - parsedObjectId.Sha.ShouldEqual(maybeSha); - maybeSha.StartsWith(parsedObjectId.ToString(3)).ShouldBeTrue(); - parsedObjectId.ToString(42).ShouldEqual(maybeSha); + Assert.NotNull(parsedObjectId); + Assert.Equal(maybeSha, parsedObjectId.Sha); + Assert.True(maybeSha.StartsWith(parsedObjectId.ToString(3))); + Assert.Equal(maybeSha, parsedObjectId.ToString(42)); } } } diff --git a/LibGit2Sharp.Tests/ReferenceFixture.cs b/LibGit2Sharp.Tests/ReferenceFixture.cs index d32da5485..a7ad0fb49 100644 --- a/LibGit2Sharp.Tests/ReferenceFixture.cs +++ b/LibGit2Sharp.Tests/ReferenceFixture.cs @@ -11,7 +11,8 @@ public class ReferenceFixture : BaseFixture private readonly string[] expectedRefs = new[] { "refs/heads/br2", "refs/heads/deadbeef", "refs/heads/master", "refs/heads/packed", "refs/heads/packed-test", - "refs/heads/test", "refs/tags/e90810b", "refs/tags/lw", "refs/tags/point_to_blob", "refs/tags/test", + "refs/heads/test", "refs/notes/answer", "refs/notes/answer2", "refs/notes/commits", "refs/tags/e90810b", + "refs/tags/lw", "refs/tags/point_to_blob", "refs/tags/test" }; [Fact] @@ -23,12 +24,12 @@ public void CanCreateADirectReference() using (var repo = new Repository(path.RepositoryPath)) { var newRef = (DirectReference)repo.Refs.Create(name, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); - newRef.ShouldNotBeNull(); - newRef.CanonicalName.ShouldEqual(name); - newRef.Target.ShouldNotBeNull(); - newRef.Target.Sha.ShouldEqual("be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); - newRef.TargetIdentifier.ShouldEqual(newRef.Target.Sha); - repo.Refs[name].ShouldNotBeNull(); + Assert.NotNull(newRef); + Assert.Equal(name, newRef.CanonicalName); + Assert.NotNull(newRef.Target); + Assert.Equal("be3563ae3f795b2b4353bcce3a527ad0a4f7f644", newRef.Target.Sha); + Assert.Equal(newRef.Target.Sha, newRef.TargetIdentifier); + Assert.NotNull(repo.Refs[name]); } } @@ -42,12 +43,12 @@ public void CanCreateASymbolicReference() using (var repo = new Repository(path.RepositoryPath)) { var newRef = (SymbolicReference)repo.Refs.Create(name, target); - newRef.ShouldNotBeNull(); - newRef.CanonicalName.ShouldEqual(name); - newRef.Target.CanonicalName.ShouldEqual(target); - newRef.TargetIdentifier.ShouldEqual(newRef.Target.CanonicalName); - newRef.ResolveToDirectReference().Target.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345"); - repo.Refs[name].ShouldNotBeNull(); + Assert.NotNull(newRef); + Assert.Equal(name, newRef.CanonicalName); + Assert.Equal(target, newRef.Target.CanonicalName); + Assert.Equal(newRef.Target.CanonicalName, newRef.TargetIdentifier); + Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", newRef.ResolveToDirectReference().Target.Sha); + Assert.NotNull(repo.Refs[name]); } } @@ -81,11 +82,11 @@ public void CanCreateAndOverwriteADirectReference() using (var repo = new Repository(path.RepositoryPath)) { var newRef = (DirectReference)repo.Refs.Create(name, target, true); - newRef.ShouldNotBeNull(); - newRef.CanonicalName.ShouldEqual(name); - newRef.Target.ShouldNotBeNull(); - newRef.Target.Sha.ShouldEqual(target); - ((DirectReference)repo.Refs[name]).Target.Sha.ShouldEqual(target); + Assert.NotNull(newRef); + Assert.Equal(name, newRef.CanonicalName); + Assert.NotNull(newRef.Target); + Assert.Equal(target, newRef.Target.Sha); + Assert.Equal(target, ((DirectReference)repo.Refs[name]).Target.Sha); } } @@ -99,11 +100,11 @@ public void CanCreateAndOverwriteASymbolicReference() using (var repo = new Repository(path.RepositoryPath)) { var newRef = (SymbolicReference)repo.Refs.Create(name, target, true); - newRef.ShouldNotBeNull(); - newRef.CanonicalName.ShouldEqual(name); - newRef.Target.ShouldNotBeNull(); - newRef.ResolveToDirectReference().Target.Sha.ShouldEqual("a4a7dce85cf63874e984719f4fdd239f5145052f"); - ((SymbolicReference)repo.Refs["HEAD"]).Target.CanonicalName.ShouldEqual(target); + Assert.NotNull(newRef); + Assert.Equal(name, newRef.CanonicalName); + Assert.NotNull(newRef.Target); + Assert.Equal("a4a7dce85cf63874e984719f4fdd239f5145052f", newRef.ResolveToDirectReference().Target.Sha); + Assert.Equal(target, ((SymbolicReference)repo.Refs["HEAD"]).Target.CanonicalName); } } @@ -162,7 +163,7 @@ public void ADeletedReferenceCannotBeLookedUp() const string refName = "refs/heads/test"; repo.Refs.Delete(refName); - repo.Refs[refName].ShouldBeNull(); + Assert.Null(repo.Refs[refName]); } } @@ -175,14 +176,14 @@ public void DeletingAReferenceDecreasesTheRefsCount() const string refName = "refs/heads/test"; List refs = repo.Refs.Select(r => r.CanonicalName).ToList(); - refs.Contains(refName).ShouldBeTrue(); + Assert.True(refs.Contains(refName)); repo.Refs.Delete(refName); List refs2 = repo.Refs.Select(r => r.CanonicalName).ToList(); - refs2.Contains(refName).ShouldBeFalse(); + Assert.False(refs2.Contains(refName)); - refs2.Count.ShouldEqual(refs.Count - 1); + Assert.Equal(refs.Count - 1, refs2.Count); } } @@ -214,7 +215,7 @@ public void CanListAllReferencesEvenCorruptedOnes() Assert.Equal(expectedRefs, repo.Refs.Select(r => r.CanonicalName).ToArray()); - repo.Refs.Count().ShouldEqual(10); + Assert.Equal(13, repo.Refs.Count()); } } @@ -224,18 +225,18 @@ public void CanResolveHeadByName() using (var repo = new Repository(BareTestRepoPath)) { var head = (SymbolicReference)repo.Refs["HEAD"]; - head.ShouldNotBeNull(); - head.CanonicalName.ShouldEqual("HEAD"); - head.Target.ShouldNotBeNull(); - head.Target.CanonicalName.ShouldEqual("refs/heads/master"); - head.ResolveToDirectReference().Target.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345"); + Assert.NotNull(head); + Assert.Equal("HEAD", head.CanonicalName); + Assert.NotNull(head.Target); + Assert.Equal("refs/heads/master", head.Target.CanonicalName); + Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", head.ResolveToDirectReference().Target.Sha); Assert.IsType(((DirectReference)head.Target).Target); Branch head2 = repo.Head; - head2.CanonicalName.ShouldEqual("refs/heads/master"); - head2.Tip.ShouldNotBeNull(); + Assert.Equal("refs/heads/master", head2.CanonicalName); + Assert.NotNull(head2.Tip); - head2.Tip.ShouldEqual(head.ResolveToDirectReference().Target); + Assert.Equal(head.ResolveToDirectReference().Target, head2.Tip); } } @@ -245,10 +246,10 @@ public void CanResolveReferenceToALightweightTag() using (var repo = new Repository(BareTestRepoPath)) { var lwTag = (DirectReference)repo.Refs["refs/tags/lw"]; - lwTag.ShouldNotBeNull(); - lwTag.CanonicalName.ShouldEqual("refs/tags/lw"); - lwTag.Target.ShouldNotBeNull(); - lwTag.Target.Sha.ShouldEqual("e90810b8df3e80c413d903f631643c716887138d"); + Assert.NotNull(lwTag); + Assert.Equal("refs/tags/lw", lwTag.CanonicalName); + Assert.NotNull(lwTag.Target); + Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", lwTag.Target.Sha); Assert.IsType(lwTag.Target); } } @@ -259,10 +260,10 @@ public void CanResolveReferenceToAnAnnotatedTag() using (var repo = new Repository(BareTestRepoPath)) { var annTag = (DirectReference)repo.Refs["refs/tags/test"]; - annTag.ShouldNotBeNull(); - annTag.CanonicalName.ShouldEqual("refs/tags/test"); - annTag.Target.ShouldNotBeNull(); - annTag.Target.Sha.ShouldEqual("b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); + Assert.NotNull(annTag); + Assert.Equal("refs/tags/test", annTag.CanonicalName); + Assert.NotNull(annTag.Target); + Assert.Equal("b25fa35b38051e4ae45d4222e795f9df2e43f1d1", annTag.Target.Sha); Assert.IsType(annTag.Target); } } @@ -273,10 +274,10 @@ public void CanResolveRefsByName() using (var repo = new Repository(BareTestRepoPath)) { var master = (DirectReference)repo.Refs["refs/heads/master"]; - master.ShouldNotBeNull(); - master.CanonicalName.ShouldEqual("refs/heads/master"); - master.Target.ShouldNotBeNull(); - master.Target.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345"); + Assert.NotNull(master); + Assert.Equal("refs/heads/master", master.CanonicalName); + Assert.NotNull(master.Target); + Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", master.Target.Sha); Assert.IsType(master.Target); } } @@ -308,14 +309,14 @@ public void CanUpdateTargetOnReference() { string sha = repo.Refs["refs/heads/test"].ResolveToDirectReference().Target.Sha; Reference master = repo.Refs[masterRef]; - master.ResolveToDirectReference().Target.Sha.ShouldNotEqual(sha); + Assert.NotEqual(sha, master.ResolveToDirectReference().Target.Sha); Reference updated = repo.Refs.UpdateTarget(masterRef, sha); master = repo.Refs[masterRef]; - master.ShouldEqual(updated); + Assert.Equal(updated, master); - master.ResolveToDirectReference().Target.Sha.ShouldEqual(sha); + Assert.Equal(sha, master.ResolveToDirectReference().Target.Sha); } } @@ -327,12 +328,12 @@ public void CanUpdateTargetOnSymbolicReference() using (var repo = new Repository(path.RepositoryPath)) { var newRef = (SymbolicReference)repo.Refs.Create(name, "refs/heads/master"); - newRef.ShouldNotBeNull(); + Assert.NotNull(newRef); repo.Refs.UpdateTarget(newRef.CanonicalName, "refs/heads/test"); newRef = (SymbolicReference)repo.Refs[newRef.CanonicalName]; - newRef.ResolveToDirectReference().Target.ShouldEqual(repo.Refs["refs/heads/test"].ResolveToDirectReference().Target); + Assert.Equal(repo.Refs["refs/heads/test"].ResolveToDirectReference().Target, newRef.ResolveToDirectReference().Target); repo.Refs.Delete(newRef.CanonicalName); } @@ -347,12 +348,12 @@ public void CanUpdateHeadWithEitherAnOidOrACanonicalHeadReference() Branch test = repo.Branches["test"]; Reference direct = repo.Refs.UpdateTarget("HEAD", test.Tip.Sha); - (direct is DirectReference).ShouldBeTrue(); - direct.ShouldEqual(repo.Refs["HEAD"]); + Assert.True((direct is DirectReference)); + Assert.Equal(repo.Refs["HEAD"], direct); Reference symref = repo.Refs.UpdateTarget("HEAD", test.CanonicalName); - (symref is SymbolicReference).ShouldBeTrue(); - symref.ShouldEqual(repo.Refs["HEAD"]); + Assert.True((symref is SymbolicReference)); + Assert.Equal(repo.Refs["HEAD"], symref); } } @@ -365,7 +366,7 @@ public void UpdatingADirectRefWithSymbolFails() using (var repo = new Repository(path.RepositoryPath)) { var newRef = (SymbolicReference)repo.Refs.Create(name, "refs/heads/master"); - newRef.ShouldNotBeNull(); + Assert.NotNull(newRef); Assert.Throws( () => repo.Refs.UpdateTarget(newRef.CanonicalName, repo.Refs["refs/heads/test"].ResolveToDirectReference().Target.Sha)); @@ -405,8 +406,8 @@ public void CanMoveAReferenceToADeeperReferenceHierarchy() const string newName = "refs/tags/test/deep"; Reference moved = repo.Refs.Move("refs/tags/test", newName); - moved.ShouldNotBeNull(); - moved.CanonicalName.ShouldEqual(newName); + Assert.NotNull(moved); + Assert.Equal(newName, moved.CanonicalName); } } @@ -421,8 +422,8 @@ public void CanMoveAReferenceToAUpperReferenceHierarchy() repo.Refs.Create(oldName, repo.Head.CanonicalName); Reference moved = repo.Refs.Move(oldName, newName); - moved.ShouldNotBeNull(); - moved.CanonicalName.ShouldEqual(newName); + Assert.NotNull(moved); + Assert.Equal(newName, moved.CanonicalName); } } @@ -435,8 +436,8 @@ public void CanMoveAReferenceToADifferentReferenceHierarchy() const string newName = "refs/atic/tagtest"; Reference moved = repo.Refs.Move("refs/tags/test", newName); - moved.ShouldNotBeNull(); - moved.CanonicalName.ShouldEqual(newName); + Assert.NotNull(moved); + Assert.Equal(newName, moved.CanonicalName); } } @@ -460,8 +461,8 @@ public void CanMoveAndOverWriteAExistingReference() Reference moved = repo.Refs.Move(oldName, newName, true); - repo.Refs[oldName].ShouldBeNull(); - repo.Refs[moved.CanonicalName].ShouldNotBeNull(); + Assert.Null(repo.Refs[oldName]); + Assert.NotNull(repo.Refs[moved.CanonicalName]); } } @@ -484,15 +485,15 @@ public void MovingAReferenceDoesNotDecreaseTheRefsCount() const string newName = "refs/atic/tagtest"; List refs = repo.Refs.Select(r => r.CanonicalName).ToList(); - refs.Contains(oldName).ShouldBeTrue(); + Assert.True(refs.Contains(oldName)); repo.Refs.Move(oldName, newName); List refs2 = repo.Refs.Select(r => r.CanonicalName).ToList(); - refs2.Contains(oldName).ShouldBeFalse(); - refs2.Contains(newName).ShouldBeTrue(); + Assert.False(refs2.Contains(oldName)); + Assert.True(refs2.Contains(newName)); - refs.Count.ShouldEqual(refs2.Count); + Assert.Equal(refs2.Count, refs.Count); } } @@ -508,7 +509,7 @@ public void CanLookupAMovedReference() Reference moved = repo.Refs.Move(oldName, newName); Reference lookedUp = repo.Refs[newName]; - moved.ShouldEqual(lookedUp); + Assert.Equal(lookedUp, moved); } } } diff --git a/LibGit2Sharp.Tests/RemoteFixture.cs b/LibGit2Sharp.Tests/RemoteFixture.cs index ca721c902..663d0626b 100644 --- a/LibGit2Sharp.Tests/RemoteFixture.cs +++ b/LibGit2Sharp.Tests/RemoteFixture.cs @@ -11,9 +11,9 @@ public void CanGetRemoteOrigin() using (var repo = new Repository(StandardTestRepoPath)) { Remote origin = repo.Remotes["origin"]; - origin.ShouldNotBeNull(); - origin.Name.ShouldEqual("origin"); - origin.Url.ShouldEqual("c:/GitHub/libgit2sharp/Resources/testrepo.git"); + Assert.NotNull(origin); + Assert.Equal("origin", origin.Name); + Assert.Equal("c:/GitHub/libgit2sharp/Resources/testrepo.git", origin.Url); } } @@ -22,7 +22,7 @@ public void GettingRemoteThatDoesntExistReturnsNull() { using (var repo = new Repository(StandardTestRepoPath)) { - repo.Remotes["test"].ShouldBeNull(); + Assert.Null(repo.Remotes["test"]); } } @@ -35,11 +35,11 @@ public void CanEnumerateTheRemotes() foreach (Remote remote in repo.Remotes) { - remote.ShouldNotBeNull(); + Assert.NotNull(remote); count++; } - count.ShouldEqual(1); + Assert.Equal(1, count); } } @@ -51,18 +51,18 @@ public void CanCheckEqualityOfRemote() using (var repo = new Repository(path.RepositoryPath)) { Remote oneOrigin = repo.Remotes["origin"]; - oneOrigin.ShouldNotBeNull(); + Assert.NotNull(oneOrigin); Remote otherOrigin = repo.Remotes["origin"]; - otherOrigin.ShouldEqual(oneOrigin); + Assert.Equal(oneOrigin, otherOrigin); Remote createdRemote = repo.Remotes.Create("origin2", oneOrigin.Url); Remote loadedRemote = repo.Remotes["origin2"]; - loadedRemote.ShouldNotBeNull(); - loadedRemote.ShouldEqual(createdRemote); + Assert.NotNull(loadedRemote); + Assert.Equal(createdRemote, loadedRemote); - loadedRemote.ShouldNotEqual(oneOrigin); + Assert.NotEqual(oneOrigin, loadedRemote); } } } diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs index 4cc90edb3..e3fed6ceb 100644 --- a/LibGit2Sharp.Tests/RepositoryFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryFixture.cs @@ -17,13 +17,13 @@ public void CanCreateBareRepo() using (var repo = Repository.Init(scd.DirectoryPath, true)) { string dir = repo.Info.Path; - Path.IsPathRooted(dir).ShouldBeTrue(); - Directory.Exists(dir).ShouldBeTrue(); + Assert.True(Path.IsPathRooted(dir)); + Assert.True(Directory.Exists(dir)); CheckGitConfigFile(dir); - repo.Info.WorkingDirectory.ShouldBeNull(); - repo.Info.Path.ShouldEqual(scd.RootedDirectoryPath + Path.DirectorySeparatorChar); - repo.Info.IsBare.ShouldBeTrue(); + Assert.Null(repo.Info.WorkingDirectory); + Assert.Equal(scd.RootedDirectoryPath + Path.DirectorySeparatorChar, repo.Info.Path); + Assert.True(repo.Info.IsBare); AssertInitializedRepository(repo); } @@ -46,13 +46,13 @@ public void CanCreateStandardRepo() using (var repo = Repository.Init(scd.DirectoryPath)) { string dir = repo.Info.Path; - Path.IsPathRooted(dir).ShouldBeTrue(); - Directory.Exists(dir).ShouldBeTrue(); + Assert.True(Path.IsPathRooted(dir)); + Assert.True(Directory.Exists(dir)); CheckGitConfigFile(dir); - repo.Info.WorkingDirectory.ShouldNotBeNull(); - repo.Info.Path.ShouldEqual(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar)); - repo.Info.IsBare.ShouldBeFalse(); + Assert.NotNull(repo.Info.WorkingDirectory); + Assert.Equal(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar), repo.Info.Path); + Assert.False(repo.Info.IsBare); AssertIsHidden(repo.Info.Path); @@ -63,17 +63,17 @@ public void CanCreateStandardRepo() private static void CheckGitConfigFile(string dir) { string configFilePath = Path.Combine(dir, "config"); - File.Exists(configFilePath).ShouldBeTrue(); + Assert.True(File.Exists(configFilePath)); string contents = File.ReadAllText(configFilePath); - contents.IndexOf("repositoryformatversion = 0", StringComparison.Ordinal).ShouldNotEqual(-1); + Assert.NotEqual(-1, contents.IndexOf("repositoryformatversion = 0", StringComparison.Ordinal)); } private static void AssertIsHidden(string repoPath) { FileAttributes attribs = File.GetAttributes(repoPath); - (attribs & FileAttributes.Hidden).ShouldEqual(FileAttributes.Hidden); + Assert.Equal(FileAttributes.Hidden, (attribs & FileAttributes.Hidden)); } [Fact] @@ -84,7 +84,7 @@ public void CanReinitARepository() using (Repository repository = Repository.Init(scd.DirectoryPath)) using (Repository repository2 = Repository.Init(scd.DirectoryPath)) { - repository.Info.Path.ShouldEqual(repository2.Info.Path); + Assert.Equal(repository2.Info.Path, repository.Info.Path); } } @@ -97,30 +97,30 @@ public void CreatingRepoWithBadParamsThrows() private static void AssertInitializedRepository(Repository repo) { - repo.Info.Path.ShouldNotBeNull(); - repo.Info.IsEmpty.ShouldBeTrue(); - repo.Info.IsHeadDetached.ShouldBeFalse(); + Assert.NotNull(repo.Info.Path); + Assert.True(repo.Info.IsEmpty); + Assert.False(repo.Info.IsHeadDetached); Reference headRef = repo.Refs["HEAD"]; - headRef.ShouldNotBeNull(); - headRef.TargetIdentifier.ShouldEqual("refs/heads/master"); - headRef.ResolveToDirectReference().ShouldBeNull(); - - repo.Head.ShouldNotBeNull(); - repo.Head.IsCurrentRepositoryHead.ShouldBeTrue(); - repo.Head.CanonicalName.ShouldEqual(headRef.TargetIdentifier); - repo.Head.Tip.ShouldBeNull(); - - repo.Commits.Count().ShouldEqual(0); - repo.Commits.QueryBy(new Filter { Since = repo.Head }).Count().ShouldEqual(0); - repo.Commits.QueryBy(new Filter { Since = "HEAD" }).Count().ShouldEqual(0); - repo.Commits.QueryBy(new Filter { Since = "refs/heads/master" }).Count().ShouldEqual(0); - - repo.Head["subdir/I-do-not-exist"].ShouldBeNull(); - - repo.Branches.Count().ShouldEqual(0); - repo.Refs.Count().ShouldEqual(0); - repo.Tags.Count().ShouldEqual(0); + Assert.NotNull(headRef); + Assert.Equal("refs/heads/master", headRef.TargetIdentifier); + Assert.Null(headRef.ResolveToDirectReference()); + + Assert.NotNull(repo.Head); + Assert.True(repo.Head.IsCurrentRepositoryHead); + Assert.Equal(headRef.TargetIdentifier, repo.Head.CanonicalName); + Assert.Null(repo.Head.Tip); + + Assert.Equal(0, repo.Commits.Count()); + Assert.Equal(0, repo.Commits.QueryBy(new Filter { Since = repo.Head }).Count()); + Assert.Equal(0, repo.Commits.QueryBy(new Filter { Since = "HEAD" }).Count()); + Assert.Equal(0, repo.Commits.QueryBy(new Filter { Since = "refs/heads/master" }).Count()); + + Assert.Null(repo.Head["subdir/I-do-not-exist"]); + + Assert.Equal(0, repo.Branches.Count()); + Assert.Equal(0, repo.Refs.Count()); + Assert.Equal(0, repo.Tags.Count()); } [Fact] @@ -129,8 +129,8 @@ public void CanOpenBareRepositoryThroughAFullPathToTheGitDir() string path = Path.GetFullPath(BareTestRepoPath); using (var repo = new Repository(path)) { - repo.ShouldNotBeNull(); - repo.Info.WorkingDirectory.ShouldBeNull(); + Assert.NotNull(repo); + Assert.Null(repo.Info.WorkingDirectory); } } @@ -139,8 +139,8 @@ public void CanOpenStandardRepositoryThroughAWorkingDirPath() { using (var repo = new Repository(StandardTestRepoWorkingDirPath)) { - repo.ShouldNotBeNull(); - repo.Info.WorkingDirectory.ShouldNotBeNull(); + Assert.NotNull(repo); + Assert.NotNull(repo.Info.WorkingDirectory); } } @@ -149,8 +149,8 @@ public void OpeningStandardRepositoryThroughTheGitDirGuessesTheWorkingDirPath() { using (var repo = new Repository(StandardTestRepoPath)) { - repo.ShouldNotBeNull(); - repo.Info.WorkingDirectory.ShouldNotBeNull(); + Assert.NotNull(repo); + Assert.NotNull(repo.Info.WorkingDirectory); } } @@ -159,11 +159,11 @@ public void CanOpenRepository() { using (var repo = new Repository(BareTestRepoPath)) { - repo.Info.Path.ShouldNotBeNull(); - repo.Info.WorkingDirectory.ShouldBeNull(); - repo.Info.IsBare.ShouldBeTrue(); - repo.Info.IsEmpty.ShouldBeFalse(); - repo.Info.IsHeadDetached.ShouldBeFalse(); + Assert.NotNull(repo.Info.Path); + Assert.Null(repo.Info.WorkingDirectory); + Assert.True(repo.Info.IsBare); + Assert.False(repo.Info.IsEmpty); + Assert.False(repo.Info.IsHeadDetached); } } @@ -186,7 +186,7 @@ public void CanLookupACommitByTheNameOfABranch() using (var repo = new Repository(BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/heads/master"); - gitObject.ShouldNotBeNull(); + Assert.NotNull(gitObject); Assert.IsType(gitObject); } } @@ -197,7 +197,7 @@ public void CanLookupACommitByTheNameOfALightweightTag() using (var repo = new Repository(BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/tags/lw"); - gitObject.ShouldNotBeNull(); + Assert.NotNull(gitObject); Assert.IsType(gitObject); } } @@ -208,7 +208,7 @@ public void CanLookupATagAnnotationByTheNameOfAnAnnotatedTag() using (var repo = new Repository(BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/tags/e90810b"); - gitObject.ShouldNotBeNull(); + Assert.NotNull(gitObject); Assert.IsType(gitObject); } } @@ -218,9 +218,9 @@ public void CanLookupObjects() { using (var repo = new Repository(BareTestRepoPath)) { - repo.Lookup(commitSha).ShouldNotBeNull(); - repo.Lookup(commitSha).ShouldNotBeNull(); - repo.Lookup(commitSha).ShouldNotBeNull(); + Assert.NotNull(repo.Lookup(commitSha)); + Assert.NotNull(repo.Lookup(commitSha)); + Assert.NotNull(repo.Lookup(commitSha)); } } @@ -231,8 +231,8 @@ public void CanLookupSameObjectTwiceAndTheyAreEqual() { GitObject commit = repo.Lookup(commitSha); GitObject commit2 = repo.Lookup(commitSha); - commit.Equals(commit2).ShouldBeTrue(); - commit.GetHashCode().ShouldEqual(commit2.GetHashCode()); + Assert.True(commit.Equals(commit2)); + Assert.Equal(commit2.GetHashCode(), commit.GetHashCode()); } } @@ -241,8 +241,8 @@ public void LookupObjectByWrongShaReturnsNull() { using (var repo = new Repository(BareTestRepoPath)) { - repo.Lookup(Constants.UnknownSha).ShouldBeNull(); - repo.Lookup(Constants.UnknownSha).ShouldBeNull(); + Assert.Null(repo.Lookup(Constants.UnknownSha)); + Assert.Null(repo.Lookup(Constants.UnknownSha)); } } @@ -251,9 +251,9 @@ public void LookupObjectByWrongTypeReturnsNull() { using (var repo = new Repository(BareTestRepoPath)) { - repo.Lookup(commitSha).ShouldNotBeNull(); - repo.Lookup(commitSha).ShouldNotBeNull(); - repo.Lookup(commitSha).ShouldBeNull(); + Assert.NotNull(repo.Lookup(commitSha)); + Assert.NotNull(repo.Lookup(commitSha)); + Assert.Null(repo.Lookup(commitSha)); } } @@ -262,8 +262,8 @@ public void LookupObjectByUnknownReferenceNameReturnsNull() { using (var repo = new Repository(BareTestRepoPath)) { - repo.Lookup("refs/heads/chopped/off").ShouldBeNull(); - repo.Lookup(Constants.UnknownSha).ShouldBeNull(); + Assert.Null(repo.Lookup("refs/heads/chopped/off")); + Assert.Null(repo.Lookup(Constants.UnknownSha)); } } @@ -285,13 +285,13 @@ public void CanLookupWhithShortIdentifers() Signature author = Constants.Signature; Commit commit = repo.Commit("Initial commit", author, author); - commit.Sha.ShouldEqual(expectedSha); + Assert.Equal(expectedSha, commit.Sha); GitObject lookedUp1 = repo.Lookup(expectedSha); - lookedUp1.ShouldEqual(commit); + Assert.Equal(commit, lookedUp1); GitObject lookedUp2 = repo.Lookup(expectedAbbrevSha); - lookedUp2.ShouldEqual(commit); + Assert.Equal(commit, lookedUp2); } } @@ -313,35 +313,35 @@ public void LookingUpWithBadParamsThrows() public void CanDiscoverABareRepoGivenTheRepoPath() { string path = Repository.Discover(BareTestRepoPath); - path.ShouldEqual(Path.GetFullPath(BareTestRepoPath + Path.DirectorySeparatorChar)); + Assert.Equal(Path.GetFullPath(BareTestRepoPath + Path.DirectorySeparatorChar), path); } [Fact] public void CanDiscoverABareRepoGivenASubDirectoryOfTheRepoPath() { string path = Repository.Discover(Path.Combine(BareTestRepoPath, "objects/4a")); - path.ShouldEqual(Path.GetFullPath(BareTestRepoPath + Path.DirectorySeparatorChar)); + Assert.Equal(Path.GetFullPath(BareTestRepoPath + Path.DirectorySeparatorChar), path); } [Fact] public void CanDiscoverAStandardRepoGivenTheRepoPath() { string path = Repository.Discover(StandardTestRepoPath); - path.ShouldEqual(Path.GetFullPath(StandardTestRepoPath + Path.DirectorySeparatorChar)); + Assert.Equal(Path.GetFullPath(StandardTestRepoPath + Path.DirectorySeparatorChar), path); } [Fact] public void CanDiscoverAStandardRepoGivenASubDirectoryOfTheRepoPath() { string path = Repository.Discover(Path.Combine(StandardTestRepoPath, "objects/4a")); - path.ShouldEqual(Path.GetFullPath(StandardTestRepoPath + Path.DirectorySeparatorChar)); + Assert.Equal(Path.GetFullPath(StandardTestRepoPath + Path.DirectorySeparatorChar), path); } [Fact] public void CanDiscoverAStandardRepoGivenTheWorkingDirPath() { string path = Repository.Discover(StandardTestRepoWorkingDirPath); - path.ShouldEqual(Path.GetFullPath(StandardTestRepoPath + Path.DirectorySeparatorChar)); + Assert.Equal(Path.GetFullPath(StandardTestRepoPath + Path.DirectorySeparatorChar), path); } [Fact] @@ -352,7 +352,7 @@ public void DiscoverReturnsNullWhenNoRepoCanBeFound() SelfCleaningDirectory scd = BuildSelfCleaningDirectory(path + suffix); Directory.CreateDirectory(scd.RootedDirectoryPath); - Repository.Discover(scd.RootedDirectoryPath).ShouldBeNull(); + Assert.Null(Repository.Discover(scd.RootedDirectoryPath)); File.Delete(path); } diff --git a/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs b/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs index c7938475d..1093f09bc 100644 --- a/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; using LibGit2Sharp.Tests.TestHelpers; using Xunit; @@ -101,16 +102,6 @@ public void OpeningABareRepoWithoutProvidingBothWorkDirAndIndexThrows() Assert.Throws(() => repo = new Repository(BareTestRepoPath, new RepositoryOptions { WorkingDirectoryPath = newWorkdir })); } - [Fact] - public void OpeningARepoWithAnEmptyRepositoryOptionsThrows() - { - var options = new RepositoryOptions(); - Repository repo; - - Assert.Throws(() => repo = new Repository(BareTestRepoPath, options)); - Assert.Throws(() => repo = new Repository(StandardTestRepoPath, options)); - } - [Fact] public void CanSneakAdditionalCommitsIntoAStandardRepoWithoutAlteringTheWorkdirOrTheIndex() { @@ -150,5 +141,38 @@ private string MeanwhileInAnotherDimensionAnEvilMastermindIsAtWork(string workin return sneakyRepo.Commit("Tadaaaa!", DummySignature, DummySignature).Sha; } } + + [Fact] + public void CanProvideDifferentConfigurationFilesToARepository() + { + string globalLocation = Path.Combine(newWorkdir, "my-global-config"); + string systemLocation = Path.Combine(newWorkdir, "my-system-config"); + + const string name = "Adam 'aroben' Roben"; + const string email = "adam@github.com"; + + StringBuilder sb = new StringBuilder() + .AppendLine("[user]") + .AppendFormat("name = {0}{1}", name, Environment.NewLine) + .AppendFormat("email = {0}{1}", email, Environment.NewLine); + + File.WriteAllText(globalLocation, sb.ToString()); + + var options = new RepositoryOptions { + GlobalConfigurationLocation = globalLocation, + SystemConfigurationLocation = systemLocation, + }; + + using (var repo = new Repository(BareTestRepoPath, options)) + { + Assert.True(repo.Config.HasGlobalConfig); + Assert.Equal(name, repo.Config.Get("user", "name", null)); + Assert.Equal(email, repo.Config.Get("user", "email", null)); + + repo.Config.Set("help.link", "https://twitter.com/xpaulbettsx/status/205761932626636800", ConfigurationLevel.System); + } + + AssertValueInConfigFile(systemLocation, "xpaulbettsx"); + } } } diff --git a/LibGit2Sharp.Tests/ResetFixture.cs b/LibGit2Sharp.Tests/ResetFixture.cs index 6c2355d2e..dada45bdf 100644 --- a/LibGit2Sharp.Tests/ResetFixture.cs +++ b/LibGit2Sharp.Tests/ResetFixture.cs @@ -30,7 +30,7 @@ public void SoftResetToTheHeadOfARepositoryDoesNotChangeTheTargetOfTheHead() repo.Reset(ResetOptions.Soft, oldHead.CanonicalName); - repo.Head.ShouldEqual(oldHead); + Assert.Equal(oldHead, repo.Head); } } @@ -43,7 +43,7 @@ public void SoftResetSetsTheHeadToTheDereferencedCommitOfAChainedTag() { Tag tag = repo.Tags["test"]; repo.Reset(ResetOptions.Soft, tag.CanonicalName); - repo.Head.Tip.Sha.ShouldEqual("e90810b8df3e80c413d903f631643c716887138d"); + Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", repo.Head.Tip.Sha); } } @@ -85,25 +85,25 @@ private void AssertSoftReset(Func branchIdentifierRetriever, boo string branchIdentifier = branchIdentifierRetriever(branch); repo.Checkout(branchIdentifier); - repo.Info.IsHeadDetached.ShouldEqual(shouldHeadBeDetached); + Assert.Equal(shouldHeadBeDetached, repo.Info.IsHeadDetached); string expectedHeadName = expectedHeadNameRetriever(branch); - repo.Head.Name.ShouldEqual(expectedHeadName); - repo.Head.Tip.Sha.ShouldEqual(branch.Tip.Sha); + Assert.Equal(expectedHeadName, repo.Head.Name); + Assert.Equal(branch.Tip.Sha, repo.Head.Tip.Sha); /* Reset --soft the Head to a tag through its canonical name */ repo.Reset(ResetOptions.Soft, tag.CanonicalName); - repo.Head.Name.ShouldEqual(expectedHeadName); - repo.Head.Tip.Id.ShouldEqual(tag.Target.Id); + Assert.Equal(expectedHeadName, repo.Head.Name); + Assert.Equal(tag.Target.Id, repo.Head.Tip.Id); - repo.Index.RetrieveStatus("a.txt").ShouldEqual(FileStatus.Staged); + Assert.Equal(FileStatus.Staged, repo.Index.RetrieveStatus("a.txt")); /* Reset --soft the Head to a commit through its sha */ repo.Reset(ResetOptions.Soft, branch.Tip.Sha); - repo.Head.Name.ShouldEqual(expectedHeadName); - repo.Head.Tip.Sha.ShouldEqual(branch.Tip.Sha); + Assert.Equal(expectedHeadName, repo.Head.Name); + Assert.Equal(branch.Tip.Sha, repo.Head.Tip.Sha); - repo.Index.RetrieveStatus("a.txt").ShouldEqual(FileStatus.Unaltered); + Assert.Equal(FileStatus.Unaltered, repo.Index.RetrieveStatus("a.txt")); } } @@ -124,7 +124,7 @@ private static void FeedTheRepository(Repository repo) repo.Checkout("mybranch"); - repo.Index.RetrieveStatus().IsDirty.ShouldBeFalse(); + Assert.False(repo.Index.RetrieveStatus().IsDirty); } [Fact] @@ -140,7 +140,7 @@ public void MixedResetRefreshesTheIndex() repo.Reset(ResetOptions.Mixed, tag.CanonicalName); - repo.Index.RetrieveStatus("a.txt").ShouldEqual(FileStatus.Modified); + Assert.Equal(FileStatus.Modified, repo.Index.RetrieveStatus("a.txt")); } } diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/1a/550e416326cdb4a8e127a04dd69d7a01b11cf4 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/1a/550e416326cdb4a8e127a04dd69d7a01b11cf4 new file mode 100644 index 000000000..94df9cb37 Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/1a/550e416326cdb4a8e127a04dd69d7a01b11cf4 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/27/2a41cf2b22e57f2bc5bf6ef37b63568cd837e4 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/27/2a41cf2b22e57f2bc5bf6ef37b63568cd837e4 new file mode 100644 index 000000000..5263d60d6 Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/27/2a41cf2b22e57f2bc5bf6ef37b63568cd837e4 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/30/415905d74c9ae026fda6b5f51e9ed64dd0e1a4 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/30/415905d74c9ae026fda6b5f51e9ed64dd0e1a4 new file mode 100644 index 000000000..f72580590 Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/30/415905d74c9ae026fda6b5f51e9ed64dd0e1a4 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/3d/fd6fd25c22ef62c1657a305f05fdcdc74d5987 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/3d/fd6fd25c22ef62c1657a305f05fdcdc74d5987 new file mode 100644 index 000000000..b38937905 --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/3d/fd6fd25c22ef62c1657a305f05fdcdc74d5987 @@ -0,0 +1,2 @@ +xKj1)zEi} wPK-π52=YY{k؏9Dbk6ѓb8E\Vlz!&;d"bKȚD$_ƥ8T~H+\~kM~Ϲ/֒#'DucOyB*E + NN M \ No newline at end of file diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/09de11e16118bc4ed32bd18e2991a77f94bf62 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/09de11e16118bc4ed32bd18e2991a77f94bf62 new file mode 100644 index 000000000..23e60ec53 --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/09de11e16118bc4ed32bd18e2991a77f94bf62 @@ -0,0 +1,3 @@ +xA + Eˢhi .rE/Ճ}Ni]ja4ѻ28aĆ-Ji6ڒps3E+u,ɭ[sjMQ +RI)mi3W>}> \ No newline at end of file diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/240004a63a598f5d2d876c78d7eb53756610f8 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/240004a63a598f5d2d876c78d7eb53756610f8 new file mode 100644 index 000000000..fda78f33c Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/240004a63a598f5d2d876c78d7eb53756610f8 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/d5d1881ebcb31173b1f89ef7c2ea955c3b1a3b b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/d5d1881ebcb31173b1f89ef7c2ea955c3b1a3b new file mode 100644 index 000000000..b1a9e22a7 --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/44/d5d1881ebcb31173b1f89ef7c2ea955c3b1a3b @@ -0,0 +1,2 @@ +xM + ˢƨB)=A0bk}(okhzߏ[~.M,NO|_"*p}鶾Le'ߢN \ No newline at end of file diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/53/2740a931e8f9140b26b93cb0a2d81f6943741a b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/53/2740a931e8f9140b26b93cb0a2d81f6943741a new file mode 100644 index 000000000..9f81dbc95 --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/53/2740a931e8f9140b26b93cb0a2d81f6943741a @@ -0,0 +1,3 @@ +xM + ˢ5&B)=A0j,.rE/Ճ{!UPFja3Yk4cc) WpDI +H"N>V+qb8*AG._$~lmI=P贃TRF+bni_J%M \ No newline at end of file diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/59/cf25c488378bfc297518e2ba9786973ef15c38 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/59/cf25c488378bfc297518e2ba9786973ef15c38 new file mode 100644 index 000000000..c872ad82a Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/59/cf25c488378bfc297518e2ba9786973ef15c38 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/71/89b38caf261863c4440e15e6e71057535b6375 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/71/89b38caf261863c4440e15e6e71057535b6375 new file mode 100644 index 000000000..8d847b595 Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/71/89b38caf261863c4440e15e6e71057535b6375 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/90/2c60b555b350b1b02964a7fe7db04d6b96be2f b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/90/2c60b555b350b1b02964a7fe7db04d6b96be2f new file mode 100644 index 000000000..a887ce06f Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/90/2c60b555b350b1b02964a7fe7db04d6b96be2f differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/97/a2da25da3bd50163b13f5bd91260ba3cbb8210 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/97/a2da25da3bd50163b13f5bd91260ba3cbb8210 new file mode 100644 index 000000000..077813b68 Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/97/a2da25da3bd50163b13f5bd91260ba3cbb8210 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/9b/0bea0f1e4eafeaf2068675b44837e5c0a04d41 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/9b/0bea0f1e4eafeaf2068675b44837e5c0a04d41 new file mode 100644 index 000000000..2668898ed Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/9b/0bea0f1e4eafeaf2068675b44837e5c0a04d41 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/9f/1ee9b7f3b5cd0226f2d68c694d7fc4b96a0087 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/9f/1ee9b7f3b5cd0226f2d68c694d7fc4b96a0087 new file mode 100644 index 000000000..278998312 Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/9f/1ee9b7f3b5cd0226f2d68c694d7fc4b96a0087 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/bb/65291c2f528ddcd2a3c950582449c57d196dec b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/bb/65291c2f528ddcd2a3c950582449c57d196dec new file mode 100644 index 000000000..6aba094bb --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/bb/65291c2f528ddcd2a3c950582449c57d196dec @@ -0,0 +1,4 @@ +xK +1D]s! L@xtDb\x{GQRym`;*=.E4ab +(3&Tekђ;:RHD}Gd'E +Ri7rPr_iw hk} [ib yڎk]M \ No newline at end of file diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/c9/e302a78b5660de810c6a0161c8592ceed1ea5c b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/c9/e302a78b5660de810c6a0161c8592ceed1ea5c new file mode 100644 index 000000000..1f441acef Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/c9/e302a78b5660de810c6a0161c8592ceed1ea5c differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/ce/0e5486643e1c66b1cca956dac54a2b204ed11b b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/ce/0e5486643e1c66b1cca956dac54a2b204ed11b new file mode 100644 index 000000000..d20a20929 Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/ce/0e5486643e1c66b1cca956dac54a2b204ed11b differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/e2/a6a7e5efdfdc0e27d13faa32ee9685b2e16576 b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/e2/a6a7e5efdfdc0e27d13faa32ee9685b2e16576 new file mode 100644 index 000000000..7ec37bb47 Binary files /dev/null and b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/e2/a6a7e5efdfdc0e27d13faa32ee9685b2e16576 differ diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/answer b/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/answer new file mode 100644 index 000000000..9ff31ff12 --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/answer @@ -0,0 +1 @@ +532740a931e8f9140b26b93cb0a2d81f6943741a diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/answer2 b/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/answer2 new file mode 100644 index 000000000..1a081453e --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/answer2 @@ -0,0 +1 @@ +44d5d1881ebcb31173b1f89ef7c2ea955c3b1a3b diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/commits b/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/commits new file mode 100644 index 000000000..360770884 --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/refs/notes/commits @@ -0,0 +1 @@ +bb65291c2f528ddcd2a3c950582449c57d196dec diff --git a/LibGit2Sharp.Tests/StatusFixture.cs b/LibGit2Sharp.Tests/StatusFixture.cs index f2194ee2f..114c59f4d 100644 --- a/LibGit2Sharp.Tests/StatusFixture.cs +++ b/LibGit2Sharp.Tests/StatusFixture.cs @@ -14,7 +14,7 @@ public void CanRetrieveTheStatusOfAFile() using (var repo = new Repository(StandardTestRepoPath)) { FileStatus status = repo.Index.RetrieveStatus("new_tracked_file.txt"); - status.ShouldEqual(FileStatus.Added); + Assert.Equal(FileStatus.Added, status); } } @@ -38,36 +38,36 @@ public void CanRetrieveTheStatusOfTheWholeWorkingDirectory() RepositoryStatus status = repo.Index.RetrieveStatus(); IndexEntry indexEntry = repo.Index[file]; - indexEntry.State.ShouldEqual(FileStatus.Staged); + Assert.Equal(FileStatus.Staged, indexEntry.State); - status.ShouldNotBeNull(); - status.Count().ShouldEqual(6); - status.IsDirty.ShouldBeTrue(); + Assert.NotNull(status); + Assert.Equal(6, status.Count()); + Assert.True(status.IsDirty); - status.Untracked.Single().ShouldEqual("new_untracked_file.txt"); - status.Modified.Single().ShouldEqual("modified_unstaged_file.txt"); - status.Missing.Single().ShouldEqual("deleted_unstaged_file.txt"); - status.Added.Single().ShouldEqual("new_tracked_file.txt"); - status.Staged.Single().ShouldEqual(file); - status.Removed.Single().ShouldEqual("deleted_staged_file.txt"); + Assert.Equal("new_untracked_file.txt", status.Untracked.Single()); + Assert.Equal("modified_unstaged_file.txt", status.Modified.Single()); + Assert.Equal("deleted_unstaged_file.txt", status.Missing.Single()); + Assert.Equal("new_tracked_file.txt", status.Added.Single()); + Assert.Equal(file, status.Staged.Single()); + Assert.Equal("deleted_staged_file.txt", status.Removed.Single()); File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, file), "Tclem's favorite commit message: boom"); - indexEntry.State.ShouldEqual(FileStatus.Staged | FileStatus.Modified); + Assert.Equal(FileStatus.Staged | FileStatus.Modified, indexEntry.State); RepositoryStatus status2 = repo.Index.RetrieveStatus(); - status2.ShouldNotBeNull(); - status2.Count().ShouldEqual(6); - status2.IsDirty.ShouldBeTrue(); + Assert.NotNull(status2); + Assert.Equal(6, status2.Count()); + Assert.True(status2.IsDirty); - status2.Untracked.Single().ShouldEqual("new_untracked_file.txt"); + Assert.Equal("new_untracked_file.txt", status2.Untracked.Single()); Assert.Equal(new[] { file, "modified_unstaged_file.txt" }, status2.Modified); - status2.Missing.Single().ShouldEqual("deleted_unstaged_file.txt"); - status2.Added.Single().ShouldEqual("new_tracked_file.txt"); - status2.Staged.Single().ShouldEqual(file); - status2.Removed.Single().ShouldEqual("deleted_staged_file.txt"); + Assert.Equal("deleted_unstaged_file.txt", status2.Missing.Single()); + Assert.Equal("new_tracked_file.txt", status2.Added.Single()); + Assert.Equal(file, status2.Staged.Single()); + Assert.Equal("deleted_staged_file.txt", status2.Removed.Single()); } } @@ -79,16 +79,16 @@ public void CanRetrieveTheStatusOfANewRepository() using (Repository repo = Repository.Init(scd.DirectoryPath)) { RepositoryStatus status = repo.Index.RetrieveStatus(); - status.ShouldNotBeNull(); - status.Count().ShouldEqual(0); - status.IsDirty.ShouldBeFalse(); - - status.Untracked.Count().ShouldEqual(0); - status.Modified.Count().ShouldEqual(0); - status.Missing.Count().ShouldEqual(0); - status.Added.Count().ShouldEqual(0); - status.Staged.Count().ShouldEqual(0); - status.Removed.Count().ShouldEqual(0); + Assert.NotNull(status); + Assert.Equal(0, status.Count()); + Assert.False(status.IsDirty); + + Assert.Equal(0, status.Untracked.Count()); + Assert.Equal(0, status.Modified.Count()); + Assert.Equal(0, status.Missing.Count()); + Assert.Equal(0, status.Added.Count()); + Assert.Equal(0, status.Staged.Count()); + Assert.Equal(0, status.Removed.Count()); } } @@ -117,13 +117,13 @@ public void RetrievingTheStatusOfARepositoryReturnNativeFilePaths() // Get the repository status RepositoryStatus repoStatus = repo.Index.RetrieveStatus(); - repoStatus.Count().ShouldEqual(1); + Assert.Equal(1, repoStatus.Count()); StatusEntry statusEntry = repoStatus.Single(); string expectedPath = string.Format("{0}{1}{2}", directoryName, Path.DirectorySeparatorChar, fileName); - statusEntry.FilePath.ShouldEqual(expectedPath); + Assert.Equal(expectedPath, statusEntry.FilePath); - repoStatus.Added.Single().ShouldEqual(statusEntry.FilePath); + Assert.Equal(statusEntry.FilePath, repoStatus.Added.Single()); } } @@ -145,9 +145,9 @@ public void RetrievingTheStatusOfAnEmptyRepositoryHonorsTheGitIgnoreDirectives() File.WriteAllText(gitignorePath, "*.txt" + Environment.NewLine); RepositoryStatus newStatus = repo.Index.RetrieveStatus(); - newStatus.Untracked.Single().ShouldEqual(".gitignore"); + Assert.Equal(".gitignore", newStatus.Untracked.Single()); - repo.Index.RetrieveStatus(relativePath).ShouldEqual(FileStatus.Ignored); + Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus(relativePath)); Assert.Equal(new[] { relativePath }, newStatus.Ignored); } } @@ -236,9 +236,9 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives() */ RepositoryStatus newStatus = repo.Index.RetrieveStatus(); - newStatus.Untracked.Single().ShouldEqual(".gitignore"); + Assert.Equal(".gitignore", newStatus.Untracked.Single()); - repo.Index.RetrieveStatus(relativePath).ShouldEqual(FileStatus.Ignored); + Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus(relativePath)); Assert.Equal(new[] { relativePath, "new_untracked_file.txt" }, newStatus.Ignored); } } diff --git a/LibGit2Sharp.Tests/TagFixture.cs b/LibGit2Sharp.Tests/TagFixture.cs index 53cf7917c..96d013734 100644 --- a/LibGit2Sharp.Tests/TagFixture.cs +++ b/LibGit2Sharp.Tests/TagFixture.cs @@ -24,8 +24,8 @@ public void CanCreateALightWeightTagFromSha() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.Tags.Create("i_am_lightweight", commitE90810BSha); - newTag.ShouldNotBeNull(); - newTag.IsAnnotated.ShouldBeFalse(); + Assert.NotNull(newTag); + Assert.False(newTag.IsAnnotated); } } @@ -36,8 +36,8 @@ public void CanCreateALightWeightTagFromAbbreviatedSha() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.Tags.Create("i_am_lightweight", commitE90810BSha.Substring(0, 17)); - newTag.ShouldNotBeNull(); - newTag.IsAnnotated.ShouldBeFalse(); + Assert.NotNull(newTag); + Assert.False(newTag.IsAnnotated); } } @@ -48,8 +48,8 @@ public void CanCreateALightweightTagFromABranchName() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.Tags.Create("i_am_lightweight", "refs/heads/master"); - newTag.IsAnnotated.ShouldBeFalse(); - newTag.ShouldNotBeNull(); + Assert.False(newTag.IsAnnotated); + Assert.NotNull(newTag); } } @@ -60,8 +60,8 @@ public void CanCreateAndOverwriteALightweightTag() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.Tags.Create("e90810b", commitE90810BSha, true); - newTag.ShouldNotBeNull(); - newTag.IsAnnotated.ShouldBeFalse(); + Assert.NotNull(newTag); + Assert.False(newTag.IsAnnotated); } } @@ -73,18 +73,18 @@ public void CanCreateATagWithNameContainingASlash() { const string lwTagName = "i/am/deep"; Tag lwTag = repo.Tags.Create(lwTagName, commitE90810BSha); - lwTag.ShouldNotBeNull(); - lwTag.IsAnnotated.ShouldBeFalse(); - lwTag.Target.Sha.ShouldEqual(commitE90810BSha); - lwTag.Name.ShouldEqual(lwTagName); + Assert.NotNull(lwTag); + Assert.False(lwTag.IsAnnotated); + Assert.Equal(commitE90810BSha, lwTag.Target.Sha); + Assert.Equal(lwTagName, lwTag.Name); const string anTagName = lwTagName + "_as_well"; Tag anTag = repo.Tags.Create(anTagName, commitE90810BSha, signatureNtk, "a nice message"); - anTag.ShouldNotBeNull(); - anTag.IsAnnotated.ShouldBeTrue(); - anTag.Target.Sha.ShouldEqual(commitE90810BSha); - anTag.Annotation.Target.ShouldEqual(anTag.Target); - anTag.Name.ShouldEqual(anTagName); + Assert.NotNull(anTag); + Assert.True(anTag.IsAnnotated); + Assert.Equal(commitE90810BSha, anTag.Target.Sha); + Assert.Equal(anTag.Target, anTag.Annotation.Target); + Assert.Equal(anTagName, anTag.Name); } } @@ -107,8 +107,8 @@ public void CanCreateAnAnnotatedTagFromABranchName() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.Tags.Create("unit_test", "refs/heads/master", signatureTim, "a new tag"); - newTag.IsAnnotated.ShouldBeTrue(); - newTag.ShouldNotBeNull(); + Assert.True(newTag.IsAnnotated); + Assert.NotNull(newTag); } } @@ -119,8 +119,8 @@ public void CanCreateAnAnnotatedTagFromSha() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.Tags.Create("unit_test", tagTestSha, signatureTim, "a new tag"); - newTag.ShouldNotBeNull(); - newTag.IsAnnotated.ShouldBeTrue(); + Assert.NotNull(newTag); + Assert.True(newTag.IsAnnotated); } } @@ -132,9 +132,9 @@ public void CanCreateAnAnnotatedTagWithAnEmptyMessage() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.ApplyTag("empty-annotated-tag", signatureNtk, string.Empty); - newTag.ShouldNotBeNull(); - newTag.IsAnnotated.ShouldBeTrue(); - newTag.Annotation.Message.ShouldEqual(string.Empty); + Assert.NotNull(newTag); + Assert.True(newTag.IsAnnotated); + Assert.Equal(string.Empty, newTag.Annotation.Message); } } @@ -145,8 +145,8 @@ public void CanCreateAndOverwriteAnAnnotatedTag() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.Tags.Create("e90810b", tagTestSha, signatureTim, "a new tag", true); - newTag.ShouldNotBeNull(); - newTag.IsAnnotated.ShouldBeTrue(); + Assert.NotNull(newTag); + Assert.True(newTag.IsAnnotated); } } @@ -160,10 +160,10 @@ public void CreatingAnAnnotatedTagIsDeterministic() using (var repo = new Repository(path.RepositoryPath)) { Tag newTag = repo.Tags.Create(tagName, commitE90810BSha, signatureNtk, tagMessage); - newTag.Target.Sha.ShouldEqual(commitE90810BSha); - newTag.IsAnnotated.ShouldBeTrue(); - newTag.Annotation.Sha.ShouldEqual("26623eee75440d63e10dcb752b88a0004c914161"); - newTag.Annotation.Target.Sha.ShouldEqual(commitE90810BSha); + Assert.Equal(commitE90810BSha, newTag.Target.Sha); + Assert.True(newTag.IsAnnotated); + Assert.Equal("26623eee75440d63e10dcb752b88a0004c914161", newTag.Annotation.Sha); + Assert.Equal(commitE90810BSha, newTag.Annotation.Target.Sha); } } @@ -228,12 +228,12 @@ public void CanCreateATagForImplicitHead() using (var repo = new Repository(path.RepositoryPath)) { Tag tag = repo.ApplyTag("mytag"); - tag.ShouldNotBeNull(); + Assert.NotNull(tag); - tag.Target.Id.ShouldEqual(repo.Head.Tip.Id); + Assert.Equal(repo.Head.Tip.Id, tag.Target.Id); Tag retrievedTag = repo.Tags[tag.CanonicalName]; - tag.ShouldEqual(retrievedTag); + Assert.Equal(retrievedTag, tag); } } @@ -272,12 +272,12 @@ public void CanCreateATagUsingHead() using (var repo = new Repository(path.RepositoryPath)) { Tag tag = repo.ApplyTag("mytag", "HEAD"); - tag.ShouldNotBeNull(); + Assert.NotNull(tag); - tag.Target.Id.ShouldEqual(repo.Head.Tip.Id); + Assert.Equal(repo.Head.Tip.Id, tag.Target.Id); Tag retrievedTag = repo.Tags[tag.CanonicalName]; - tag.ShouldEqual(retrievedTag); + Assert.Equal(retrievedTag, tag); } } @@ -291,12 +291,12 @@ public void CanCreateATagPointingToATree() Tree tree = headCommit.Tree; Tag tag = repo.ApplyTag("tree-tag", tree.Sha); - tag.ShouldNotBeNull(); - tag.IsAnnotated.ShouldBeFalse(); - tag.Target.Id.ShouldEqual(tree.Id); + Assert.NotNull(tag); + Assert.False(tag.IsAnnotated); + Assert.Equal(tree.Id, tag.Target.Id); - repo.Lookup(tag.Target.Id).ShouldEqual(tree); - repo.Tags[tag.Name].ShouldEqual(tag); + Assert.Equal(tree, repo.Lookup(tag.Target.Id)); + Assert.Equal(tag, repo.Tags[tag.Name]); } } @@ -310,12 +310,12 @@ public void CanCreateATagPointingToABlob() Blob blob = headCommit.Tree.Blobs.First(); Tag tag = repo.ApplyTag("blob-tag", blob.Sha); - tag.ShouldNotBeNull(); - tag.IsAnnotated.ShouldBeFalse(); - tag.Target.Id.ShouldEqual(blob.Id); + Assert.NotNull(tag); + Assert.False(tag.IsAnnotated); + Assert.Equal(blob.Id, tag.Target.Id); - repo.Lookup(tag.Target.Id).ShouldEqual(blob); - repo.Tags[tag.Name].ShouldEqual(tag); + Assert.Equal(blob, repo.Lookup(tag.Target.Id)); + Assert.Equal(tag, repo.Tags[tag.Name]); } } @@ -329,13 +329,13 @@ public void CreatingALightweightTagPointingToATagAnnotationGeneratesAnAnnotatedT TagAnnotation annotation = annotatedTag.Annotation; Tag tag = repo.ApplyTag("lightweight-tag", annotation.Sha); - tag.ShouldNotBeNull(); - tag.IsAnnotated.ShouldBeTrue(); - tag.Target.Id.ShouldEqual(annotation.Target.Id); - tag.Annotation.ShouldEqual(annotation); + Assert.NotNull(tag); + Assert.True(tag.IsAnnotated); + Assert.Equal(annotation.Target.Id, tag.Target.Id); + Assert.Equal(annotation, tag.Annotation); - repo.Lookup(tag.Annotation.Id).ShouldEqual(annotation); - repo.Tags[tag.Name].ShouldEqual(tag); + Assert.Equal(annotation, repo.Lookup(tag.Annotation.Id)); + Assert.Equal(tag, repo.Tags[tag.Name]); } } @@ -349,12 +349,12 @@ public void CanCreateAnAnnotatedTagPointingToATagAnnotation() TagAnnotation annotation = annotatedTag.Annotation; Tag tag = repo.ApplyTag("annotatedtag-tag", annotation.Sha, signatureNtk, "A new annotation"); - tag.ShouldNotBeNull(); - tag.IsAnnotated.ShouldBeTrue(); - tag.Annotation.Target.Id.ShouldEqual(annotation.Id); - tag.Annotation.ShouldNotEqual(annotation); + Assert.NotNull(tag); + Assert.True(tag.IsAnnotated); + Assert.Equal(annotation.Id, tag.Annotation.Target.Id); + Assert.NotEqual(annotation, tag.Annotation); - repo.Tags[tag.Name].ShouldEqual(tag); + Assert.Equal(tag, repo.Tags[tag.Name]); } } @@ -477,7 +477,7 @@ public void ADeletedTagCannotBeLookedUp() const string tagName = "e90810b"; repo.Tags.Delete(tagName); - repo.Tags[tagName].ShouldBeNull(); + Assert.Null(repo.Tags[tagName]); } } @@ -490,14 +490,14 @@ public void DeletingATagDecreasesTheTagsCount() const string tagName = "e90810b"; List tags = repo.Tags.Select(r => r.Name).ToList(); - tags.Contains(tagName).ShouldBeTrue(); + Assert.True(tags.Contains(tagName)); repo.Tags.Delete(tagName); List tags2 = repo.Tags.Select(r => r.Name).ToList(); - tags2.Contains(tagName).ShouldBeFalse(); + Assert.False(tags2.Contains(tagName)); - tags2.Count.ShouldEqual(tags.Count - 1); + Assert.Equal(tags.Count - 1, tags2.Count); } } @@ -529,7 +529,7 @@ public void CanListTags() { Assert.Equal(expectedTags, repo.Tags.Select(t => t.Name).ToArray()); - repo.Tags.Count().ShouldEqual(4); + Assert.Equal(4, repo.Tags.Count()); } } @@ -541,8 +541,8 @@ public void CanListAllTagsInAEmptyRepository() using (var repo = Repository.Init(scd.DirectoryPath)) { - repo.Info.IsEmpty.ShouldBeTrue(); - repo.Tags.Count().ShouldEqual(0); + Assert.True(repo.Info.IsEmpty); + Assert.Equal(0, repo.Tags.Count()); } } @@ -567,12 +567,12 @@ public void CanLookupALightweightTag() using (var repo = new Repository(BareTestRepoPath)) { Tag tag = repo.Tags["lw"]; - tag.ShouldNotBeNull(); - tag.Name.ShouldEqual("lw"); - tag.Target.Sha.ShouldEqual(commitE90810BSha); + Assert.NotNull(tag); + Assert.Equal("lw", tag.Name); + Assert.Equal(commitE90810BSha, tag.Target.Sha); - tag.IsAnnotated.ShouldBeFalse(); - tag.Annotation.ShouldBeNull(); + Assert.False(tag.IsAnnotated); + Assert.Null(tag.Annotation); } } @@ -582,15 +582,15 @@ public void CanLookupATagByItsCanonicalName() using (var repo = new Repository(BareTestRepoPath)) { Tag tag = repo.Tags["refs/tags/lw"]; - tag.ShouldNotBeNull(); - tag.Name.ShouldEqual("lw"); + Assert.NotNull(tag); + Assert.Equal("lw", tag.Name); Tag tag2 = repo.Tags["refs/tags/lw"]; - tag2.ShouldNotBeNull(); - tag2.Name.ShouldEqual("lw"); + Assert.NotNull(tag2); + Assert.Equal("lw", tag2.Name); - tag2.ShouldEqual(tag); - (tag2 == tag).ShouldBeTrue(); + Assert.Equal(tag, tag2); + Assert.True((tag2 == tag)); } } @@ -600,17 +600,17 @@ public void CanLookupAnAnnotatedTag() using (var repo = new Repository(BareTestRepoPath)) { Tag tag = repo.Tags["e90810b"]; - tag.ShouldNotBeNull(); - tag.Name.ShouldEqual("e90810b"); - tag.Target.Sha.ShouldEqual(commitE90810BSha); - - tag.IsAnnotated.ShouldBeTrue(); - tag.Annotation.Sha.ShouldEqual(tagE90810BSha); - tag.Annotation.Tagger.Email.ShouldEqual("tanoku@gmail.com"); - tag.Annotation.Tagger.Name.ShouldEqual("Vicent Marti"); - tag.Annotation.Tagger.When.ShouldEqual(DateTimeOffset.Parse("2010-08-12 03:59:17 +0200")); - tag.Annotation.Message.ShouldEqual("This is a very simple tag.\n"); - tag.Annotation.Target.Sha.ShouldEqual(commitE90810BSha); + Assert.NotNull(tag); + Assert.Equal("e90810b", tag.Name); + Assert.Equal(commitE90810BSha, tag.Target.Sha); + + Assert.True(tag.IsAnnotated); + Assert.Equal(tagE90810BSha, tag.Annotation.Sha); + Assert.Equal("tanoku@gmail.com", tag.Annotation.Tagger.Email); + Assert.Equal("Vicent Marti", tag.Annotation.Tagger.Name); + Assert.Equal(DateTimeOffset.Parse("2010-08-12 03:59:17 +0200"), tag.Annotation.Tagger.When); + Assert.Equal("This is a very simple tag.\n", tag.Annotation.Message); + Assert.Equal(commitE90810BSha, tag.Annotation.Target.Sha); } } diff --git a/LibGit2Sharp.Tests/TestHelpers/AssertExtensions.cs b/LibGit2Sharp.Tests/TestHelpers/AssertExtensions.cs deleted file mode 100644 index a501d2fd8..000000000 --- a/LibGit2Sharp.Tests/TestHelpers/AssertExtensions.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using Xunit; - -namespace LibGit2Sharp.Tests.TestHelpers -{ - public static class AssertExtensions - { - public static void ShouldBeAboutEqualTo(this DateTimeOffset expected, DateTimeOffset current) - { - Assert.Equal(expected.Date, current.Date); - Assert.Equal(expected.Offset, current.Offset); - Assert.Equal(expected.Hour, current.Hour); - Assert.Equal(expected.Minute, current.Minute); - Assert.Equal(expected.Second, current.Second); - } - - public static void ShouldBeFalse(this bool currentObject) - { - Assert.False(currentObject); - } - - public static void ShouldBeNull(this object currentObject) - { - Assert.Null(currentObject); - } - - public static void ShouldBeTrue(this bool currentObject) - { - Assert.True(currentObject); - } - - public static void ShouldEqual(this object compareFrom, object compareTo) - { - Assert.Equal(compareTo, compareFrom); - } - - public static void ShouldEqual(this T compareFrom, T compareTo) - { - Assert.Equal(compareTo, compareFrom); - } - - public static void ShouldNotBeNull(this object currentObject) - { - Assert.NotNull(currentObject); - } - - public static void ShouldNotEqual(this object compareFrom, object compareTo) - { - Assert.NotEqual(compareTo, compareFrom); - } - } -} diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index 5c8d124a0..dfbf16a8b 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.RegularExpressions; +using Xunit; namespace LibGit2Sharp.Tests.TestHelpers { @@ -94,5 +96,12 @@ protected void InconclusiveIf(Func predicate, string message) throw new SkipException(message); } + + protected static void AssertValueInConfigFile(string configFilePath, string regex) + { + var text = File.ReadAllText(configFilePath); + var r = new Regex(regex, RegexOptions.Multiline).Match(text); + Assert.True(r.Success, text); + } } } diff --git a/LibGit2Sharp.Tests/TestHelpers/DirectoryHelper.cs b/LibGit2Sharp.Tests/TestHelpers/DirectoryHelper.cs index 8d83cd01f..0c6f89c2e 100644 --- a/LibGit2Sharp.Tests/TestHelpers/DirectoryHelper.cs +++ b/LibGit2Sharp.Tests/TestHelpers/DirectoryHelper.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; namespace LibGit2Sharp.Tests.TestHelpers { @@ -46,7 +47,19 @@ public static void DeleteDirectory(string directoryPath) } File.SetAttributes(directoryPath, FileAttributes.Normal); - Directory.Delete(directoryPath, false); + try + { + Directory.Delete(directoryPath, false); + } + catch (IOException ex) + { + throw new IOException(string.Format("{0}The directory '{1}' could not be deleted!" + + "{0}Most of the time, this is due to an external process accessing the files in the temporary repositories created during the test runs, and keeping a handle on the directory, thus preventing the deletion of those files." + + "{0}Known and common causes include:" + + "{0}- Windows Search Indexer (go to the Indexing Options, in the Windows Control Panel, and exclude the bin folder of LibGit2Sharp.Tests)" + + "{0}- Antivirus (exclude the bin folder of LibGit2Sharp.Tests from the paths scanned by your real-time antivirus){0}", + Environment.NewLine, Path.GetFullPath(directoryPath)), ex); + } } } } diff --git a/LibGit2Sharp.Tests/TreeFixture.cs b/LibGit2Sharp.Tests/TreeFixture.cs index a472caef5..d1ee8262d 100755 --- a/LibGit2Sharp.Tests/TreeFixture.cs +++ b/LibGit2Sharp.Tests/TreeFixture.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using System.Linq; using LibGit2Sharp.Tests.TestHelpers; using Xunit; @@ -18,8 +17,8 @@ public void CanCompareTwoTreeEntries() var tree = repo.Lookup(sha); TreeEntry treeEntry1 = tree["README"]; TreeEntry treeEntry2 = tree["README"]; - treeEntry1.ShouldEqual(treeEntry2); - (treeEntry1 == treeEntry2).ShouldBeTrue(); + Assert.Equal(treeEntry2, treeEntry1); + Assert.True((treeEntry1 == treeEntry2)); } } @@ -32,7 +31,7 @@ public void CanConvertEntryToBlob() TreeEntry treeEntry = tree["README"]; var blob = treeEntry.Target as Blob; - blob.ShouldNotBeNull(); + Assert.NotNull(blob); } } @@ -45,7 +44,7 @@ public void CanConvertEntryToTree() TreeEntry treeEntry = tree["1"]; var subtree = treeEntry.Target as Tree; - subtree.ShouldNotBeNull(); + Assert.NotNull(subtree); } } @@ -55,7 +54,7 @@ public void CanEnumerateBlobs() using (var repo = new Repository(BareTestRepoPath)) { var tree = repo.Lookup(sha); - tree.Blobs.Count().ShouldEqual(3); + Assert.Equal(3, tree.Blobs.Count()); } } @@ -65,7 +64,7 @@ public void CanEnumerateSubTrees() using (var repo = new Repository(BareTestRepoPath)) { var tree = repo.Lookup(sha); - tree.Trees.Count().ShouldEqual(1); + Assert.Equal(1, tree.Trees.Count()); } } @@ -75,7 +74,7 @@ public void CanEnumerateTreeEntries() using (var repo = new Repository(BareTestRepoPath)) { var tree = repo.Lookup(sha); - tree.Count().ShouldEqual(tree.Count); + Assert.Equal(tree.Count, tree.Count()); Assert.Equal(new[] { "1", "README", "branch_file.txt", "new.txt" }, tree.Select(te => te.Name).ToArray()); } @@ -88,8 +87,8 @@ public void CanGetEntryByName() { var tree = repo.Lookup(sha); TreeEntry treeEntry = tree["README"]; - treeEntry.Target.Sha.ShouldEqual("a8233120f6ad708f843d861ce2b7228ec4e3dec6"); - treeEntry.Name.ShouldEqual("README"); + Assert.Equal("a8233120f6ad708f843d861ce2b7228ec4e3dec6", treeEntry.Target.Sha); + Assert.Equal("README", treeEntry.Name); } } @@ -100,7 +99,7 @@ public void GettingAnUknownTreeEntryReturnsNull() { var tree = repo.Lookup(sha); TreeEntry treeEntry = tree["I-do-not-exist"]; - treeEntry.ShouldBeNull(); + Assert.Null(treeEntry); } } @@ -110,7 +109,7 @@ public void CanGetEntryCountFromTree() using (var repo = new Repository(BareTestRepoPath)) { var tree = repo.Lookup(sha); - tree.Count.ShouldEqual(4); + Assert.Equal(4, tree.Count); } } @@ -120,7 +119,7 @@ public void CanReadEntryAttributes() using (var repo = new Repository(BareTestRepoPath)) { var tree = repo.Lookup(sha); - tree["README"].Mode.ShouldEqual(Mode.NonExecutableFile); + Assert.Equal(Mode.NonExecutableFile, tree["README"].Mode); } } @@ -130,7 +129,7 @@ public void CanReadTheTreeData() using (var repo = new Repository(BareTestRepoPath)) { var tree = repo.Lookup(sha); - tree.ShouldNotBeNull(); + Assert.NotNull(tree); } } @@ -140,7 +139,7 @@ public void TreeDataIsPresent() using (var repo = new Repository(BareTestRepoPath)) { GitObject tree = repo.Lookup(sha); - tree.ShouldNotBeNull(); + Assert.NotNull(tree); } } @@ -153,27 +152,27 @@ public void CanRetrieveTreeEntryPath() var commitTree = repo.Lookup("4c062a6").Tree; TreeEntry treeTreeEntry = commitTree["1"]; - treeTreeEntry.Path.ShouldEqual("1"); + Assert.Equal("1", treeTreeEntry.Path); string completePath = "1" + Path.DirectorySeparatorChar + "branch_file.txt"; TreeEntry blobTreeEntry = commitTree["1/branch_file.txt"]; - blobTreeEntry.Path.ShouldEqual(completePath); + Assert.Equal(completePath, blobTreeEntry.Path); // A tree entry is now fetched through a relative path to the // tree but exposes a complete path through its Path property var subTree = treeTreeEntry.Target as Tree; - subTree.ShouldNotBeNull(); + Assert.NotNull(subTree); TreeEntry anInstance = subTree["branch_file.txt"]; - anInstance.Path.ShouldNotEqual("branch_file.txt"); - anInstance.Path.ShouldEqual(completePath); - subTree.First().Path.ShouldEqual(completePath); + Assert.NotEqual("branch_file.txt", anInstance.Path); + Assert.Equal(completePath, anInstance.Path); + Assert.Equal(completePath, subTree.First().Path); /* From a random tree */ var tree = repo.Lookup(treeTreeEntry.Target.Id); TreeEntry anotherInstance = tree["branch_file.txt"]; - anotherInstance.Path.ShouldEqual("branch_file.txt"); + Assert.Equal("branch_file.txt", anotherInstance.Path); Assert.Equal(tree, subTree); Assert.Equal(anotherInstance, anInstance); diff --git a/LibGit2Sharp.Tests/TupleFixture.cs b/LibGit2Sharp.Tests/TupleFixture.cs index 58984b1d2..fe86d948f 100644 --- a/LibGit2Sharp.Tests/TupleFixture.cs +++ b/LibGit2Sharp.Tests/TupleFixture.cs @@ -14,8 +14,8 @@ public class TupleFixture [Fact] public void Properties() { - sut.Item1.ShouldEqual(integer); - sut.Item2.ShouldEqual(stringy); + Assert.Equal(integer, sut.Item1); + Assert.Equal(stringy, sut.Item2); } [Fact] @@ -23,7 +23,7 @@ public void GetHashCodeIsTheSame() { var sut2 = new Tuple(integer, stringy); - sut.GetHashCode().ShouldEqual(sut2.GetHashCode()); + Assert.Equal(sut2.GetHashCode(), sut.GetHashCode()); } [Fact] @@ -31,7 +31,7 @@ public void GetHashCodeIsDifferent() { var sut2 = new Tuple(integer + 1, stringy); - sut.GetHashCode().ShouldNotEqual(sut2.GetHashCode()); + Assert.NotEqual(sut2.GetHashCode(), sut.GetHashCode()); } [Fact] @@ -39,8 +39,8 @@ public void VerifyEquals() { var sut2 = new Tuple(integer, stringy); - sut.Equals(sut2).ShouldBeTrue(); - Equals(sut, sut2).ShouldBeTrue(); + Assert.True(sut.Equals(sut2)); + Assert.True(Equals(sut, sut2)); } [Fact] @@ -48,8 +48,8 @@ public void VerifyNotEquals() { var sut2 = new Tuple(integer + 1, stringy); - sut.Equals(sut2).ShouldBeFalse(); - Equals(sut, sut2).ShouldBeFalse(); + Assert.False(sut.Equals(sut2)); + Assert.False(Equals(sut, sut2)); } } } diff --git a/LibGit2Sharp.sln b/LibGit2Sharp.sln index 7a837169c..8d9f849eb 100644 --- a/LibGit2Sharp.sln +++ b/LibGit2Sharp.sln @@ -8,15 +8,20 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Leaks|Any CPU = Leaks|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE6ED99F-CB12-4683-B055-D28FC7357A34}.Leaks|Any CPU.ActiveCfg = Leaks|Any CPU + {EE6ED99F-CB12-4683-B055-D28FC7357A34}.Leaks|Any CPU.Build.0 = Leaks|Any CPU {EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.Build.0 = Release|Any CPU {286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Any CPU.Build.0 = Debug|Any CPU + {286E63EB-04DD-4ADE-88D6-041B57800761}.Leaks|Any CPU.ActiveCfg = Leaks|Any CPU + {286E63EB-04DD-4ADE-88D6-041B57800761}.Leaks|Any CPU.Build.0 = Leaks|Any CPU {286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Any CPU.ActiveCfg = Release|Any CPU {286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs index 4c674d912..381ee5c15 100644 --- a/LibGit2Sharp/BranchCollection.cs +++ b/LibGit2Sharp/BranchCollection.cs @@ -88,17 +88,6 @@ IEnumerator IEnumerable.GetEnumerator() #endregion - /// - /// Checkout the branch with the specified by name. - /// - /// The sha of the commit, a canonical reference name or the name of the branch to checkout. - /// - [Obsolete("This method will be removed in the next release. Please use Repository.Checkout() instead.")] - public Branch Checkout(string shaOrReferenceName) - { - return repo.Checkout(shaOrReferenceName); - } - /// /// Create a new local branch with the specified name /// diff --git a/LibGit2Sharp/Commit.cs b/LibGit2Sharp/Commit.cs index 73241190e..1d5c976fe 100644 --- a/LibGit2Sharp/Commit.cs +++ b/LibGit2Sharp/Commit.cs @@ -1,6 +1,5 @@ -using System; using System.Collections.Generic; -using System.Runtime.InteropServices; +using System.Linq; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Compat; using LibGit2Sharp.Core.Handles; @@ -16,6 +15,7 @@ public class Commit : GitObject private readonly Lazy> parents; private readonly Lazy tree; private readonly Lazy shortMessage; + private readonly Lazy> notes; internal Commit(ObjectId id, ObjectId treeId, Repository repo) : base(id) @@ -23,6 +23,7 @@ internal Commit(ObjectId id, ObjectId treeId, Repository repo) tree = new Lazy(() => repo.Lookup(treeId)); parents = new Lazy>(() => RetrieveParentsOfCommit(id)); shortMessage = new Lazy(ExtractShortMessage); + notes = new Lazy>(() => RetrieveNotesOfCommit(id).ToList()); this.repo = repo; } @@ -104,6 +105,14 @@ public int ParentsCount } } + /// + /// Gets the notes of this commit. + /// + public IEnumerable Notes + { + get { return notes.Value; } + } + private IEnumerable RetrieveParentsOfCommit(ObjectId oid) { using (var obj = new ObjectSafeWrapper(oid, repo)) @@ -112,13 +121,19 @@ private IEnumerable RetrieveParentsOfCommit(ObjectId oid) for (uint i = 0; i < parentsCount; i++) { - GitObjectSafeHandle parentCommit; - Ensure.Success(NativeMethods.git_commit_parent(out parentCommit, obj.ObjectPtr, i)); - yield return BuildFromPtr(parentCommit, ObjectIdOf(parentCommit), repo); + using (var parentCommit = GetParentCommitHandle(i, obj)) + { + yield return BuildFromPtr(parentCommit, ObjectIdOf(parentCommit), repo); + } } } } + private IEnumerable RetrieveNotesOfCommit(ObjectId oid) + { + return repo.Notes[oid]; + } + internal static Commit BuildFromPtr(GitObjectSafeHandle obj, ObjectId id, Repository repo) { ObjectId treeId = NativeMethods.git_commit_tree_oid(obj).MarshalAsObjectId(); @@ -132,6 +147,13 @@ internal static Commit BuildFromPtr(GitObjectSafeHandle obj, ObjectId id, Reposi }; } + private static GitObjectSafeHandle GetParentCommitHandle(uint i, ObjectSafeWrapper obj) + { + GitObjectSafeHandle parentCommit; + Ensure.Success(NativeMethods.git_commit_parent(out parentCommit, obj.ObjectPtr, i)); + return parentCommit; + } + private static string RetrieveEncodingOf(GitObjectSafeHandle obj) { string encoding = NativeMethods.git_commit_message_encoding(obj); diff --git a/LibGit2Sharp/Configuration.cs b/LibGit2Sharp/Configuration.cs index bc3334784..0c85ccfbf 100644 --- a/LibGit2Sharp/Configuration.cs +++ b/LibGit2Sharp/Configuration.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; @@ -20,21 +21,61 @@ public class Configuration : IDisposable private ConfigurationSafeHandle globalHandle; private ConfigurationSafeHandle localHandle; - internal Configuration(Repository repository) + internal Configuration(Repository repository, string globalConfigurationFileLocation, string systemConfigurationFileLocation) { this.repository = repository; - globalConfigPath = ConvertPath(NativeMethods.git_config_find_global); - systemConfigPath = ConvertPath(NativeMethods.git_config_find_system); + globalConfigPath = globalConfigurationFileLocation ?? ConvertPath(NativeMethods.git_config_find_global); + systemConfigPath = systemConfigurationFileLocation ?? ConvertPath(NativeMethods.git_config_find_system); Init(); } + private void Init() + { + if (repository != null) + { + //TODO: push back this logic into libgit2. + // As stated by @carlosmn "having a helper function to load the defaults and then allowing you + // to modify it before giving it to git_repository_open_ext() would be a good addition, I think." + // -- Agreed :) + + Ensure.Success(NativeMethods.git_config_new(out localHandle)); + + string repoConfigLocation = Path.Combine(repository.Info.Path, "config"); + Ensure.Success(NativeMethods.git_config_add_file_ondisk(localHandle, repoConfigLocation, 3)); + + if (globalConfigPath != null) + { + Ensure.Success(NativeMethods.git_config_add_file_ondisk(localHandle, globalConfigPath, 2)); + } + + if (systemConfigPath != null) + { + Ensure.Success(NativeMethods.git_config_add_file_ondisk(localHandle, systemConfigPath, 1)); + } + + NativeMethods.git_repository_set_config(repository.Handle, localHandle); + } + + if (globalConfigPath != null) + { + Ensure.Success(NativeMethods.git_config_open_ondisk(out globalHandle, globalConfigPath)); + } + + if (systemConfigPath != null) + { + Ensure.Success(NativeMethods.git_config_open_ondisk(out systemHandle, systemConfigPath)); + } + } + /// /// Access configuration values without a repository. Generally you want to access configuration via an instance of instead. /// - public Configuration() - : this(null) + /// Path to a Global configuration file. If null, the default path for a global configuration file will be probed. + /// Path to a System configuration file. If null, the default path for a system configuration file will be probed. + public Configuration(string globalConfigurationFileLocation = null, string systemConfigurationFileLocation = null) + : this(null, globalConfigurationFileLocation, systemConfigurationFileLocation) { } @@ -62,11 +103,11 @@ public bool HasSystemConfig get { return systemConfigPath != null; } } - private static string ConvertPath(Func pathRetriever) + private static string ConvertPath(Func pathRetriever) { var buffer = new byte[NativeMethods.GIT_PATH_MAX]; - int result = pathRetriever(buffer, new IntPtr(NativeMethods.GIT_PATH_MAX)); + int result = pathRetriever(buffer, NativeMethods.GIT_PATH_MAX); if (result == (int)GitErrorCode.GIT_ENOTFOUND) { @@ -117,55 +158,6 @@ protected virtual void Dispose(bool disposing) systemHandle.SafeDispose(); } - private static T ProcessReadResult(int res, T value, T defaultValue) - { - if (res == (int)GitErrorCode.GIT_ENOTFOUND) - { - return defaultValue; - } - - Ensure.Success(res); - - return value; - } - - private readonly IDictionary> configurationTypedRetriever = ConfigurationTypedRetriever(); - - private static Dictionary> ConfigurationTypedRetriever() - { - var dic = new Dictionary>(); - - dic.Add(typeof(int), (key, dv, handle) => - { - int value; - int res = NativeMethods.git_config_get_int32(out value, handle, key); - return ProcessReadResult(res, value, dv); - }); - - dic.Add(typeof(long), (key, dv, handle) => - { - long value; - int res = NativeMethods.git_config_get_int64(out value, handle, key); - return ProcessReadResult(res, value, dv); - }); - - dic.Add(typeof(bool), (key, dv, handle) => - { - bool value; - int res = NativeMethods.git_config_get_bool(out value, handle, key); - return ProcessReadResult(res, value, dv); - }); - - dic.Add(typeof(string), (key, dv, handle) => - { - string value; - int res = NativeMethods.git_config_get_string(out value, handle, key); - return ProcessReadResult(res, value, dv); - }); - - return dic; - } - /// /// Get a configuration value for a key. Keys are in the form 'section.name'. /// @@ -295,44 +287,12 @@ public T Get(string[] keyParts, T defaultValue) return Get(string.Join(".", keyParts), defaultValue); } - private void Init() - { - if (repository != null) - { - Ensure.Success(NativeMethods.git_repository_config(out localHandle, repository.Handle)); - } - - if (globalConfigPath != null) - { - Ensure.Success(NativeMethods.git_config_open_ondisk(out globalHandle, globalConfigPath)); - } - - if (systemConfigPath != null) - { - Ensure.Success(NativeMethods.git_config_open_ondisk(out systemHandle, systemConfigPath)); - } - } - private void Save() { Dispose(true); Init(); } - private readonly IDictionary> configurationTypedUpdater = ConfigurationTypedUpdater(); - - private static Dictionary> ConfigurationTypedUpdater() - { - var dic = new Dictionary>(); - - dic.Add(typeof(int), (key, val, handle) => Ensure.Success(NativeMethods.git_config_set_int32(handle, key, (int)val))); - dic.Add(typeof(long), (key, val, handle) => Ensure.Success(NativeMethods.git_config_set_int64(handle, key, (long)val))); - dic.Add(typeof(bool), (key, val, handle) => Ensure.Success(NativeMethods.git_config_set_bool(handle, key, (bool)val))); - dic.Add(typeof(string), (key, val, handle) => Ensure.Success(NativeMethods.git_config_set_string(handle, key, (string)val))); - - return dic; - } - /// /// Set a configuration value for a key. Keys are in the form 'section.name'. /// @@ -397,5 +357,44 @@ public void Set(string key, T value, ConfigurationLevel level = Configuration configurationTypedUpdater[typeof(T)](key, value, h); Save(); } + + private delegate int ConfigGetter(out T value, ConfigurationSafeHandle handle, string name); + + private static Func GetRetriever(ConfigGetter getter) + { + return (key, defaultValue, handle) => + { + T value; + var res = getter(out value, handle, key); + if (res == (int)GitErrorCode.GIT_ENOTFOUND) + { + return defaultValue; + } + + Ensure.Success(res); + return value; + }; + } + + private readonly IDictionary> configurationTypedRetriever = new Dictionary> + { + { typeof(int), GetRetriever(NativeMethods.git_config_get_int32) }, + { typeof(long), GetRetriever(NativeMethods.git_config_get_int64) }, + { typeof(bool), GetRetriever(NativeMethods.git_config_get_bool) }, + { typeof(string), GetRetriever(NativeMethods.git_config_get_string) }, + }; + + private static Action GetUpdater(Func setter) + { + return (key, val, handle) => Ensure.Success(setter(handle, key, (T)val)); + } + + private readonly IDictionary> configurationTypedUpdater = new Dictionary> + { + { typeof(int), GetUpdater(NativeMethods.git_config_set_int32) }, + { typeof(long), GetUpdater(NativeMethods.git_config_set_int64) }, + { typeof(bool), GetUpdater(NativeMethods.git_config_set_bool) }, + { typeof(string), GetUpdater(NativeMethods.git_config_set_string) }, + }; } } diff --git a/LibGit2Sharp/ContentChanges.cs b/LibGit2Sharp/ContentChanges.cs index c5c6cdac9..b9913538e 100644 --- a/LibGit2Sharp/ContentChanges.cs +++ b/LibGit2Sharp/ContentChanges.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices; using System.Text; using LibGit2Sharp.Core; @@ -11,6 +10,7 @@ namespace LibGit2Sharp public class ContentChanges { private readonly StringBuilder patchBuilder = new StringBuilder(); + private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty); protected ContentChanges() { @@ -45,22 +45,17 @@ internal static bool IsBinaryDelta(GitDiffDelta delta) return delta.OldFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY) || delta.NewFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY); } - private static string NativeToString(IntPtr content, IntPtr contentlen) + private int HunkCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, IntPtr header, uint headerlen) { - return ((Utf8Marshaler)(Utf8Marshaler.GetInstance(string.Empty))).NativeToString(content, contentlen.ToInt32()); - } - - private int HunkCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, IntPtr header, IntPtr headerlen) - { - string decodedContent = NativeToString(header, headerlen); + string decodedContent = marshaler.NativeToString(header, headerlen); PatchBuilder.AppendFormat("{0}", decodedContent); return 0; } - private int LineCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, IntPtr contentlen) + private int LineCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, uint contentlen) { - string decodedContent = NativeToString(content, contentlen); + string decodedContent = marshaler.NativeToString(content, contentlen); string prefix; diff --git a/LibGit2Sharp/Core/Ensure.cs b/LibGit2Sharp/Core/Ensure.cs index ea164100c..60566d3c2 100644 --- a/LibGit2Sharp/Core/Ensure.cs +++ b/LibGit2Sharp/Core/Ensure.cs @@ -70,7 +70,7 @@ public static void Success(int result, bool allowPositiveResult = false) throw new LibGit2Exception( String.Format(CultureInfo.InvariantCulture, "An error was raised by libgit2. Class = {0} ({1}).{2}{3}", - Enum.GetName(typeof(GitErrorType), error.Klass.ToInt32()), + Enum.GetName(typeof(GitErrorType), error.Klass), result, Environment.NewLine, errorMessage)); diff --git a/LibGit2Sharp/Core/EnumExtensions.cs b/LibGit2Sharp/Core/EnumExtensions.cs index 42391c53d..fbd5218b1 100644 --- a/LibGit2Sharp/Core/EnumExtensions.cs +++ b/LibGit2Sharp/Core/EnumExtensions.cs @@ -13,7 +13,7 @@ public static bool Has(this Enum enumInstance, T entry) public static bool HasAny(this Enum enumInstance, IEnumerable entries) { - return entries.Any(enumInstance.Has); + return entries.Any(enumInstance.Has); } } } diff --git a/LibGit2Sharp/Core/GitDiff.cs b/LibGit2Sharp/Core/GitDiff.cs index f7ac7f8ec..36b36be0d 100644 --- a/LibGit2Sharp/Core/GitDiff.cs +++ b/LibGit2Sharp/Core/GitDiff.cs @@ -59,17 +59,17 @@ internal class GitDiffDelta public GitDiffFile OldFile; public GitDiffFile NewFile; public ChangeKind Status; - public UIntPtr Similarity; - public IntPtr Binary; + public uint Similarity; + public int Binary; } [StructLayout(LayoutKind.Sequential)] internal class GitDiffRange { - public IntPtr OldStart; - public IntPtr OldLines; - public IntPtr NewStart; - public IntPtr NewLines; + public int OldStart; + public int OldLines; + public int NewStart; + public int NewLines; } enum GitDiffLineOrigin : byte @@ -85,4 +85,4 @@ enum GitDiffLineOrigin : byte GIT_DIFF_LINE_HUNK_HDR = 0x48, //'H', GIT_DIFF_LINE_BINARY = 0x42, //'B', } -} \ No newline at end of file +} diff --git a/LibGit2Sharp/Core/GitError.cs b/LibGit2Sharp/Core/GitError.cs index 587ae48bf..5d72dce65 100644 --- a/LibGit2Sharp/Core/GitError.cs +++ b/LibGit2Sharp/Core/GitError.cs @@ -7,7 +7,7 @@ namespace LibGit2Sharp.Core internal class GitError { public IntPtr Message; - public IntPtr Klass; + public int Klass; } internal enum GitErrorType diff --git a/LibGit2Sharp/Core/GitNoteData.cs b/LibGit2Sharp/Core/GitNoteData.cs new file mode 100644 index 000000000..6592ab8c5 --- /dev/null +++ b/LibGit2Sharp/Core/GitNoteData.cs @@ -0,0 +1,11 @@ +using System.Runtime.InteropServices; + +namespace LibGit2Sharp.Core +{ + [StructLayout(LayoutKind.Sequential)] + internal class GitNoteData + { + public GitOid BlobOid; + public GitOid TargetOid; + } +} diff --git a/LibGit2Sharp/Core/Handles/NoteSafeHandle.cs b/LibGit2Sharp/Core/Handles/NoteSafeHandle.cs new file mode 100644 index 000000000..22e8fcffb --- /dev/null +++ b/LibGit2Sharp/Core/Handles/NoteSafeHandle.cs @@ -0,0 +1,11 @@ +namespace LibGit2Sharp.Core.Handles +{ + internal class NoteSafeHandle : SafeHandleBase + { + protected override bool ReleaseHandle() + { + NativeMethods.git_note_free(handle); + return true; + } + } +} diff --git a/LibGit2Sharp/Core/Handles/SafeHandleBase.cs b/LibGit2Sharp/Core/Handles/SafeHandleBase.cs index 3a5535a0f..a65669076 100644 --- a/LibGit2Sharp/Core/Handles/SafeHandleBase.cs +++ b/LibGit2Sharp/Core/Handles/SafeHandleBase.cs @@ -1,13 +1,36 @@ using System; +using System.Diagnostics; using System.Runtime.InteropServices; namespace LibGit2Sharp.Core.Handles { internal abstract class SafeHandleBase : SafeHandle { +#if LEAKS + private readonly string trace; +#endif + protected SafeHandleBase() : base(IntPtr.Zero, true) { +#if LEAKS + trace = new StackTrace(2, true).ToString(); +#endif + } + + protected override void Dispose(bool disposing) + { +#if DEBUG + if (!disposing && !IsInvalid) + { + Trace.WriteLine(string.Format("A {0} handle wrapper has not been properly disposed.", GetType().Name)); +#if LEAKS + Trace.WriteLine(trace); +#endif + Trace.WriteLine(""); + } +#endif + base.Dispose(disposing); } public override bool IsInvalid diff --git a/LibGit2Sharp/Core/Handles/SafeHandleExtensions.cs b/LibGit2Sharp/Core/Handles/SafeHandleExtensions.cs index 1282dcc7b..00a4b6ed7 100644 --- a/LibGit2Sharp/Core/Handles/SafeHandleExtensions.cs +++ b/LibGit2Sharp/Core/Handles/SafeHandleExtensions.cs @@ -1,7 +1,24 @@ -namespace LibGit2Sharp.Core.Handles +using System; + +namespace LibGit2Sharp.Core.Handles { internal static class SafeHandleExtensions { + public static void SafeDispose(this IDisposable disposable) + { + if (disposable == null) + return; + + var handle = disposable as SafeHandleBase; + if (handle != null) + { + SafeDispose(handle); + return; + } + + disposable.Dispose(); + } + public static void SafeDispose(this SafeHandleBase handle) { if (handle == null || handle.IsClosed || handle.IsInvalid) diff --git a/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs b/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs index e87cb9213..dc38cdb38 100644 --- a/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs +++ b/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs @@ -52,7 +52,7 @@ private static IList BuildListOf(UnSafeNativeMethods.git_strarray strArr { UnSafeNativeMethods.git_strarray* gitStrArray = &strArray; - int numberOfEntries = gitStrArray->size.ToInt32(); + uint numberOfEntries = gitStrArray->size; for (uint i = 0; i < numberOfEntries; i++) { var name = (string)marshaler.MarshalNativeToManaged((IntPtr)gitStrArray->strings[i]); diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index ffe53751c..164562e1d 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -9,7 +9,7 @@ namespace LibGit2Sharp.Core { internal static class NativeMethods { - public const int GIT_PATH_MAX = 4096; + public const uint GIT_PATH_MAX = 4096; private const string libgit2 = "git2"; static NativeMethods() @@ -149,10 +149,10 @@ public static extern int git_commit_create( public static extern int git_config_delete(ConfigurationSafeHandle cfg, string name); [DllImport(libgit2)] - public static extern int git_config_find_global(byte[] global_config_path, IntPtr length); + public static extern int git_config_find_global(byte[] global_config_path, uint length); [DllImport(libgit2)] - public static extern int git_config_find_system(byte[] system_config_path, IntPtr length); + public static extern int git_config_find_system(byte[] system_config_path, uint length); [DllImport(libgit2)] public static extern void git_config_free(IntPtr cfg); @@ -181,6 +181,15 @@ public static extern int git_config_get_string( ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name); + [DllImport(libgit2)] + public static extern int git_config_add_file_ondisk( + ConfigurationSafeHandle cfg, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path, + int priority); + + [DllImport(libgit2)] + public static extern int git_config_new(out ConfigurationSafeHandle cfg); + [DllImport(libgit2)] public static extern int git_config_open_global(out ConfigurationSafeHandle cfg); @@ -259,7 +268,7 @@ internal delegate int git_diff_hunk_fn( GitDiffDelta delta, GitDiffRange range, IntPtr header, - IntPtr headerLen); + uint headerLen); [DllImport(libgit2)] public static extern int git_diff_foreach( @@ -275,7 +284,7 @@ internal delegate int git_diff_data_fn( GitDiffRange range, GitDiffLineOrigin lineOrigin, IntPtr content, - IntPtr contentLen); + uint contentLen); [DllImport(libgit2)] public static extern int git_diff_print_patch( @@ -339,6 +348,57 @@ public static extern int git_merge_base( GitObjectSafeHandle one, GitObjectSafeHandle two); + [DllImport(libgit2)] + public static extern int git_note_create( + out GitOid noteOid, + RepositorySafeHandle repo, + SignatureSafeHandle author, + SignatureSafeHandle committer, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref, + ref GitOid oid, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string note); + + [DllImport(libgit2)] + public static extern void git_note_free(IntPtr note); + + [DllImport(libgit2)] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] + public static extern string git_note_message(NoteSafeHandle note); + + [DllImport(libgit2)] + public static extern OidSafeHandle git_note_oid(NoteSafeHandle note); + + [DllImport(libgit2)] + public static extern int git_note_read( + out NoteSafeHandle note, + RepositorySafeHandle repo, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref, + ref GitOid oid); + + [DllImport(libgit2)] + public static extern int git_note_remove( + RepositorySafeHandle repo, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref, + SignatureSafeHandle author, + SignatureSafeHandle committer, + ref GitOid oid); + + [DllImport(libgit2)] + public static extern int git_note_default_ref( + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] out string notes_ref, + RepositorySafeHandle repo); + + internal delegate int notes_foreach_callback( + GitNoteData noteData, + IntPtr payload); + + [DllImport(libgit2)] + public static extern int git_note_foreach( + RepositorySafeHandle repo, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref, + notes_foreach_callback callback, + IntPtr payload); + [DllImport(libgit2)] public static extern int git_odb_exists(ObjectDatabaseSafeHandle odb, ref GitOid id); @@ -496,6 +556,11 @@ public static extern int git_repository_open( [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] public static extern FilePath git_repository_path(RepositorySafeHandle repository); + [DllImport(libgit2)] + public static extern void git_repository_set_config( + RepositorySafeHandle repository, + ConfigurationSafeHandle index); + [DllImport(libgit2)] public static extern void git_repository_set_index( RepositorySafeHandle repository, diff --git a/LibGit2Sharp/Core/UnSafeNativeMethods.cs b/LibGit2Sharp/Core/UnSafeNativeMethods.cs index fe35e2f96..4f6aa11d7 100644 --- a/LibGit2Sharp/Core/UnSafeNativeMethods.cs +++ b/LibGit2Sharp/Core/UnSafeNativeMethods.cs @@ -28,7 +28,7 @@ internal static unsafe class UnSafeNativeMethods internal struct git_strarray { public sbyte** strings; - public IntPtr size; + public uint size; } #endregion diff --git a/LibGit2Sharp/Core/Utf8Marshaler.cs b/LibGit2Sharp/Core/Utf8Marshaler.cs index 712faaa8d..ac48b0e2e 100644 --- a/LibGit2Sharp/Core/Utf8Marshaler.cs +++ b/LibGit2Sharp/Core/Utf8Marshaler.cs @@ -59,18 +59,19 @@ protected unsafe string NativeToString(IntPtr pNativeData) { walk++; } - var length = (int)(walk - (byte*)pNativeData); + + var length = (uint)(walk - (byte*)pNativeData); return NativeToString(pNativeData, length); } - public string NativeToString(IntPtr pNativeData, int length) + public string NativeToString(IntPtr pNativeData, uint length) { // should not be null terminated var strbuf = new byte[length]; // skip the trailing null - Marshal.Copy(pNativeData, strbuf, 0, length); + Marshal.Copy(pNativeData, strbuf, 0, (int)length); string data = Encoding.UTF8.GetString(strbuf); return data; } diff --git a/LibGit2Sharp/GitObject.cs b/LibGit2Sharp/GitObject.cs index 703fc7c33..9418f3f05 100644 --- a/LibGit2Sharp/GitObject.cs +++ b/LibGit2Sharp/GitObject.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using System.Runtime.InteropServices; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; diff --git a/LibGit2Sharp/IndexEntry.cs b/LibGit2Sharp/IndexEntry.cs index 8bb5ea468..8fd5039ee 100644 --- a/LibGit2Sharp/IndexEntry.cs +++ b/LibGit2Sharp/IndexEntry.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index fc6bbd76d..b840ad90b 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -37,6 +37,18 @@ false bin\Release\LibGit2Sharp.xml + + true + full + false + bin\Leaks\ + TRACE;DEBUG;NET35;LEAKS + prompt + 4 + false + true + AllRules.ruleset + @@ -62,8 +74,10 @@ + + @@ -78,6 +92,8 @@ + + diff --git a/LibGit2Sharp/Note.cs b/LibGit2Sharp/Note.cs new file mode 100644 index 000000000..6ec864b3a --- /dev/null +++ b/LibGit2Sharp/Note.cs @@ -0,0 +1,103 @@ +using System; +using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp +{ + /// + /// A note, attached to a given . + /// + public class Note + { + private Note(ObjectId blobId, string message, ObjectId targetObjectId, string @namespace) + { + BlobId = blobId; + Namespace = @namespace; + Message = message; + TargetObjectId = targetObjectId; + } + + /// + /// The of the blob containing the note message. + /// + public ObjectId BlobId { get; private set; } + + /// + /// The message. + /// + public string Message { get; private set; } + + /// + /// The namespace with which this note is associated. + /// This is the abbreviated namespace (e.g.: commits), and not the canonical namespace (e.g.: refs/notes/commits). + /// + public string Namespace { get; private set; } + + /// + /// The of the target object. + /// + public ObjectId TargetObjectId { get; private set; } + + internal static Note BuildFromPtr(Repository repo, string @namespace, ObjectId targetObjectId, NoteSafeHandle note) + { + ObjectId oid = NativeMethods.git_note_oid(note).MarshalAsObjectId(); + string message = NativeMethods.git_note_message(note); + + return new Note(oid, message, targetObjectId, @namespace); + } + + private static readonly LambdaEqualityHelper equalityHelper = + new LambdaEqualityHelper(new Func[] { x => x.BlobId, x => x.TargetObjectId, x => x.Namespace }); + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// True if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return Equals(obj as Note); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// True if the specified is equal to the current ; otherwise, false. + public bool Equals(Note other) + { + return equalityHelper.Equals(this, other); + } + + /// + /// Returns the hash code for this instance. + /// + /// A 32-bit signed integer hash code. + public override int GetHashCode() + { + return equalityHelper.GetHashCode(this); + } + + /// + /// Tests if two are equal. + /// + /// First to compare. + /// Second to compare. + /// True if the two objects are equal; false otherwise. + public static bool operator ==(Note left, Note right) + { + return Equals(left, right); + } + + /// + /// Tests if two are different. + /// + /// First to compare. + /// Second to compare. + /// True if the two objects are different; false otherwise. + public static bool operator !=(Note left, Note right) + { + return !Equals(left, right); + } + } +} diff --git a/LibGit2Sharp/NoteCollection.cs b/LibGit2Sharp/NoteCollection.cs new file mode 100644 index 000000000..5759075b3 --- /dev/null +++ b/LibGit2Sharp/NoteCollection.cs @@ -0,0 +1,262 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp +{ + /// + /// A collection of exposed in the . + /// + public class NoteCollection : IEnumerable + { + private readonly Repository repo; + private readonly Lazy defaultNamespace; + + private const string refsNotesPrefix = "refs/notes/"; + + internal NoteCollection(Repository repo) + { + this.repo = repo; + defaultNamespace = new Lazy(RetrieveDefaultNamespace); + } + + #region Implementation of IEnumerable + + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An object that can be used to iterate through the collection. + public IEnumerator GetEnumerator() + { + return this[DefaultNamespace].GetEnumerator(); + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An object that can be used to iterate through the collection. + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion + + /// + /// The default namespace for notes. + /// + public string DefaultNamespace + { + get { return defaultNamespace.Value; } + } + + /// + /// The list of canonicalized namespaces related to notes. + /// + public IEnumerable Namespaces + { + get + { + return NamespaceRefs.Select(UnCanonicalizeName); + } + } + + internal IEnumerable NamespaceRefs + { + get + { + return new[] { NormalizeToCanonicalName(DefaultNamespace) }.Concat( + from reference in repo.Refs + select reference.CanonicalName into refCanonical + where refCanonical.StartsWith(refsNotesPrefix) && refCanonical != NormalizeToCanonicalName(DefaultNamespace) + select refCanonical); + } + } + + /// + /// Gets the collection of associated with the specified . + /// + public IEnumerable this[ObjectId id] + { + get + { + Ensure.ArgumentNotNull(id, "id"); + + return NamespaceRefs + .Select(ns => RetrieveNote(id, ns)) + .Where(n => n != null); + } + } + + /// + /// Gets the collection of associated with the specified namespace. + /// This is similar to the 'get notes list' command. + /// + public IEnumerable this[string @namespace] + { + get + { + Ensure.ArgumentNotNull(@namespace, "@namespace"); + + string canonicalNamespace = NormalizeToCanonicalName(@namespace); + var notesOidRetriever = new NotesOidRetriever(repo, canonicalNamespace); + + return notesOidRetriever.Retrieve().Select(oid => RetrieveNote(new ObjectId(oid), canonicalNamespace)); + } + } + + internal Note RetrieveNote(ObjectId targetObjectId, string canonicalNamespace) + { + using (NoteSafeHandle noteHandle = BuildNoteSafeHandle(targetObjectId, canonicalNamespace)) + { + if (noteHandle == null) + { + return null; + } + + return Note.BuildFromPtr(repo, UnCanonicalizeName(canonicalNamespace), targetObjectId, noteHandle); + } + } + + private string RetrieveDefaultNamespace() + { + string notesRef; + Ensure.Success(NativeMethods.git_note_default_ref(out notesRef, repo.Handle)); + + return UnCanonicalizeName(notesRef); + } + + private NoteSafeHandle BuildNoteSafeHandle(ObjectId id, string canonicalNamespace) + { + NoteSafeHandle noteHandle; + GitOid oid = id.Oid; + + int res = NativeMethods.git_note_read(out noteHandle, repo.Handle, canonicalNamespace, ref oid); + + if (res == (int)GitErrorCode.GIT_ENOTFOUND) + { + return null; + } + + Ensure.Success(res); + + return noteHandle; + } + + internal string NormalizeToCanonicalName(string name) + { + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + if (name.StartsWith(refsNotesPrefix, StringComparison.Ordinal)) + { + return name; + } + + return string.Concat(refsNotesPrefix, name); + } + + internal string UnCanonicalizeName(string name) + { + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + if (!name.StartsWith(refsNotesPrefix, StringComparison.Ordinal)) + { + return name; + } + + return name.Substring(refsNotesPrefix.Length); + } + + /// + /// Creates or updates a on the specified object, and for the given namespace. + /// + /// The target , for which the note will be created. + /// The note message. + /// The author. + /// The committer. + /// The namespace on which the note will be created. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace'). + /// The note which was just saved. + public Note Create(ObjectId targetId, string message, Signature author, Signature committer, string @namespace) + { + Ensure.ArgumentNotNull(targetId, "targetId"); + Ensure.ArgumentNotNullOrEmptyString(message, "message"); + Ensure.ArgumentNotNull(author, "author"); + Ensure.ArgumentNotNull(committer, "committer"); + Ensure.ArgumentNotNullOrEmptyString(@namespace, "@namespace"); + + string canonicalNamespace = NormalizeToCanonicalName(@namespace); + + GitOid oid = targetId.Oid; + + Delete(targetId, author, committer, @namespace); + + using (SignatureSafeHandle authorHandle = author.BuildHandle()) + using (SignatureSafeHandle committerHandle = committer.BuildHandle()) + { + GitOid noteOid; + Ensure.Success(NativeMethods.git_note_create(out noteOid, repo.Handle, authorHandle, committerHandle, canonicalNamespace, ref oid, message)); + } + + return RetrieveNote(targetId, canonicalNamespace); + } + + /// + /// Deletes the note on the specified object, and for the given namespace. + /// + /// The target , for which the note will be created. + /// The author. + /// The committer. + /// The namespace on which the note will be removed. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace'). + public void Delete(ObjectId targetId, Signature author, Signature committer, string @namespace) + { + Ensure.ArgumentNotNull(targetId, "targetId"); + Ensure.ArgumentNotNull(author, "author"); + Ensure.ArgumentNotNull(committer, "committer"); + Ensure.ArgumentNotNullOrEmptyString(@namespace, "@namespace"); + + string canonicalNamespace = NormalizeToCanonicalName(@namespace); + + GitOid oid = targetId.Oid; + int res; + + using (SignatureSafeHandle authorHandle = author.BuildHandle()) + using (SignatureSafeHandle committerHandle = committer.BuildHandle()) + { + res = NativeMethods.git_note_remove(repo.Handle, canonicalNamespace, authorHandle, committerHandle, ref oid); + } + + if (res == (int)GitErrorCode.GIT_ENOTFOUND) + { + return; + } + + Ensure.Success(res); + } + + private class NotesOidRetriever + { + private readonly List notesOid = new List(); + + internal NotesOidRetriever(Repository repo, string canonicalNamespace) + { + Ensure.Success(NativeMethods.git_note_foreach(repo.Handle, canonicalNamespace, NoteListCallBack, IntPtr.Zero)); + } + + private int NoteListCallBack(GitNoteData noteData, IntPtr intPtr) + { + notesOid.Add(noteData.TargetOid); + + return 0; + } + + public IEnumerable Retrieve() + { + return notesOid; + } + } + } +} diff --git a/LibGit2Sharp/Properties/AssemblyInfo.cs b/LibGit2Sharp/Properties/AssemblyInfo.cs index ba9846e3d..255070ff6 100644 --- a/LibGit2Sharp/Properties/AssemblyInfo.cs +++ b/LibGit2Sharp/Properties/AssemblyInfo.cs @@ -42,5 +42,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.9.0")] -[assembly: AssemblyFileVersion("0.9.0")] +[assembly: AssemblyVersion("0.9.5")] +[assembly: AssemblyFileVersion("0.9.5")] diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 2bd09b942..e4ee702fe 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -24,8 +24,9 @@ public class Repository : IDisposable private readonly TagCollection tags; private readonly Lazy info; private readonly Diff diff; + private readonly NoteCollection notes; private readonly Lazy odb; - private readonly Stack handlesToCleanup = new Stack(); + private readonly Stack toCleanup = new Stack(); private static readonly Lazy versionRetriever = new Lazy(RetrieveVersion); /// @@ -50,16 +51,14 @@ public Repository(string path, RepositoryOptions options = null) Func indexBuilder = () => new Index(this); + string configurationGlobalFilePath = null; + string configurationSystemFilePath = null; + if (options != null) { bool isWorkDirNull = string.IsNullOrEmpty(options.WorkingDirectoryPath); bool isIndexNull = string.IsNullOrEmpty(options.IndexPath); - if (isWorkDirNull && isIndexNull) - { - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "At least one member of the {0} instance has to be provided.", typeof(RepositoryOptions).Name)); - } - if (isBare && (isWorkDirNull ^ isIndexNull)) { throw new ArgumentException("When overriding the opening of a bare repository, both RepositoryOptions.WorkingDirectoryPath an RepositoryOptions.IndexPath have to be provided."); @@ -76,6 +75,9 @@ public Repository(string path, RepositoryOptions options = null) { Ensure.Success(NativeMethods.git_repository_set_workdir(handle, options.WorkingDirectoryPath)); } + + configurationGlobalFilePath = options.GlobalConfigurationLocation; + configurationSystemFilePath = options.SystemConfigurationLocation; } if (!isBare) @@ -88,10 +90,11 @@ public Repository(string path, RepositoryOptions options = null) branches = new BranchCollection(this); tags = new TagCollection(this); info = new Lazy(() => new RepositoryInformation(this, isBare)); - config = new Lazy(() => new Configuration(this)); + config = new Lazy(() => RegisterForCleanup(new Configuration(this, configurationGlobalFilePath, configurationSystemFilePath))); remotes = new Lazy(() => new RemoteCollection(this)); odb = new Lazy(() => new ObjectDatabase(this)); diff = new Diff(this); + notes = new NoteCollection(this); } /// @@ -218,6 +221,14 @@ public Diff Diff get { return diff; } } + /// + /// Lookup notes in the repository. + /// + public NoteCollection Notes + { + get { return notes; } + } + #region IDisposable Members /// @@ -234,9 +245,9 @@ public void Dispose() /// protected virtual void Dispose(bool disposing) { - while (handlesToCleanup.Count > 0) + while (toCleanup.Count > 0) { - handlesToCleanup.Pop().SafeDispose(); + toCleanup.Pop().SafeDispose(); } } @@ -471,9 +482,10 @@ public void Reset(ResetOptions resetOptions, string shaOrReferenceName) throw new NotImplementedException(); } - internal void RegisterForCleanup(SafeHandleBase handleToCleanup) + internal T RegisterForCleanup(T disposable) where T : IDisposable { - handlesToCleanup.Push(handleToCleanup); + toCleanup.Push(disposable); + return disposable; } /// diff --git a/LibGit2Sharp/RepositoryInformation.cs b/LibGit2Sharp/RepositoryInformation.cs index 818fafe22..e2df17727 100644 --- a/LibGit2Sharp/RepositoryInformation.cs +++ b/LibGit2Sharp/RepositoryInformation.cs @@ -1,5 +1,4 @@ -using System; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; namespace LibGit2Sharp { diff --git a/LibGit2Sharp/RepositoryOptions.cs b/LibGit2Sharp/RepositoryOptions.cs index 507288d6a..dfb06e335 100644 --- a/LibGit2Sharp/RepositoryOptions.cs +++ b/LibGit2Sharp/RepositoryOptions.cs @@ -25,5 +25,23 @@ public class RepositoryOptions /// /// public string IndexPath { get; set; } + + /// + /// Overrides the probed location of the Global configuration file of a repository. + /// + /// The path has either to lead to an existing valid configuration file, + /// or to a non existent configuration file which will be eventually created. + /// + /// + public string GlobalConfigurationLocation { get; set; } + + /// + /// Overrides the probed location of the System configuration file of a repository. + /// + /// The path has to lead to an existing valid configuration file, + /// or to a non existent configuration file which will be eventually created. + /// + /// + public string SystemConfigurationLocation { get; set; } } } diff --git a/LibGit2Sharp/TagAnnotation.cs b/LibGit2Sharp/TagAnnotation.cs index d52b394bb..86cec7ccd 100644 --- a/LibGit2Sharp/TagAnnotation.cs +++ b/LibGit2Sharp/TagAnnotation.cs @@ -1,5 +1,4 @@ -using System; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; using LibGit2Sharp.Core.Compat; using LibGit2Sharp.Core.Handles; diff --git a/LibGit2Sharp/Tree.cs b/LibGit2Sharp/Tree.cs index 4bd84714f..59b11527b 100644 --- a/LibGit2Sharp/Tree.cs +++ b/LibGit2Sharp/Tree.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Linq; using LibGit2Sharp.Core; @@ -62,6 +61,7 @@ private TreeEntry RetrieveFromPath(FilePath relativePath) string filename = posixPath.Split('/').Last(); TreeEntrySafeHandle handle = NativeMethods.git_tree_entry_byname(objectPtr, filename); + objectPtr.SafeDispose(); if (handle.IsInvalid) { @@ -101,19 +101,6 @@ public IEnumerable Blobs } } - - /// - /// Gets the s immediately under this . - /// - [Obsolete("This property will be removed in the next release. Please use Tree.Blobs instead.")] - public IEnumerable Files - { - get - { - return Blobs; - } - } - internal string Path { get { return path.Native; } diff --git a/LibGit2Sharp/TreeChanges.cs b/LibGit2Sharp/TreeChanges.cs index b4b3126fa..40147ebaa 100644 --- a/LibGit2Sharp/TreeChanges.cs +++ b/LibGit2Sharp/TreeChanges.cs @@ -41,9 +41,9 @@ internal TreeChanges(DiffListSafeHandle diff) Ensure.Success(NativeMethods.git_diff_print_patch(diff, IntPtr.Zero, PrintCallBack)); } - private int PrintCallBack(IntPtr data, GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, IntPtr contentlen) + private int PrintCallBack(IntPtr data, GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, uint contentlen) { - string formattedoutput = marshaler.NativeToString(content, contentlen.ToInt32()); + string formattedoutput = marshaler.NativeToString(content, contentlen); var currentFilePath = (string)marshaler.MarshalNativeToManaged(delta.NewFile.Path); AddLineChange(currentFilePath, lineorigin); diff --git a/LibGit2Sharp/TreeEntryChanges.cs b/LibGit2Sharp/TreeEntryChanges.cs index f19fbafaa..8f39e7363 100644 --- a/LibGit2Sharp/TreeEntryChanges.cs +++ b/LibGit2Sharp/TreeEntryChanges.cs @@ -1,5 +1,3 @@ -using System.Text; - namespace LibGit2Sharp { /// diff --git a/LibGit2Sharp/libgit2_hash.txt b/LibGit2Sharp/libgit2_hash.txt index 5a1dd268f..bbe030622 100644 --- a/LibGit2Sharp/libgit2_hash.txt +++ b/LibGit2Sharp/libgit2_hash.txt @@ -1 +1 @@ -7a361e93f39789e9523caeb3ef8754173165aab7 +4c977a61e598f2230e9902aa80cfea8e89d94f88 diff --git a/README.md b/README.md index 84f36648c..afe1d5430 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ More thorough information available in the [wiki](https://github.com/libgit2/lib ## Authors -The LibGit2Sharp [contributors](https://github.com/libgit2/libgit2sharp/contributors) + - **Code:** The LibGit2Sharp [contributors](https://github.com/libgit2/libgit2sharp/contributors) + - **Logo:** [Jason "blackant" Long](https://github.com/blackant) ## License diff --git a/build.libgit2sharp.sh b/build.libgit2sharp.sh index 99b85feac..5d67d5649 100644 --- a/build.libgit2sharp.sh +++ b/build.libgit2sharp.sh @@ -1,3 +1,19 @@ #!/bin/sh -xbuild CI-build.msbuild /t:Deploy \ No newline at end of file +PREVIOUS_LD=$LD_LIBRARY_PATH + +mkdir cmake-build && cd cmake-build + +cmake -DBUILD_SHARED_LIBS:BOOL=ON -DTHREADSAFE:BOOL=ON -DBUILD_CLAR:BOOL=OFF -DCMAKE_INSTALL_PREFIX=./libgit2-bin ../libgit2 +cmake --build . --target install + +LD_LIBRARY_PATH=$PWD/libgit2-bin/lib:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH + +cd .. + +echo $LD_LIBRARY_PATH +xbuild CI-build.msbuild /t:Deploy + +LD_LIBRARY_PATH=$PREVIOUS_LD +export LD_LIBRARY_PATH diff --git a/libgit2 b/libgit2 index 7a361e93f..4c977a61e 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit 7a361e93f39789e9523caeb3ef8754173165aab7 +Subproject commit 4c977a61e598f2230e9902aa80cfea8e89d94f88 diff --git a/nuget.package/LibGit2Sharp.nuspec b/nuget.package/LibGit2Sharp.nuspec index b32710a37..74c31d533 100644 --- a/nuget.package/LibGit2Sharp.nuspec +++ b/nuget.package/LibGit2Sharp.nuspec @@ -9,6 +9,7 @@ https://github.com/libgit2/libgit2sharp/ false $description$ + https://github.com/libgit2/libgit2sharp/raw/master/square-logo.png libgit2 git wrapper bindings API dvcs vcs diff --git a/square-logo.png b/square-logo.png new file mode 100644 index 000000000..b758c5bc1 Binary files /dev/null and b/square-logo.png differ