diff --git a/Lib/NativeBinaries/amd64/git2-9bbc8f3.dll b/Lib/NativeBinaries/amd64/git2-9bbc8f3.dll new file mode 100644 index 00000000..f162e6c6 Binary files /dev/null and b/Lib/NativeBinaries/amd64/git2-9bbc8f3.dll differ diff --git a/Lib/NativeBinaries/amd64/git2-9bbc8f3.pdb b/Lib/NativeBinaries/amd64/git2-9bbc8f3.pdb new file mode 100644 index 00000000..43f4171f Binary files /dev/null and b/Lib/NativeBinaries/amd64/git2-9bbc8f3.pdb differ diff --git a/Lib/NativeBinaries/amd64/git2-e0902fb.dll b/Lib/NativeBinaries/amd64/git2-e0902fb.dll deleted file mode 100644 index f4931dbd..00000000 Binary files a/Lib/NativeBinaries/amd64/git2-e0902fb.dll and /dev/null differ diff --git a/Lib/NativeBinaries/amd64/git2-e0902fb.pdb b/Lib/NativeBinaries/amd64/git2-e0902fb.pdb deleted file mode 100644 index bdef63b0..00000000 Binary files a/Lib/NativeBinaries/amd64/git2-e0902fb.pdb and /dev/null differ diff --git a/Lib/NativeBinaries/x86/git2-9bbc8f3.dll b/Lib/NativeBinaries/x86/git2-9bbc8f3.dll new file mode 100644 index 00000000..db04bb5b Binary files /dev/null and b/Lib/NativeBinaries/x86/git2-9bbc8f3.dll differ diff --git a/Lib/NativeBinaries/x86/git2-e0902fb.pdb b/Lib/NativeBinaries/x86/git2-9bbc8f3.pdb similarity index 51% rename from Lib/NativeBinaries/x86/git2-e0902fb.pdb rename to Lib/NativeBinaries/x86/git2-9bbc8f3.pdb index d466f239..89c4624f 100644 Binary files a/Lib/NativeBinaries/x86/git2-e0902fb.pdb and b/Lib/NativeBinaries/x86/git2-9bbc8f3.pdb differ diff --git a/Lib/NativeBinaries/x86/git2-e0902fb.dll b/Lib/NativeBinaries/x86/git2-e0902fb.dll deleted file mode 100644 index b0c55e6c..00000000 Binary files a/Lib/NativeBinaries/x86/git2-e0902fb.dll and /dev/null differ diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index c39a9658..225ea4ee 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -18,7 +18,7 @@ namespace LibGit2Sharp.Tests public void CanCreateBranch(string name) { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -39,8 +39,10 @@ namespace LibGit2Sharp.Tests Assert.NotNull(repo.Branches.SingleOrDefault(p => p.Name.Normalize() == name)); AssertRefLogEntry(repo, newBranch.CanonicalName, + "branch: Created from " + committish, + null, newBranch.Tip.Id, - "branch: Created from " + committish); + Constants.Identity, DateTimeOffset.Now); repo.Branches.Remove(newBranch.Name); Assert.Null(repo.Branches[name]); @@ -86,7 +88,7 @@ namespace LibGit2Sharp.Tests public void CanCreateBranchUsingAbbreviatedSha() { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions{ Identity = Constants.Identity })) { EnableRefLog(repo); @@ -98,8 +100,10 @@ namespace LibGit2Sharp.Tests Assert.Equal("be3563ae3f795b2b4353bcce3a527ad0a4f7f644", newBranch.Tip.Sha); AssertRefLogEntry(repo, newBranch.CanonicalName, + "branch: Created from " + committish, + null, newBranch.Tip.Id, - "branch: Created from " + committish); + Constants.Identity, DateTimeOffset.Now); } } @@ -109,7 +113,7 @@ namespace LibGit2Sharp.Tests public void CanCreateBranchFromImplicitHead(string headCommitOrBranchSpec) { string path = SandboxStandardTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -126,8 +130,10 @@ namespace LibGit2Sharp.Tests Assert.NotNull(repo.Branches.SingleOrDefault(p => p.Name == name)); AssertRefLogEntry(repo, newBranch.CanonicalName, + "branch: Created from " + headCommitOrBranchSpec, + null, newBranch.Tip.Id, - "branch: Created from " + headCommitOrBranchSpec); + Constants.Identity, DateTimeOffset.Now); } } @@ -137,7 +143,7 @@ namespace LibGit2Sharp.Tests public void CanCreateBranchFromExplicitHead(string headCommitOrBranchSpec) { string path = SandboxStandardTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -149,8 +155,10 @@ namespace LibGit2Sharp.Tests Assert.Equal("32eab9cb1f450b5fe7ab663462b77d7f4b703344", newBranch.Tip.Sha); AssertRefLogEntry(repo, newBranch.CanonicalName, + "branch: Created from HEAD", + null, newBranch.Tip.Id, - "branch: Created from " + headCommitOrBranchSpec); + Constants.Identity, DateTimeOffset.Now); } } @@ -158,7 +166,7 @@ namespace LibGit2Sharp.Tests public void CanCreateBranchFromCommit() { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -169,8 +177,10 @@ namespace LibGit2Sharp.Tests Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", newBranch.Tip.Sha); AssertRefLogEntry(repo, newBranch.CanonicalName, + "branch: Created from " + newBranch.Tip.Sha, + null, newBranch.Tip.Id, - "branch: Created from " + newBranch.Tip.Sha); + Constants.Identity, DateTimeOffset.Now); } } @@ -178,7 +188,7 @@ namespace LibGit2Sharp.Tests public void CanCreateBranchFromRevparseSpec() { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -190,8 +200,10 @@ namespace LibGit2Sharp.Tests Assert.Equal("9fd738e8f7967c078dceed8190330fc8648ee56a", newBranch.Tip.Sha); AssertRefLogEntry(repo, newBranch.CanonicalName, + "branch: Created from " + committish, + null, newBranch.Tip.Id, - "branch: Created from " + committish); + Constants.Identity, DateTimeOffset.Now); } } @@ -201,7 +213,7 @@ namespace LibGit2Sharp.Tests public void CreatingABranchFromATagPeelsToTheCommit(string committish) { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -212,8 +224,10 @@ namespace LibGit2Sharp.Tests Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", newBranch.Tip.Sha); AssertRefLogEntry(repo, newBranch.CanonicalName, + "branch: Created from " + committish, + null, newBranch.Tip.Id, - "branch: Created from " + committish); + Constants.Identity, DateTimeOffset.Now); } } @@ -559,7 +573,7 @@ namespace LibGit2Sharp.Tests { Branch master = repo.Branches["master"]; const string logMessage = "update target message"; - repo.Refs.UpdateTarget("refs/remotes/origin/master", "origin/test", Constants.Signature, logMessage); + repo.Refs.UpdateTarget("refs/remotes/origin/master", "origin/test", logMessage); Assert.True(master.IsTracking); Assert.NotNull(master.TrackedBranch); @@ -964,7 +978,7 @@ namespace LibGit2Sharp.Tests public void CanRenameABranch() { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -980,8 +994,10 @@ namespace LibGit2Sharp.Tests Assert.NotNull(repo.Branches["br3"]); AssertRefLogEntry(repo, newBranch.CanonicalName, + string.Format("branch: renamed {0} to {1}", br2.CanonicalName, newBranch.CanonicalName), + br2.Tip.Id, newBranch.Tip.Id, - string.Format("branch: renamed {0} to {1}", br2.CanonicalName, newBranch.CanonicalName)); + Constants.Identity, DateTimeOffset.Now); } } @@ -999,7 +1015,7 @@ namespace LibGit2Sharp.Tests public void CanRenameABranchWhileOverwritingAnExistingOne() { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -1021,9 +1037,10 @@ namespace LibGit2Sharp.Tests Assert.Equal(br2.Tip, newTest.Tip); AssertRefLogEntry(repo, newBranch.CanonicalName, - newBranch.Tip.Id, string.Format("branch: renamed {0} to {1}", br2.CanonicalName, newBranch.CanonicalName), - test.Tip.Id); + br2.Tip.Id, + newTest.Tip.Id, + Constants.Identity, DateTimeOffset.Now); } } @@ -1129,15 +1146,22 @@ namespace LibGit2Sharp.Tests public void CreatingABranchIncludesTheCorrectReflogEntries() { string path = SandboxStandardTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); var branch = repo.Branches.Add("foo", repo.Head.Tip); - AssertRefLogEntry(repo, branch.CanonicalName, branch.Tip.Id, - string.Format("branch: Created from {0}", repo.Head.Tip.Sha)); - branch = repo.Branches.Add("bar", repo.Head.Tip, null, "BAR"); - AssertRefLogEntry(repo, branch.CanonicalName, repo.Head.Tip.Id, "BAR"); + AssertRefLogEntry(repo, branch.CanonicalName, + string.Format("branch: Created from {0}", repo.Head.Tip.Sha), + null, branch.Tip.Id, + Constants.Identity, DateTimeOffset.Now); + + branch = repo.Branches.Add("bar", repo.Head.Tip); + + AssertRefLogEntry(repo, branch.CanonicalName, + "branch: Created from " + repo.Head.Tip.Sha, + null, repo.Head.Tip.Id, + Constants.Identity, DateTimeOffset.Now); } } @@ -1145,16 +1169,19 @@ namespace LibGit2Sharp.Tests public void RenamingABranchIncludesTheCorrectReflogEntries() { string path = SandboxStandardTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); var master = repo.Branches["master"]; var newMaster = repo.Branches.Rename(master, "new-master"); - AssertRefLogEntry(repo, newMaster.CanonicalName, newMaster.Tip.Id, - "branch: renamed refs/heads/master to refs/heads/new-master"); + AssertRefLogEntry(repo, newMaster.CanonicalName, "branch: renamed refs/heads/master to refs/heads/new-master", + newMaster.Tip.Id, newMaster.Tip.Id, + Constants.Identity, DateTimeOffset.Now); - newMaster = repo.Branches.Rename(newMaster, "new-master2", null, "MOVE"); - AssertRefLogEntry(repo, newMaster.CanonicalName, newMaster.Tip.Id, "MOVE"); + var newMaster2 = repo.Branches.Rename(newMaster, "new-master2"); + AssertRefLogEntry(repo, newMaster2.CanonicalName, "branch: renamed refs/heads/new-master to refs/heads/new-master2", + newMaster.Tip.Id, newMaster2.Tip.Id, + Constants.Identity, DateTimeOffset.Now); } } } diff --git a/LibGit2Sharp.Tests/CheckoutFixture.cs b/LibGit2Sharp.Tests/CheckoutFixture.cs index 77809d58..448ae2c3 100644 --- a/LibGit2Sharp.Tests/CheckoutFixture.cs +++ b/LibGit2Sharp.Tests/CheckoutFixture.cs @@ -779,7 +779,7 @@ namespace LibGit2Sharp.Tests public void CheckoutBranchFromDetachedHead() { string path = SandboxStandardTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions{ Identity = Constants.Identity })) { // Set the working directory to the current head ResetAndCleanWorkingDirectory(repo); @@ -789,12 +789,12 @@ namespace LibGit2Sharp.Tests Assert.True(repo.Info.IsHeadDetached); - Branch newHead = repo.Checkout(repo.Branches["master"], Constants.Signature); + Branch newHead = repo.Checkout(repo.Branches["master"]); // Assert reflog entry is created - AssertRefLogEntry(repo, "HEAD", newHead.Tip.Id, + AssertRefLogEntry(repo, "HEAD", string.Format("checkout: moving from {0} to {1}", initialHead.Tip.Sha, newHead.Name), - initialHead.Tip.Id, Constants.Signature); + initialHead.Tip.Id, newHead.Tip.Id, Constants.Identity, DateTimeOffset.Now); } } @@ -847,7 +847,7 @@ namespace LibGit2Sharp.Tests public void CheckoutCurrentReference() { string path = SandboxStandardTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { Branch master = repo.Branches["master"]; Assert.True(master.IsCurrentRepositoryHead); @@ -866,8 +866,8 @@ namespace LibGit2Sharp.Tests repo.Checkout(master.Tip.Sha); Assert.True(repo.Info.IsHeadDetached); - AssertRefLogEntry(repo, "HEAD", master.Tip.Id, - string.Format("checkout: moving from master to {0}", master.Tip.Sha), master.Tip.Id); + AssertRefLogEntry(repo, "HEAD", + string.Format("checkout: moving from master to {0}", master.Tip.Sha), master.Tip.Id, master.Tip.Id, Constants.Identity, DateTimeOffset.Now); // Checkout detached "HEAD" => nothing should happen reflogEntriesCount = repo.Refs.Log(repo.Refs.Head).Count(); diff --git a/LibGit2Sharp.Tests/CommitFixture.cs b/LibGit2Sharp.Tests/CommitFixture.cs index e86d7da3..18fec45b 100644 --- a/LibGit2Sharp.Tests/CommitFixture.cs +++ b/LibGit2Sharp.Tests/CommitFixture.cs @@ -661,7 +661,9 @@ namespace LibGit2Sharp.Tests { string repoPath = InitNewRepository(); - using (var repo = new Repository(repoPath)) + var identity = Constants.Identity; + + using (var repo = new Repository(repoPath, new RepositoryOptions { Identity = identity })) { string dir = repo.Info.Path; Assert.True(Path.IsPathRooted(dir)); @@ -691,7 +693,13 @@ namespace LibGit2Sharp.Tests // Assert a reflog entry is created on HEAD Assert.Equal(1, repo.Refs.Log("HEAD").Count()); var reflogEntry = repo.Refs.Log("HEAD").First(); - Assert.Equal(author, reflogEntry.Committer); + + Assert.Equal(identity.Name, reflogEntry.Committer.Name); + Assert.Equal(identity.Email, reflogEntry.Committer.Email); + + var now = DateTimeOffset.Now; + Assert.InRange(reflogEntry.Committer.When, now - TimeSpan.FromSeconds(1), now); + Assert.Equal(commit.Id, reflogEntry.To); Assert.Equal(ObjectId.Zero, reflogEntry.From); Assert.Equal(string.Format("commit (initial): {0}", shortMessage), reflogEntry.Message); @@ -805,7 +813,7 @@ namespace LibGit2Sharp.Tests public void CanAmendACommitWithMoreThanOneParent() { string path = SandboxStandardTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { var mergedCommit = repo.Lookup("be3563a"); Assert.NotNull(mergedCommit); @@ -822,10 +830,10 @@ namespace LibGit2Sharp.Tests AssertCommitHasBeenAmended(repo, amendedCommit, mergedCommit); AssertRefLogEntry(repo, "HEAD", - amendedCommit.Id, string.Format("commit (amend): {0}", commitMessage), mergedCommit.Id, - amendedCommit.Committer); + amendedCommit.Id, + Constants.Identity, DateTimeOffset.Now); } } diff --git a/LibGit2Sharp.Tests/PushFixture.cs b/LibGit2Sharp.Tests/PushFixture.cs index 88e932ad..10261d0b 100644 --- a/LibGit2Sharp.Tests/PushFixture.cs +++ b/LibGit2Sharp.Tests/PushFixture.cs @@ -98,7 +98,7 @@ namespace LibGit2Sharp.Tests // Create a new repository string localRepoPath = InitNewRepository(); - using (var localRepo = new Repository(localRepoPath)) + using (var localRepo = new Repository(localRepoPath, new RepositoryOptions { Identity = Constants.Identity })) { // Add a commit Commit first = AddCommitToRepo(localRepo); @@ -129,8 +129,9 @@ namespace LibGit2Sharp.Tests AssertRemoteHeadTipEquals(localRepo, second.Sha); AssertRefLogEntry(localRepo, "refs/remotes/origin/master", - localRepo.Head.Tip.Id, "update by push", - oldId); + "update by push", + oldId, localRepo.Head.Tip.Id, + Constants.Identity, DateTimeOffset.Now); } } diff --git a/LibGit2Sharp.Tests/ReferenceFixture.cs b/LibGit2Sharp.Tests/ReferenceFixture.cs index 4674ecef..07432632 100644 --- a/LibGit2Sharp.Tests/ReferenceFixture.cs +++ b/LibGit2Sharp.Tests/ReferenceFixture.cs @@ -22,7 +22,7 @@ namespace LibGit2Sharp.Tests const string name = "refs/heads/unit_test"; string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -35,8 +35,9 @@ namespace LibGit2Sharp.Tests Assert.NotNull(repo.Refs[name]); AssertRefLogEntry(repo, name, - newRef.ResolveToDirectReference().Target.Id, - "branch: Created from be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + "branch: Created from be3563ae3f795b2b4353bcce3a527ad0a4f7f644", + null, newRef.ResolveToDirectReference().Target.Id, Constants.Identity, DateTimeOffset.Now + ); } } @@ -47,11 +48,11 @@ namespace LibGit2Sharp.Tests const string logMessage = "Create new ref"; string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); - var newRef = (DirectReference)repo.Refs.Add(name, "master^1^2", Constants.Signature, logMessage); + var newRef = (DirectReference)repo.Refs.Add(name, "master^1^2", logMessage); Assert.NotNull(newRef); Assert.Equal(name, newRef.CanonicalName); Assert.NotNull(newRef.Target); @@ -59,9 +60,9 @@ namespace LibGit2Sharp.Tests Assert.Equal(newRef.Target.Sha, newRef.TargetIdentifier); Assert.NotNull(repo.Refs[name]); - AssertRefLogEntry(repo, name, - newRef.ResolveToDirectReference().Target.Id, - logMessage, committer: Constants.Signature); + AssertRefLogEntry(repo, name, logMessage, + null, newRef.ResolveToDirectReference().Target.Id, + Constants.Identity, DateTimeOffset.Now); } } @@ -106,7 +107,7 @@ namespace LibGit2Sharp.Tests var targetRef = repo.Refs[target]; - var newRef = repo.Refs.Add(name, targetRef, Constants.Signature, logMessage); + var newRef = repo.Refs.Add(name, targetRef, logMessage); AssertSymbolicRef(newRef, repo, target, name); Assert.Empty(repo.Refs.Log(newRef)); @@ -151,12 +152,12 @@ namespace LibGit2Sharp.Tests const string logMessage = "Create new ref"; string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); var oldRef = repo.Refs[name]; - var newRef = (DirectReference)repo.Refs.Add(name, target, Constants.Signature, logMessage, true); + var newRef = (DirectReference)repo.Refs.Add(name, target, logMessage, true); Assert.NotNull(newRef); Assert.Equal(name, newRef.CanonicalName); Assert.NotNull(newRef.Target); @@ -164,9 +165,9 @@ namespace LibGit2Sharp.Tests Assert.Equal(target, ((DirectReference)repo.Refs[name]).Target.Sha); AssertRefLogEntry(repo, name, - newRef.ResolveToDirectReference().Target.Id, logMessage, ((DirectReference)oldRef).Target.Id, - Constants.Signature); + newRef.ResolveToDirectReference().Target.Id, + Constants.Identity, DateTimeOffset.Now); } } @@ -178,22 +179,22 @@ namespace LibGit2Sharp.Tests const string logMessage = "Create new ref"; string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); var oldtarget = repo.Refs[name].ResolveToDirectReference().Target.Id; - var newRef = (SymbolicReference)repo.Refs.Add(name, target, Constants.Signature, logMessage, true); + var newRef = (SymbolicReference)repo.Refs.Add(name, target, logMessage, true); 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); - AssertRefLogEntry(repo, name, + AssertRefLogEntry(repo, name, logMessage, + oldtarget, newRef.ResolveToDirectReference().Target.Id, - logMessage, oldtarget, - Constants.Signature); + Constants.Identity, DateTimeOffset.Now); } } @@ -498,36 +499,35 @@ namespace LibGit2Sharp.Tests public void CanUpdateHeadWithEitherAnObjectIdOrAReference() { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); Reference head = repo.Refs.Head; Reference test = repo.Refs["refs/heads/test"]; - Reference direct = repo.Refs.UpdateTarget(head, new ObjectId(test.TargetIdentifier), Constants.Signature, null); + Reference direct = repo.Refs.UpdateTarget(head, new ObjectId(test.TargetIdentifier), null); Assert.True((direct is DirectReference)); Assert.Equal(test.TargetIdentifier, direct.TargetIdentifier); Assert.Equal(repo.Refs.Head, direct); var testTargetId = test.ResolveToDirectReference().Target.Id; - AssertRefLogEntry(repo, "HEAD", - testTargetId, - null, + AssertRefLogEntry(repo, "HEAD", null, head.ResolveToDirectReference().Target.Id, - Constants.Signature); + testTargetId, + Constants.Identity, DateTimeOffset.Now); const string secondLogMessage = "second update target message"; - Reference symref = repo.Refs.UpdateTarget(head, test, Constants.Signature, secondLogMessage); + Reference symref = repo.Refs.UpdateTarget(head, test, secondLogMessage); Assert.True((symref is SymbolicReference)); Assert.Equal(test.CanonicalName, symref.TargetIdentifier); Assert.Equal(repo.Refs.Head, symref); AssertRefLogEntry(repo, "HEAD", - testTargetId, secondLogMessage, testTargetId, - Constants.Signature); + testTargetId, + Constants.Identity, DateTimeOffset.Now); } } @@ -535,7 +535,7 @@ namespace LibGit2Sharp.Tests public void CanUpdateTargetOfADirectReferenceWithARevparseSpec() { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { EnableRefLog(repo); @@ -545,7 +545,7 @@ namespace LibGit2Sharp.Tests var @from = master.Target.Id; const string logMessage = "update target message"; - var newRef = (DirectReference)repo.Refs.UpdateTarget(master, "master^1^2", Constants.Signature, logMessage); + var newRef = (DirectReference)repo.Refs.UpdateTarget(master, "master^1^2", logMessage); Assert.NotNull(newRef); Assert.Equal(name, newRef.CanonicalName); Assert.NotNull(newRef.Target); @@ -554,10 +554,10 @@ namespace LibGit2Sharp.Tests Assert.NotNull(repo.Refs[name]); AssertRefLogEntry(repo, name, - newRef.Target.Id, logMessage, @from, - Constants.Signature); + newRef.Target.Id, + Constants.Identity, DateTimeOffset.Now); } } @@ -648,7 +648,7 @@ namespace LibGit2Sharp.Tests public void CanRenameAReferenceToADifferentReferenceHierarchy() { string path = SandboxBareTestRepo(); - using (var repo = new Repository(path)) + using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity })) { const string oldName = "refs/tags/test"; const string newName = "refs/atic/tagtest"; @@ -662,8 +662,11 @@ namespace LibGit2Sharp.Tests Assert.Equal(newName, renamed.CanonicalName); Assert.Equal(oldId, renamed.ResolveToDirectReference().Target.Id); - AssertRefLogEntry(repo, newName, renamed.ResolveToDirectReference().Target.Id, - string.Format("reference: renamed {0} to {1}", oldName, newName)); + AssertRefLogEntry(repo, newName, + string.Format("reference: renamed {0} to {1}", oldName, newName), + oldId, + renamed.ResolveToDirectReference().Target.Id, + Constants.Identity, DateTimeOffset.Now); } } diff --git a/LibGit2Sharp.Tests/ReflogFixture.cs b/LibGit2Sharp.Tests/ReflogFixture.cs index cda56e9c..88785d67 100644 --- a/LibGit2Sharp.Tests/ReflogFixture.cs +++ b/LibGit2Sharp.Tests/ReflogFixture.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using LibGit2Sharp.Tests.TestHelpers; using Xunit; @@ -56,7 +57,9 @@ namespace LibGit2Sharp.Tests { string repoPath = InitNewRepository(); - using (var repo = new Repository(repoPath)) + var identity = Constants.Identity; + + using (var repo = new Repository(repoPath, new RepositoryOptions{ Identity = identity })) { // setup refs as HEAD => unit_test => master var newRef = repo.Refs.Add("refs/heads/unit_test", "refs/heads/master"); @@ -74,14 +77,26 @@ namespace LibGit2Sharp.Tests // Assert a reflog entry is created on HEAD Assert.Equal(1, repo.Refs.Log("HEAD").Count()); var reflogEntry = repo.Refs.Log("HEAD").First(); - Assert.Equal(author, reflogEntry.Committer); + + Assert.Equal(identity.Name, reflogEntry.Committer.Name); + Assert.Equal(identity.Email, reflogEntry.Committer.Email); + + var now = DateTimeOffset.Now; + Assert.InRange(reflogEntry.Committer.When, now - TimeSpan.FromSeconds(1), now); + Assert.Equal(commit.Id, reflogEntry.To); Assert.Equal(ObjectId.Zero, reflogEntry.From); // Assert the same reflog entry is created on refs/heads/master Assert.Equal(1, repo.Refs.Log("refs/heads/master").Count()); reflogEntry = repo.Refs.Log("HEAD").First(); - Assert.Equal(author, reflogEntry.Committer); + + Assert.Equal(identity.Name, reflogEntry.Committer.Name); + Assert.Equal(identity.Email, reflogEntry.Committer.Email); + + now = DateTimeOffset.Now; + Assert.InRange(reflogEntry.Committer.When, now - TimeSpan.FromSeconds(1), now); + Assert.Equal(commit.Id, reflogEntry.To); Assert.Equal(ObjectId.Zero, reflogEntry.From); @@ -116,7 +131,9 @@ namespace LibGit2Sharp.Tests { string repoPath = SandboxStandardTestRepo(); - using (var repo = new Repository(repoPath)) + var identity = Constants.Identity; + + using (var repo = new Repository(repoPath, new RepositoryOptions { Identity = identity })) { Assert.False(repo.Info.IsHeadDetached); @@ -134,7 +151,13 @@ namespace LibGit2Sharp.Tests // Assert a reflog entry is created on HEAD var reflogEntry = repo.Refs.Log("HEAD").First(); - Assert.Equal(author, reflogEntry.Committer); + + Assert.Equal(identity.Name, reflogEntry.Committer.Name); + Assert.Equal(identity.Email, reflogEntry.Committer.Email); + + var now = DateTimeOffset.Now; + Assert.InRange(reflogEntry.Committer.When, now - TimeSpan.FromSeconds(1), now); + Assert.Equal(commit.Id, reflogEntry.To); Assert.Equal(string.Format("commit: {0}", commitMessage), repo.Refs.Log("HEAD").First().Message); } @@ -174,7 +197,7 @@ namespace LibGit2Sharp.Tests public void UnsignedMethodsWriteCorrectlyToTheReflog() { var repoPath = InitNewRepository(true); - using (var repo = new Repository(repoPath)) + using (var repo = new Repository(repoPath, new RepositoryOptions{ Identity = Constants.Identity })) { EnableRefLog(repo); @@ -184,7 +207,7 @@ namespace LibGit2Sharp.Tests tree, Enumerable.Empty(), false); var direct = repo.Refs.Add("refs/heads/direct", commit.Id); - AssertRefLogEntry(repo, direct.CanonicalName, direct.ResolveToDirectReference().Target.Id, null); + AssertRefLogEntry(repo, direct.CanonicalName, null, null, direct.ResolveToDirectReference().Target.Id, Constants.Identity, DateTimeOffset.Now); var symbolic = repo.Refs.Add("refs/heads/symbolic", direct); Assert.Empty(repo.Refs.Log(symbolic)); // creation of symbolic refs doesn't update the reflog diff --git a/LibGit2Sharp.Tests/ResetHeadFixture.cs b/LibGit2Sharp.Tests/ResetHeadFixture.cs index b1cfda8d..a6132ec1 100644 --- a/LibGit2Sharp.Tests/ResetHeadFixture.cs +++ b/LibGit2Sharp.Tests/ResetHeadFixture.cs @@ -94,7 +94,7 @@ namespace LibGit2Sharp.Tests { string repoPath = InitNewRepository(); - using (var repo = new Repository(repoPath)) + using (var repo = new Repository(repoPath, new RepositoryOptions{ Identity = Constants.Identity })) { FeedTheRepository(repo); @@ -118,38 +118,40 @@ namespace LibGit2Sharp.Tests Assert.Equal(FileStatus.Staged, repo.RetrieveStatus("a.txt")); AssertRefLogEntry(repo, "HEAD", - tag.Target.Id, string.Format("reset: moving to {0}", tag.Target.Sha), - oldHeadId); + oldHeadId, + tag.Target.Id, + Constants.Identity, DateTimeOffset.Now); if (!shouldHeadBeDetached) { AssertRefLogEntry(repo, branch.CanonicalName, - tag.Target.Id, string.Format("reset: moving to {0}", tag.Target.Sha), - oldHeadId); + oldHeadId, + tag.Target.Id, + Constants.Identity, DateTimeOffset.Now); } /* Reset --soft the Head to a commit through its sha */ - repo.Reset(ResetMode.Soft, branch.Tip.Sha, Constants.Signature, "FOO"); + repo.Reset(ResetMode.Soft, branch.Tip.Sha); Assert.Equal(expectedHeadName, repo.Head.Name); Assert.Equal(branch.Tip.Sha, repo.Head.Tip.Sha); Assert.Equal(FileStatus.Unaltered, repo.RetrieveStatus("a.txt")); AssertRefLogEntry(repo, "HEAD", - branch.Tip.Id, - "FOO", + string.Format("reset: moving to {0}", branch.Tip.Sha), tag.Target.Id, - Constants.Signature); + branch.Tip.Id, + Constants.Identity, DateTimeOffset.Now); if (!shouldHeadBeDetached) { AssertRefLogEntry(repo, branch.CanonicalName, - branch.Tip.Id, - "FOO", + string.Format("reset: moving to {0}", branch.Tip.Sha), tag.Target.Id, - Constants.Signature); + branch.Tip.Id, + Constants.Identity, DateTimeOffset.Now); } } } @@ -178,7 +180,7 @@ namespace LibGit2Sharp.Tests { string repoPath = InitNewRepository(); - using (var repo = new Repository(repoPath)) + using (var repo = new Repository(repoPath, new RepositoryOptions { Identity = Constants.Identity })) { FeedTheRepository(repo); @@ -191,14 +193,16 @@ namespace LibGit2Sharp.Tests Assert.Equal(FileStatus.Modified, repo.RetrieveStatus("a.txt")); AssertRefLogEntry(repo, "HEAD", - tag.Target.Id, string.Format("reset: moving to {0}", tag.Target.Sha), - oldHeadId); + oldHeadId, + tag.Target.Id, + Constants.Identity, DateTimeOffset.Now); AssertRefLogEntry(repo, "refs/heads/mybranch", - tag.Target.Id, string.Format("reset: moving to {0}", tag.Target.Sha), - oldHeadId); + oldHeadId, + tag.Target.Id, + Constants.Identity, DateTimeOffset.Now); } } diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index 63398fc4..a7cc1a58 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -405,8 +405,8 @@ namespace LibGit2Sharp.Tests.TestHelpers } protected static void AssertRefLogEntry(IRepository repo, string canonicalName, - ObjectId to, string message, ObjectId @from = null, - Signature committer = null) + string message, ObjectId @from, ObjectId to, + Identity committer, DateTimeOffset when) { var reflogEntry = repo.Refs.Log(canonicalName).First(); @@ -414,9 +414,8 @@ namespace LibGit2Sharp.Tests.TestHelpers Assert.Equal(message, reflogEntry.Message); Assert.Equal(@from ?? ObjectId.Zero, reflogEntry.From); - committer = committer ?? repo.Config.BuildSignature(DateTimeOffset.Now); Assert.Equal(committer.Email, reflogEntry.Committer.Email); - Assert.InRange(reflogEntry.Committer.When, committer.When - TimeSpan.FromSeconds(5), committer.When); + Assert.InRange(reflogEntry.Committer.When, when - TimeSpan.FromSeconds(5), when); } protected static void EnableRefLog(IRepository repository, bool enable = true) diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs index 929661fe..a00934d4 100644 --- a/LibGit2Sharp/BranchCollection.cs +++ b/LibGit2Sharp/BranchCollection.cs @@ -110,39 +110,20 @@ namespace LibGit2Sharp /// Create a new local branch with the specified name /// /// The name of the branch. - /// The target commit. - /// Identity used for updating the reflog - /// Message added to the reflog. If null, the default is "branch: Created from [sha]". + /// Revparse spec for the target commit. /// True to allow silent overwriting a potentially existing branch, false otherwise. /// A new . - public virtual Branch Add(string name, Commit commit, Signature signature, string logMessage = null, bool allowOverwrite = false) + public virtual Branch Add(string name, string committish, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNull(commit, "commit"); + Ensure.ArgumentNotNullOrEmptyString(committish, "committish"); - if (logMessage == null) - { - logMessage = "branch: Created from " + commit.Id; - } - - using (Proxy.git_branch_create(repo.Handle, name, commit.Id, allowOverwrite, signature.OrDefault(repo.Config), logMessage)) {} + using (Proxy.git_branch_create_from_annotated(repo.Handle, name, committish, allowOverwrite)) { } var branch = this[ShortToLocalName(name)]; return branch; } - /// - /// Create a new local branch with the specified name, using the default reflog message - /// - /// The name of the branch. - /// The target commit. - /// True to allow silent overwriting a potentially existing branch, false otherwise. - /// A new . - public virtual Branch Add(string name, Commit commit, bool allowOverwrite = false) - { - return Add(name, commit, null, null, allowOverwrite); - } - /// /// Deletes the specified branch. /// @@ -162,11 +143,9 @@ namespace LibGit2Sharp /// /// The current local branch. /// The new name the existing branch should bear. - /// Identity used for updating the reflog - /// Message added to the reflog. If null, the default is "branch: renamed [old] to [new]". /// True to allow silent overwriting a potentially existing branch, false otherwise. /// A new . - public virtual Branch Rename(Branch branch, string newName, Signature signature, string logMessage = null, bool allowOverwrite = false) + public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite = false) { Ensure.ArgumentNotNull(branch, "branch"); Ensure.ArgumentNotNullOrEmptyString(newName, "newName"); @@ -178,15 +157,9 @@ namespace LibGit2Sharp "Cannot rename branch '{0}'. It's a remote tracking branch.", branch.Name)); } - if (logMessage == null) - { - logMessage = string.Format(CultureInfo.InvariantCulture, - "branch: renamed {0} to {1}", branch.CanonicalName, Reference.LocalBranchPrefix + newName); - } - using (ReferenceSafeHandle referencePtr = repo.Refs.RetrieveReferencePtr(Reference.LocalBranchPrefix + branch.Name)) { - using (Proxy.git_branch_move(referencePtr, newName, allowOverwrite, signature.OrDefault(repo.Config), logMessage)) + using (Proxy.git_branch_move(referencePtr, newName, allowOverwrite)) { } } @@ -195,18 +168,6 @@ namespace LibGit2Sharp return newBranch; } - /// - /// Rename an existing local branch, using the default reflog message - /// - /// The current local branch. - /// The new name the existing branch should bear. - /// True to allow silent overwriting a potentially existing branch, false otherwise. - /// A new . - public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite = false) - { - return Rename(branch, newName, null, null, allowOverwrite); - } - /// /// Update properties of a branch. /// diff --git a/LibGit2Sharp/BranchCollectionExtensions.cs b/LibGit2Sharp/BranchCollectionExtensions.cs index f352099d..cea02c7a 100644 --- a/LibGit2Sharp/BranchCollectionExtensions.cs +++ b/LibGit2Sharp/BranchCollectionExtensions.cs @@ -7,51 +7,22 @@ namespace LibGit2Sharp /// public static class BranchCollectionExtensions { - /// - /// Create a new local branch with the specified name, using the default reflog message - /// - /// The name of the branch. - /// Revparse spec for the target commit. - /// True to allow silent overwriting a potentially existing branch, false otherwise. - /// The being worked with. - /// A new . - public static Branch Add(this BranchCollection branches, string name, string committish, bool allowOverwrite = false) - { - return Add(branches, name, committish, null, null, allowOverwrite); - } - /// /// Create a new local branch with the specified name /// /// The being worked with. /// The name of the branch. - /// Revparse spec for the target commit. - /// The identity used for updating the reflog - /// The optional message to log in the + /// The target commit. /// True to allow silent overwriting a potentially existing branch, false otherwise. /// A new . - public static Branch Add(this BranchCollection branches, string name, string committish, Signature signature, - string logMessage = null, bool allowOverwrite = false) + public static Branch Add(this BranchCollection branches, string name, Commit commit, bool allowOverwrite = false) { - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNullOrEmptyString(committish, "committish"); + Ensure.ArgumentNotNull(commit, "commit"); - var commit = branches.repo.LookupCommit(committish); - - if (logMessage == null) - { - var createdFrom = committish != "HEAD" - ? committish - : branches.repo.Info.IsHeadDetached - ? commit.Sha - : branches.repo.Head.Name; - - logMessage = "branch: Created from " + createdFrom; - } - - return branches.Add(name, commit, signature, logMessage, allowOverwrite); + return branches.Add(name, commit.Sha, allowOverwrite); } + /// /// Deletes the branch with the specified name. /// diff --git a/LibGit2Sharp/CloneOptions.cs b/LibGit2Sharp/CloneOptions.cs index a4515684..98f529ef 100644 --- a/LibGit2Sharp/CloneOptions.cs +++ b/LibGit2Sharp/CloneOptions.cs @@ -50,7 +50,7 @@ namespace LibGit2Sharp get { return this.Checkout ? - CheckoutStrategy.GIT_CHECKOUT_SAFE_CREATE : + CheckoutStrategy.GIT_CHECKOUT_SAFE : CheckoutStrategy.GIT_CHECKOUT_NONE; } } diff --git a/LibGit2Sharp/Core/GitCheckoutOpts.cs b/LibGit2Sharp/Core/GitCheckoutOpts.cs index b3f2bd96..4416aa60 100644 --- a/LibGit2Sharp/Core/GitCheckoutOpts.cs +++ b/LibGit2Sharp/Core/GitCheckoutOpts.cs @@ -16,15 +16,15 @@ namespace LibGit2Sharp.Core /// GIT_CHECKOUT_SAFE = (1 << 0), - /// - /// Allow safe updates plus creation of missing files. - /// - GIT_CHECKOUT_SAFE_CREATE = (1 << 1), - /// /// Allow update of entries in working dir that are modified from HEAD. /// - GIT_CHECKOUT_FORCE = (1 << 2), + GIT_CHECKOUT_FORCE = (1 << 1), + + /// + /// Allow checkout to recreate missing files. + /// + GIT_CHECKOUT_RECREATE_MISSING = (1 << 2), /// /// Allow checkout to make safe updates even if conflicts are found @@ -48,6 +48,7 @@ namespace LibGit2Sharp.Core /// /// Normally checkout updates index entries as it goes; this stops that + /// Implies `GIT_CHECKOUT_DONT_WRITE_INDEX`. /// GIT_CHECKOUT_DONT_UPDATE_INDEX = (1 << 8), @@ -94,6 +95,18 @@ namespace LibGit2Sharp.Core /// GIT_CHECKOUT_CONFLICT_STYLE_DIFF3 = (1 << 21), + /// + /// Don't overwrite existing files or folders + /// + GIT_CHECKOUT_DONT_REMOVE_EXISTING = (1 << 22), + + /// + /// Normally checkout writes the index upon completion; this prevents that. + /// + GIT_CHECKOUT_DONT_WRITE_INDEX = (1 << 23), + + // THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED + /// /// Recursively checkout submodules with same options (NOT IMPLEMENTED) /// diff --git a/LibGit2Sharp/Core/GitConfigEntry.cs b/LibGit2Sharp/Core/GitConfigEntry.cs index d8bd3751..85d1669a 100644 --- a/LibGit2Sharp/Core/GitConfigEntry.cs +++ b/LibGit2Sharp/Core/GitConfigEntry.cs @@ -9,5 +9,7 @@ namespace LibGit2Sharp.Core public IntPtr namePtr; public IntPtr valuePtr; public uint level; + public IntPtr freePtr; + public IntPtr payloadPtr; } } diff --git a/LibGit2Sharp/Core/GitSubmoduleOptions.cs b/LibGit2Sharp/Core/GitSubmoduleOptions.cs index b26244e8..1b64aa1f 100644 --- a/LibGit2Sharp/Core/GitSubmoduleOptions.cs +++ b/LibGit2Sharp/Core/GitSubmoduleOptions.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace LibGit2Sharp.Core { @@ -13,7 +12,5 @@ namespace LibGit2Sharp.Core public GitRemoteCallbacks RemoteCallbacks; public CheckoutStrategy CloneCheckoutStrategy; - - public IntPtr Signature; } } diff --git a/LibGit2Sharp/Core/Handles/GitConfigEntryHandle.cs b/LibGit2Sharp/Core/Handles/GitConfigEntryHandle.cs index 3112ec31..677c5fbd 100644 --- a/LibGit2Sharp/Core/Handles/GitConfigEntryHandle.cs +++ b/LibGit2Sharp/Core/Handles/GitConfigEntryHandle.cs @@ -1,10 +1,16 @@ namespace LibGit2Sharp.Core.Handles { - internal class GitConfigEntryHandle : NotOwnedSafeHandleBase + internal class GitConfigEntryHandle : SafeHandleBase { public GitConfigEntry MarshalAsGitConfigEntry() { return handle.MarshalAs(); } + + protected override bool ReleaseHandleImpl() + { + Proxy.git_config_entry_free(handle); + return true; + } } } diff --git a/LibGit2Sharp/Core/HistoryRewriter.cs b/LibGit2Sharp/Core/HistoryRewriter.cs index 33c35c6f..15686ecc 100644 --- a/LibGit2Sharp/Core/HistoryRewriter.cs +++ b/LibGit2Sharp/Core/HistoryRewriter.cs @@ -108,7 +108,7 @@ namespace LibGit2Sharp.Core { return RewriteReference( sref, old => old.Target, RewriteReference, - (refs, old, target, sig, logMessage) => refs.UpdateTarget(old, target, sig, logMessage)); + (refs, old, target, logMessage) => refs.UpdateTarget(old, target, logMessage)); } var dref = reference as DirectReference; @@ -116,14 +116,14 @@ namespace LibGit2Sharp.Core { return RewriteReference( dref, old => old.Target, RewriteTarget, - (refs, old, target, sig, logMessage) => refs.UpdateTarget(old, target.Id, sig, logMessage)); + (refs, old, target, logMessage) => refs.UpdateTarget(old, target.Id, logMessage)); } return reference; } private delegate Reference ReferenceUpdater( - ReferenceCollection refs, TRef origRef, TTarget origTarget, Signature signature, string logMessage) + ReferenceCollection refs, TRef origRef, TTarget origTarget, string logMessage) where TRef : Reference where TTarget : class; @@ -135,7 +135,6 @@ namespace LibGit2Sharp.Core where TTarget : class { var oldRefTarget = selectTarget(oldRef); - var signature = repo.Config.BuildSignature(DateTimeOffset.Now); string newRefName = oldRef.CanonicalName; if (oldRef.IsTag() && options.TagNameRewriter != null) @@ -163,26 +162,26 @@ namespace LibGit2Sharp.Core oldRef.CanonicalName, backupName)); } - repo.Refs.Add(backupName, oldRef.TargetIdentifier, signature, "filter-branch: backup"); + repo.Refs.Add(backupName, oldRef.TargetIdentifier, "filter-branch: backup"); rollbackActions.Enqueue(() => repo.Refs.Remove(backupName)); if (newTarget == null) { repo.Refs.Remove(oldRef); - rollbackActions.Enqueue(() => repo.Refs.Add(oldRef.CanonicalName, oldRef, signature, "filter-branch: abort", true)); + rollbackActions.Enqueue(() => repo.Refs.Add(oldRef.CanonicalName, oldRef, "filter-branch: abort", true)); return refMap[oldRef] = null; } - Reference newRef = updateTarget(repo.Refs, oldRef, newTarget, signature, "filter-branch: rewrite"); - rollbackActions.Enqueue(() => updateTarget(repo.Refs, oldRef, oldRefTarget, signature, "filter-branch: abort")); + Reference newRef = updateTarget(repo.Refs, oldRef, newTarget, "filter-branch: rewrite"); + rollbackActions.Enqueue(() => updateTarget(repo.Refs, oldRef, oldRefTarget, "filter-branch: abort")); if (newRef.CanonicalName == newRefName) { return refMap[oldRef] = newRef; } - var movedRef = repo.Refs.Rename(newRef, newRefName); - rollbackActions.Enqueue(() => repo.Refs.Rename(newRef, oldRef.CanonicalName)); + var movedRef = repo.Refs.Rename(newRef, newRefName, false); + rollbackActions.Enqueue(() => repo.Refs.Rename(newRef, oldRef.CanonicalName, false)); return refMap[oldRef] = movedRef; } diff --git a/LibGit2Sharp/Core/NativeDllName.cs b/LibGit2Sharp/Core/NativeDllName.cs index 5127c4e4..01f148a9 100644 --- a/LibGit2Sharp/Core/NativeDllName.cs +++ b/LibGit2Sharp/Core/NativeDllName.cs @@ -2,6 +2,6 @@ namespace LibGit2Sharp.Core { internal static class NativeDllName { - public const string Name = "git2-e0902fb"; + public const string Name = "git2-9bbc8f3"; } } diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 82afa397..a8fb1eac 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -146,14 +146,12 @@ namespace LibGit2Sharp.Core internal static extern Int64 git_blob_rawsize(GitObjectSafeHandle blob); [DllImport(libgit2)] - internal static extern int git_branch_create( + internal static extern int git_branch_create_from_annotated( out ReferenceSafeHandle ref_out, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string branch_name, - GitObjectSafeHandle target, // TODO: GitCommitSafeHandle? - [MarshalAs(UnmanagedType.Bool)] bool force, - SignatureSafeHandle signature, - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); + GitAnnotatedCommitHandle target, + [MarshalAs(UnmanagedType.Bool)] bool force); [DllImport(libgit2)] internal static extern int git_branch_delete( @@ -179,9 +177,7 @@ namespace LibGit2Sharp.Core out ReferenceSafeHandle ref_out, ReferenceSafeHandle reference, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string new_branch_name, - [MarshalAs(UnmanagedType.Bool)] bool force, - SignatureSafeHandle signature, - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); + [MarshalAs(UnmanagedType.Bool)] bool force); [DllImport(libgit2)] internal static extern int git_branch_next( @@ -290,6 +286,9 @@ namespace LibGit2Sharp.Core [DllImport(libgit2)] internal static extern void git_config_free(IntPtr cfg); + [DllImport(libgit2)] + internal static extern void git_config_entry_free(IntPtr entry); + [DllImport(libgit2)] internal static extern int git_config_get_entry( out GitConfigEntryHandle entry, @@ -637,6 +636,12 @@ namespace LibGit2Sharp.Core [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote_url, ref GitOid oid); + [DllImport(libgit2)] + internal static extern int git_annotated_commit_from_revspec( + out GitAnnotatedCommitHandle annotatedCommit, + RepositorySafeHandle repo, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string revspec); + [DllImport(libgit2)] internal static extern int git_annotated_commit_lookup( out GitAnnotatedCommitHandle annotatedCommit, @@ -823,7 +828,6 @@ namespace LibGit2Sharp.Core [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name, ref GitOid oid, [MarshalAs(UnmanagedType.Bool)] bool force, - SignatureSafeHandle signature, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); [DllImport(libgit2)] @@ -833,7 +837,6 @@ namespace LibGit2Sharp.Core [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string target, [MarshalAs(UnmanagedType.Bool)] bool force, - SignatureSafeHandle signature, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); internal delegate int ref_glob_callback( @@ -881,7 +884,6 @@ namespace LibGit2Sharp.Core ReferenceSafeHandle reference, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string newName, [MarshalAs(UnmanagedType.Bool)] bool force, - SignatureSafeHandle signature, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); [DllImport(libgit2)] @@ -889,7 +891,6 @@ namespace LibGit2Sharp.Core out ReferenceSafeHandle ref_out, ReferenceSafeHandle reference, ref GitOid id, - SignatureSafeHandle signature, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); [DllImport(libgit2)] @@ -897,7 +898,6 @@ namespace LibGit2Sharp.Core out ReferenceSafeHandle ref_out, ReferenceSafeHandle reference, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string target, - SignatureSafeHandle signature, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); [DllImport(libgit2)] @@ -1015,7 +1015,6 @@ namespace LibGit2Sharp.Core internal static extern int git_remote_fetch( RemoteSafeHandle remote, ref GitStrArray refspecs, - SignatureSafeHandle signature, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); [DllImport(libgit2)] @@ -1034,9 +1033,7 @@ namespace LibGit2Sharp.Core internal static extern int git_remote_push( RemoteSafeHandle remote, ref GitStrArray refSpecs, - GitPushOptions opts, - SignatureSafeHandle signature, - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string reflogMessage); + GitPushOptions opts); [DllImport(libgit2)] internal static extern UIntPtr git_remote_refspec_count(RemoteSafeHandle remote); @@ -1143,6 +1140,12 @@ namespace LibGit2Sharp.Core [DllImport(libgit2)] internal static extern int git_repository_head_unborn(RepositorySafeHandle repo); + [DllImport(libgit2)] + internal static extern int git_repository_ident( + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))] out string name, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))] out string email, + RepositorySafeHandle repo); + [DllImport(libgit2)] internal static extern int git_repository_index(out IndexSafeHandle index, RepositorySafeHandle repo); @@ -1200,6 +1203,13 @@ namespace LibGit2Sharp.Core RepositorySafeHandle repository, ConfigurationSafeHandle config); + [DllImport(libgit2)] + internal static extern int git_repository_set_ident( + RepositorySafeHandle repo, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string email); + + [DllImport(libgit2)] internal static extern void git_repository_set_index( RepositorySafeHandle repository, @@ -1214,16 +1224,17 @@ namespace LibGit2Sharp.Core [DllImport(libgit2)] internal static extern int git_repository_set_head_detached( RepositorySafeHandle repo, - ref GitOid commitish, - SignatureSafeHandle signature, - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); + ref GitOid commitish); + + [DllImport(libgit2)] + internal static extern int git_repository_set_head_detached_from_annotated( + RepositorySafeHandle repo, + GitAnnotatedCommitHandle commit); [DllImport(libgit2)] internal static extern int git_repository_set_head( RepositorySafeHandle repo, - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string refname, - SignatureSafeHandle signature, - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string refname); [DllImport(libgit2)] internal static extern int git_repository_state( @@ -1238,9 +1249,7 @@ namespace LibGit2Sharp.Core RepositorySafeHandle repo, GitObjectSafeHandle target, ResetMode reset_type, - ref GitCheckoutOpts opts, - SignatureSafeHandle signature, - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string log_message); + ref GitCheckoutOpts opts); [DllImport(libgit2)] internal static extern int git_revert( diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index 3076ddef..ab2f7ead 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -143,16 +143,18 @@ namespace LibGit2Sharp.Core #region git_branch_ - public static ReferenceSafeHandle git_branch_create(RepositorySafeHandle repo, string branch_name, ObjectId targetId, bool force, - Signature signature, string logMessage) + public static ReferenceSafeHandle git_branch_create_from_annotated(RepositorySafeHandle repo, string branch_name, string targetIdentifier, bool force) { using (ThreadAffinity()) - using (var osw = new ObjectSafeWrapper(targetId, repo)) - using (var sigHandle = signature.BuildHandle()) { ReferenceSafeHandle reference; - int res = NativeMethods.git_branch_create(out reference, repo, branch_name, osw.ObjectPtr, force, sigHandle, logMessage); - Ensure.ZeroResult(res); + + using (var annotatedCommit = git_annotated_commit_from_revspec(repo, targetIdentifier)) + { + int res = NativeMethods.git_branch_create_from_annotated(out reference, repo, branch_name, annotatedCommit, force); + Ensure.ZeroResult(res); + } + return reference; } } @@ -190,14 +192,12 @@ namespace LibGit2Sharp.Core NativeMethods.git_branch_iterator_free(iter); } - public static ReferenceSafeHandle git_branch_move(ReferenceSafeHandle reference, string new_branch_name, bool force, - Signature signature, string logMessage) + public static ReferenceSafeHandle git_branch_move(ReferenceSafeHandle reference, string new_branch_name, bool force) { using (ThreadAffinity()) - using (var sigHandle = signature.BuildHandle()) { ReferenceSafeHandle ref_out; - int res = NativeMethods.git_branch_move(out ref_out, reference, new_branch_name, force, sigHandle, logMessage); + int res = NativeMethods.git_branch_move(out ref_out, reference, new_branch_name, force); Ensure.ZeroResult(res); return ref_out; } @@ -433,27 +433,41 @@ namespace LibGit2Sharp.Core NativeMethods.git_config_free(config); } + public static void git_config_entry_free(IntPtr entry) + { + NativeMethods.git_config_entry_free(entry); + } + public static ConfigurationEntry git_config_get_entry(ConfigurationSafeHandle config, string key) { - GitConfigEntryHandle handle; + GitConfigEntryHandle handle = null; if (!configurationParser.ContainsKey(typeof(T))) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Generic Argument of type '{0}' is not supported.", typeof(T).FullName)); } - using (ThreadAffinity()) + GitConfigEntry entry; + + try { - var res = NativeMethods.git_config_get_entry(out handle, config, key); - if (res == (int)GitErrorCode.NotFound) + using (ThreadAffinity()) { - return null; + var res = NativeMethods.git_config_get_entry(out handle, config, key); + if (res == (int)GitErrorCode.NotFound) + { + return null; + } + + Ensure.ZeroResult(res); + + entry = handle.MarshalAsGitConfigEntry(); } - - Ensure.ZeroResult(res); } - - GitConfigEntry entry = handle.MarshalAsGitConfigEntry(); + finally + { + handle.SafeDispose(); + } return new ConfigurationEntry(LaxUtf8Marshaler.FromNative(entry.namePtr), (T)configurationParser[typeof(T)](LaxUtf8Marshaler.FromNative(entry.valuePtr)), @@ -1165,6 +1179,20 @@ namespace LibGit2Sharp.Core } } + public static GitAnnotatedCommitHandle git_annotated_commit_from_revspec(RepositorySafeHandle repo, string revspec) + { + using (ThreadAffinity()) + { + GitAnnotatedCommitHandle their_head; + + int res = NativeMethods.git_annotated_commit_from_revspec(out their_head, repo, revspec); + + Ensure.ZeroResult(res); + + return their_head; + } + } + public static ObjectId git_annotated_commit_id(GitAnnotatedCommitHandle mergeHead) { return NativeMethods.git_annotated_commit_id(mergeHead).MarshalAsObjectId(); @@ -1576,15 +1604,14 @@ namespace LibGit2Sharp.Core #region git_reference_ public static ReferenceSafeHandle git_reference_create(RepositorySafeHandle repo, string name, ObjectId targetId, bool allowOverwrite, - Signature signature, string logMessage) + string logMessage) { using (ThreadAffinity()) - using (var sigHandle = signature.BuildHandle()) { GitOid oid = targetId.Oid; ReferenceSafeHandle handle; - int res = NativeMethods.git_reference_create(out handle, repo, name, ref oid, allowOverwrite, sigHandle, logMessage); + int res = NativeMethods.git_reference_create(out handle, repo, name, ref oid, allowOverwrite, logMessage); Ensure.ZeroResult(res); return handle; @@ -1592,13 +1619,12 @@ namespace LibGit2Sharp.Core } public static ReferenceSafeHandle git_reference_symbolic_create(RepositorySafeHandle repo, string name, string target, bool allowOverwrite, - Signature signature, string logMessage) + string logMessage) { using (ThreadAffinity()) - using (var sigHandle = signature.BuildHandle()) { ReferenceSafeHandle handle; - int res = NativeMethods.git_reference_symbolic_create(out handle, repo, name, target, allowOverwrite, sigHandle, logMessage); + int res = NativeMethods.git_reference_symbolic_create(out handle, repo, name, target, allowOverwrite, logMessage); Ensure.ZeroResult(res); return handle; @@ -1684,43 +1710,40 @@ namespace LibGit2Sharp.Core } public static ReferenceSafeHandle git_reference_rename(ReferenceSafeHandle reference, string newName, bool allowOverwrite, - Signature signature, string logMessage) + string logMessage) { using (ThreadAffinity()) - using (var sigHandle = signature.BuildHandle()) { ReferenceSafeHandle ref_out; - int res = NativeMethods.git_reference_rename(out ref_out, reference, newName, allowOverwrite, sigHandle, logMessage); + int res = NativeMethods.git_reference_rename(out ref_out, reference, newName, allowOverwrite, logMessage); Ensure.ZeroResult(res); return ref_out; } } - public static ReferenceSafeHandle git_reference_set_target(ReferenceSafeHandle reference, ObjectId id, Signature signature, string logMessage) + public static ReferenceSafeHandle git_reference_set_target(ReferenceSafeHandle reference, ObjectId id, string logMessage) { using (ThreadAffinity()) - using (SignatureSafeHandle sigHandle = signature.BuildHandle()) { GitOid oid = id.Oid; ReferenceSafeHandle ref_out; - int res = NativeMethods.git_reference_set_target(out ref_out, reference, ref oid, sigHandle, logMessage); + int res = NativeMethods.git_reference_set_target(out ref_out, reference, ref oid, logMessage); Ensure.ZeroResult(res); return ref_out; } } - public static ReferenceSafeHandle git_reference_symbolic_set_target(ReferenceSafeHandle reference, string target, Signature signature, string logMessage) + public static ReferenceSafeHandle git_reference_symbolic_set_target(ReferenceSafeHandle reference, string target, string logMessage) { using (ThreadAffinity()) - using (SignatureSafeHandle sigHandle = signature.BuildHandle()) { ReferenceSafeHandle ref_out; - int res = NativeMethods.git_reference_symbolic_set_target(out ref_out, reference, target, sigHandle, logMessage); + int res = NativeMethods.git_reference_symbolic_set_target(out ref_out, reference, target, logMessage); Ensure.ZeroResult(res); return ref_out; @@ -1966,25 +1989,22 @@ namespace LibGit2Sharp.Core } } - public static void git_remote_push(RemoteSafeHandle remote, IEnumerable refSpecs, GitPushOptions opts, Signature signature, string reflogMessage) + public static void git_remote_push(RemoteSafeHandle remote, IEnumerable refSpecs, GitPushOptions opts) { using (ThreadAffinity()) { - using (var sigHandle = signature.BuildHandle()) + var array = new GitStrArrayManaged(); + + try { - var array = new GitStrArrayManaged(); + array = GitStrArrayManaged.BuildFrom(refSpecs.ToArray()); - try - { - array = GitStrArrayManaged.BuildFrom(refSpecs.ToArray()); - - int res = NativeMethods.git_remote_push(remote, ref array.Array, opts, sigHandle, reflogMessage); - Ensure.ZeroResult(res); - } - finally - { - array.Dispose(); - } + int res = NativeMethods.git_remote_push(remote, ref array.Array, opts); + Ensure.ZeroResult(res); + } + finally + { + array.Dispose(); } } } @@ -2037,7 +2057,7 @@ namespace LibGit2Sharp.Core Ensure.ZeroResult(res); } } - + public static void git_remote_set_pushurl(RemoteSafeHandle remote, string url) { using (ThreadAffinity()) @@ -2047,16 +2067,15 @@ namespace LibGit2Sharp.Core } } - public static void git_remote_fetch(RemoteSafeHandle remote, Signature signature, string logMessage) + public static void git_remote_fetch(RemoteSafeHandle remote, string logMessage) { using (ThreadAffinity()) - using (var sigHandle = signature.BuildHandle()) { var array = new GitStrArrayNative(); try { - int res = NativeMethods.git_remote_fetch(remote, ref array.Array, sigHandle, logMessage); + int res = NativeMethods.git_remote_fetch(remote, ref array.Array, logMessage); Ensure.ZeroResult(res); } finally @@ -2405,6 +2424,15 @@ namespace LibGit2Sharp.Core NativeMethods.git_repository_set_config(repo, config); } + public static void git_repository_set_ident(RepositorySafeHandle repo, string name, string email) + { + using (ThreadAffinity()) + { + int res = NativeMethods.git_repository_set_ident(repo, name, email); + Ensure.ZeroResult(res); + } + } + public static void git_repository_set_index(RepositorySafeHandle repo, IndexSafeHandle index) { NativeMethods.git_repository_set_index(repo, index); @@ -2434,25 +2462,30 @@ namespace LibGit2Sharp.Core return NativeMethods.git_repository_workdir(repo); } - public static void git_repository_set_head_detached(RepositorySafeHandle repo, ObjectId commitish, - Signature signature, string logMessage) + public static void git_repository_set_head_detached(RepositorySafeHandle repo, ObjectId commitish) { using (ThreadAffinity()) - using (var sigHandle = signature.BuildHandle()) { GitOid oid = commitish.Oid; - int res = NativeMethods.git_repository_set_head_detached(repo, ref oid, sigHandle, logMessage); + int res = NativeMethods.git_repository_set_head_detached(repo, ref oid); Ensure.ZeroResult(res); } } - public static void git_repository_set_head(RepositorySafeHandle repo, string refname, - Signature signature, string logMessage) + public static void git_repository_set_head_detached_from_annotated(RepositorySafeHandle repo, GitAnnotatedCommitHandle commit) { using (ThreadAffinity()) - using (var sigHandle = signature.BuildHandle()) { - int res = NativeMethods.git_repository_set_head(repo, refname, sigHandle, logMessage); + int res = NativeMethods.git_repository_set_head_detached_from_annotated(repo, commit); + Ensure.ZeroResult(res); + } + } + + public static void git_repository_set_head(RepositorySafeHandle repo, string refname) + { + using (ThreadAffinity()) + { + int res = NativeMethods.git_repository_set_head(repo, refname); Ensure.ZeroResult(res); } } @@ -2465,15 +2498,12 @@ namespace LibGit2Sharp.Core RepositorySafeHandle repo, ObjectId committishId, ResetMode resetKind, - ref GitCheckoutOpts checkoutOptions, - Signature signature, - string logMessage) + ref GitCheckoutOpts checkoutOptions) { using (ThreadAffinity()) using (var osw = new ObjectSafeWrapper(committishId, repo)) - using (var sigHandle = signature.BuildHandle()) { - int res = NativeMethods.git_reset(repo, osw.ObjectPtr, resetKind, ref checkoutOptions, sigHandle, logMessage); + int res = NativeMethods.git_reset(repo, osw.ObjectPtr, resetKind, ref checkoutOptions); Ensure.ZeroResult(res); } } diff --git a/LibGit2Sharp/IRepository.cs b/LibGit2Sharp/IRepository.cs index 1557d07e..4b0b56d8 100644 --- a/LibGit2Sharp/IRepository.cs +++ b/LibGit2Sharp/IRepository.cs @@ -78,9 +78,8 @@ namespace LibGit2Sharp /// /// The to check out. /// controlling checkout behavior. - /// Identity for use when updating the reflog. /// The that was checked out. - Branch Checkout(Branch branch, CheckoutOptions options, Signature signature); + Branch Checkout(Branch branch, CheckoutOptions options); /// /// Checkout the specified branch, reference or SHA. @@ -91,9 +90,8 @@ namespace LibGit2Sharp /// /// A revparse spec for the commit or branch to checkout. /// controlling checkout behavior. - /// Identity for use when updating the reflog. /// The that was checked out. - Branch Checkout(string committishOrBranchSpec, CheckoutOptions options, Signature signature); + Branch Checkout(string committishOrBranchSpec, CheckoutOptions options); /// /// Checkout the specified . @@ -103,9 +101,8 @@ namespace LibGit2Sharp /// /// The to check out. /// controlling checkout behavior. - /// Identity for use when updating the reflog. /// The that was checked out. - Branch Checkout(Commit commit, CheckoutOptions options, Signature signature); + Branch Checkout(Commit commit, CheckoutOptions options); /// /// Updates specifed paths in the index and working directory with the versions from the specified branch, reference, or SHA. @@ -166,9 +163,7 @@ namespace LibGit2Sharp /// /// Flavor of reset operation to perform. /// The target commit object. - /// Identity for use when updating the reflog. - /// Message to use when updating the reflog. - void Reset(ResetMode resetMode, Commit commit, Signature signature, string logMessage); + void Reset(ResetMode resetMode, Commit commit); /// /// Replaces entries in the with entries from the specified commit. diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 82ace6aa..3ca4a389 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -132,7 +132,6 @@ - diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index becdb916..49d80d3d 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -88,7 +88,7 @@ namespace LibGit2Sharp } } - static void DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, Signature signature, string logMessage) + static void DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, string logMessage) { if (options == null) { @@ -113,7 +113,7 @@ namespace LibGit2Sharp // GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords. Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); - Proxy.git_remote_fetch(remoteHandle, signature, logMessage); + Proxy.git_remote_fetch(remoteHandle, logMessage); } /// @@ -121,17 +121,15 @@ namespace LibGit2Sharp /// /// The remote to fetch /// controlling fetch behavior - /// Identity for use when updating the reflog. /// Message to use when updating the reflog. public virtual void Fetch(Remote remote, FetchOptions options = null, - Signature signature = null, string logMessage = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_lookup(repository.Handle, remote.Name, true)) { - DoFetch(remoteHandle, options, signature.OrDefault(repository.Config), logMessage); + DoFetch(remoteHandle, options, logMessage); } } @@ -141,10 +139,8 @@ namespace LibGit2Sharp /// The remote to fetch /// Refspecs to use, replacing the remote's fetch refspecs /// controlling fetch behavior - /// Identity for use when updating the reflog. /// Message to use when updating the reflog. public virtual void Fetch(Remote remote, IEnumerable refspecs, FetchOptions options = null, - Signature signature = null, string logMessage = null) { Ensure.ArgumentNotNull(remote, "remote"); @@ -154,7 +150,7 @@ namespace LibGit2Sharp { Proxy.git_remote_set_fetch_refspecs(remoteHandle, refspecs); - DoFetch(remoteHandle, options, signature.OrDefault(repository.Config), logMessage); + DoFetch(remoteHandle, options, logMessage); } } @@ -164,13 +160,11 @@ namespace LibGit2Sharp /// The url to fetch from /// The list of resfpecs to use /// controlling fetch behavior - /// Identity for use when updating the reflog. /// Message to use when updating the reflog. public virtual void Fetch( string url, IEnumerable refspecs, FetchOptions options = null, - Signature signature = null, string logMessage = null) { Ensure.ArgumentNotNull(url, "url"); @@ -180,7 +174,7 @@ namespace LibGit2Sharp { Proxy.git_remote_set_fetch_refspecs(remoteHandle, refspecs); - DoFetch(remoteHandle, options, signature.OrDefault(repository.Config), logMessage); + DoFetch(remoteHandle, options, logMessage); } } @@ -191,22 +185,18 @@ namespace LibGit2Sharp /// The source objectish to push. /// The reference to update on the remote. /// controlling push behavior - /// Identity for use when updating the reflog. - /// Message to use when updating the reflog. public virtual void Push( Remote remote, string objectish, string destinationSpec, - PushOptions pushOptions = null, - Signature signature = null, - string logMessage = null) + PushOptions pushOptions = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec); Push(remote, string.Format(CultureInfo.InvariantCulture, - "{0}:{1}", objectish, destinationSpec), pushOptions, signature, logMessage); + "{0}:{1}", objectish, destinationSpec), pushOptions); } /// @@ -215,19 +205,15 @@ namespace LibGit2Sharp /// The to push to. /// The pushRefSpec to push. /// controlling push behavior - /// Identity for use when updating the reflog. - /// Message to use when updating the reflog. public virtual void Push( Remote remote, string pushRefSpec, - PushOptions pushOptions = null, - Signature signature = null, - string logMessage = null) + PushOptions pushOptions = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); - Push(remote, new[] { pushRefSpec }, pushOptions, signature, logMessage); + Push(remote, new[] { pushRefSpec }, pushOptions); } /// @@ -236,14 +222,10 @@ namespace LibGit2Sharp /// The to push to. /// The pushRefSpecs to push. /// controlling push behavior - /// Identity for use when updating the reflog. - /// Message to use when updating the reflog. public virtual void Push( Remote remote, IEnumerable pushRefSpecs, - PushOptions pushOptions = null, - Signature signature = null, - string logMessage = null) + PushOptions pushOptions = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); @@ -269,12 +251,11 @@ namespace LibGit2Sharp try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); - Proxy.git_remote_push(remoteHandle, pushRefSpecs, + Proxy.git_remote_push(remoteHandle, pushRefSpecs, new GitPushOptions() { PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism - }, - signature.OrDefault(repository.Config), logMessage); + }); } finally { diff --git a/LibGit2Sharp/ReferenceCollection.cs b/LibGit2Sharp/ReferenceCollection.cs index a564e82b..e3dc68c8 100644 --- a/LibGit2Sharp/ReferenceCollection.cs +++ b/LibGit2Sharp/ReferenceCollection.cs @@ -71,16 +71,15 @@ namespace LibGit2Sharp /// /// The canonical name of the reference to create. /// Id of the target object. - /// Identity used for updating the reflog. /// The optional message to log in the when adding the /// True to allow silent overwriting a potentially existing reference, false otherwise. /// A new . - public virtual DirectReference Add(string name, ObjectId targetId, Signature signature, string logMessage, bool allowOverwrite = false) + public virtual DirectReference Add(string name, ObjectId targetId, string logMessage, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(targetId, "targetId"); - using (ReferenceSafeHandle handle = Proxy.git_reference_create(repo.Handle, name, targetId, allowOverwrite, signature.OrDefault(repo.Config), logMessage)) + using (ReferenceSafeHandle handle = Proxy.git_reference_create(repo.Handle, name, targetId, allowOverwrite, logMessage)) { return (DirectReference)Reference.BuildFromPtr(handle, repo); } @@ -95,7 +94,7 @@ namespace LibGit2Sharp /// A new . public virtual DirectReference Add(string name, ObjectId targetId, bool allowOverwrite = false) { - return Add(name, targetId, null, null, allowOverwrite); + return Add(name, targetId, null, allowOverwrite); } /// @@ -103,17 +102,16 @@ namespace LibGit2Sharp /// /// The canonical name of the reference to create. /// The target reference. - /// Identity used for updating the reflog. /// The optional message to log in the when adding the /// True to allow silent overwriting a potentially existing reference, false otherwise. /// A new . - public virtual SymbolicReference Add(string name, Reference targetRef, Signature signature, string logMessage, bool allowOverwrite = false) + public virtual SymbolicReference Add(string name, Reference targetRef, string logMessage, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(targetRef, "targetRef"); using (ReferenceSafeHandle handle = Proxy.git_reference_symbolic_create(repo.Handle, name, targetRef.CanonicalName, - allowOverwrite, signature.OrDefault(repo.Config), logMessage)) + allowOverwrite, logMessage)) { return (SymbolicReference)Reference.BuildFromPtr(handle, repo); } @@ -128,7 +126,7 @@ namespace LibGit2Sharp /// A new . public virtual SymbolicReference Add(string name, Reference targetRef, bool allowOverwrite = false) { - return Add(name, targetRef, null, null, allowOverwrite); + return Add(name, targetRef, null, allowOverwrite); } /// @@ -147,11 +145,10 @@ namespace LibGit2Sharp /// /// The reference to rename. /// The new canonical name. - /// Identity used for updating the reflog. /// Message added to the reflog. /// True to allow silent overwriting a potentially existing reference, false otherwise. /// A new . - public virtual Reference Rename(Reference reference, string newName, Signature signature, string logMessage = null, bool allowOverwrite = false) + public virtual Reference Rename(Reference reference, string newName, string logMessage = null, bool allowOverwrite = false) { Ensure.ArgumentNotNull(reference, "reference"); Ensure.ArgumentNotNullOrEmptyString(newName, "newName"); @@ -163,7 +160,7 @@ namespace LibGit2Sharp } using (ReferenceSafeHandle referencePtr = RetrieveReferencePtr(reference.CanonicalName)) - using (ReferenceSafeHandle handle = Proxy.git_reference_rename(referencePtr, newName, allowOverwrite, signature.OrDefault(repo.Config), logMessage)) + using (ReferenceSafeHandle handle = Proxy.git_reference_rename(referencePtr, newName, allowOverwrite, logMessage)) { return Reference.BuildFromPtr(handle, repo); } @@ -178,7 +175,7 @@ namespace LibGit2Sharp /// A new . public virtual Reference Rename(Reference reference, string newName, bool allowOverwrite = false) { - return Rename(reference, newName, null, null, allowOverwrite); + return Rename(reference, newName, null, allowOverwrite); } internal T Resolve(string name) where T : Reference @@ -196,23 +193,25 @@ namespace LibGit2Sharp /// /// The direct reference which target should be updated. /// The new target. - /// The identity used for updating the reflog. /// The optional message to log in the of the reference /// A new . - public virtual Reference UpdateTarget(Reference directRef, ObjectId targetId, Signature signature, string logMessage) + public virtual Reference UpdateTarget(Reference directRef, ObjectId targetId, string logMessage) { Ensure.ArgumentNotNull(directRef, "directRef"); Ensure.ArgumentNotNull(targetId, "targetId"); - signature = signature.OrDefault(repo.Config); - if (directRef.CanonicalName == "HEAD") { - return UpdateHeadTarget(targetId, signature, logMessage); + return UpdateHeadTarget(targetId, logMessage); } + return UpdateDirectReferenceTarget(directRef, targetId, logMessage); + } + + private Reference UpdateDirectReferenceTarget(Reference directRef, ObjectId targetId, string logMessage) + { using (ReferenceSafeHandle referencePtr = RetrieveReferencePtr(directRef.CanonicalName)) - using (ReferenceSafeHandle handle = Proxy.git_reference_set_target(referencePtr, targetId, signature, logMessage)) + using (ReferenceSafeHandle handle = Proxy.git_reference_set_target(referencePtr, targetId, logMessage)) { return Reference.BuildFromPtr(handle, repo); } @@ -226,7 +225,7 @@ namespace LibGit2Sharp /// A new . public virtual Reference UpdateTarget(Reference directRef, ObjectId targetId) { - return UpdateTarget(directRef, targetId, null, null); + return UpdateTarget(directRef, targetId, null); } /// @@ -234,23 +233,25 @@ namespace LibGit2Sharp /// /// The symbolic reference which target should be updated. /// The new target. - /// The identity used for updating the reflog. /// The optional message to log in the of the reference. /// A new . - public virtual Reference UpdateTarget(Reference symbolicRef, Reference targetRef, Signature signature, string logMessage) + public virtual Reference UpdateTarget(Reference symbolicRef, Reference targetRef, string logMessage) { Ensure.ArgumentNotNull(symbolicRef, "symbolicRef"); Ensure.ArgumentNotNull(targetRef, "targetRef"); - signature = signature.OrDefault(repo.Config); - if (symbolicRef.CanonicalName == "HEAD") { - return UpdateHeadTarget(targetRef, signature, logMessage); + return UpdateHeadTarget(targetRef, logMessage); } + return UpdateSymbolicRefenceTarget(symbolicRef, targetRef, logMessage); + } + + private Reference UpdateSymbolicRefenceTarget(Reference symbolicRef, Reference targetRef, string logMessage) + { using (ReferenceSafeHandle referencePtr = RetrieveReferencePtr(symbolicRef.CanonicalName)) - using (ReferenceSafeHandle handle = Proxy.git_reference_symbolic_set_target(referencePtr, targetRef.CanonicalName, signature, logMessage)) + using (ReferenceSafeHandle handle = Proxy.git_reference_symbolic_set_target(referencePtr, targetRef.CanonicalName, logMessage)) { return Reference.BuildFromPtr(handle, repo); } @@ -264,49 +265,67 @@ namespace LibGit2Sharp /// A new . public virtual Reference UpdateTarget(Reference symbolicRef, Reference targetRef) { - return UpdateTarget(symbolicRef, targetRef, null, null); + return UpdateTarget(symbolicRef, targetRef, null); } - internal Reference UpdateHeadTarget(T target, Signature signature, string logMessage) + internal Reference MoveHeadTarget(T target) { - Debug.Assert(signature != null); - if (target is ObjectId) { - Proxy.git_repository_set_head_detached(repo.Handle, target as ObjectId, signature, logMessage); + Proxy.git_repository_set_head_detached(repo.Handle, target as ObjectId); } else if (target is DirectReference || target is SymbolicReference) { - Proxy.git_repository_set_head(repo.Handle, (target as Reference).CanonicalName, signature, logMessage); + Proxy.git_repository_set_head(repo.Handle, (target as Reference).CanonicalName); } else if (target is string) { var targetIdentifier = target as string; - if (Reference.IsValidName(targetIdentifier)) + if (Reference.IsValidName(targetIdentifier) && targetIdentifier.LooksLikeLocalBranch()) { - Proxy.git_repository_set_head(repo.Handle, targetIdentifier, signature, logMessage); + Proxy.git_repository_set_head(repo.Handle, targetIdentifier); } else { - GitObject commit = repo.Lookup(targetIdentifier, - GitObjectType.Any, - LookUpOptions.ThrowWhenNoGitObjectHasBeenFound | - LookUpOptions.DereferenceResultToCommit | - LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit); - - Proxy.git_repository_set_head_detached(repo.Handle, commit.Id, signature, logMessage); + using (var annotatedCommit = Proxy.git_annotated_commit_from_revspec(repo.Handle, targetIdentifier)) + { + Proxy.git_repository_set_head_detached_from_annotated(repo.Handle, annotatedCommit); + } } } else { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, - "'{0}' is not a valid target type.", typeof (T))); + "'{0}' is not a valid target type.", typeof(T))); } return repo.Refs.Head; } + internal Reference UpdateHeadTarget(ObjectId target, string logMessage) + { + Add("HEAD", target, logMessage, true); + + return repo.Refs.Head; + } + + internal Reference UpdateHeadTarget(Reference target, string logMessage) + { + Ensure.ArgumentConformsTo(target, r => (r is DirectReference || r is SymbolicReference), "target"); + + Add("HEAD", target, logMessage, true); + + return repo.Refs.Head; + } + + internal Reference UpdateHeadTarget(string target, string logMessage) + { + this.Add("HEAD", target, logMessage, true); + + return repo.Refs.Head; + } + internal ReferenceSafeHandle RetrieveReferencePtr(string referenceName, bool shouldThrowIfNotFound = true) { ReferenceSafeHandle reference = Proxy.git_reference_lookup(repo.Handle, referenceName, shouldThrowIfNotFound); diff --git a/LibGit2Sharp/ReferenceCollectionExtensions.cs b/LibGit2Sharp/ReferenceCollectionExtensions.cs index 34c2a662..423397cc 100644 --- a/LibGit2Sharp/ReferenceCollectionExtensions.cs +++ b/LibGit2Sharp/ReferenceCollectionExtensions.cs @@ -38,11 +38,10 @@ namespace LibGit2Sharp /// The being worked with. /// The name of the reference to create. /// The target which can be either the canonical name of a reference or a revparse spec. - /// The identity used for updating the reflog /// The optional message to log in the when adding the /// True to allow silent overwriting a potentially existing reference, false otherwise. /// A new . - public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, Signature signature, string logMessage, bool allowOverwrite = false) + public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, string logMessage, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(canonicalRefNameOrObjectish, "canonicalRefNameOrObjectish"); @@ -54,13 +53,13 @@ namespace LibGit2Sharp if (refState == RefState.Exists) { - return refsColl.Add(name, reference, signature, logMessage, allowOverwrite); + return refsColl.Add(name, reference, logMessage, allowOverwrite); } if (refState == RefState.DoesNotExistButLooksValid && gitObject == null) { using (ReferenceSafeHandle handle = Proxy.git_reference_symbolic_create(refsColl.repo.Handle, name, canonicalRefNameOrObjectish, allowOverwrite, - signature.OrDefault(refsColl.repo.Config), logMessage)) + logMessage)) { return Reference.BuildFromPtr(handle, refsColl.repo); } @@ -75,7 +74,7 @@ namespace LibGit2Sharp } refsColl.EnsureHasLog(name); - return refsColl.Add(name, gitObject.Id, signature, logMessage, allowOverwrite); + return refsColl.Add(name, gitObject.Id, logMessage, allowOverwrite); } /// @@ -88,7 +87,7 @@ namespace LibGit2Sharp /// A new . public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, bool allowOverwrite = false) { - return Add(refsColl, name, canonicalRefNameOrObjectish, null, null, allowOverwrite); + return Add(refsColl, name, canonicalRefNameOrObjectish, null, allowOverwrite); } /// @@ -97,10 +96,9 @@ namespace LibGit2Sharp /// The being worked with. /// The direct reference which target should be updated. /// The revparse spec of the target. - /// The identity used for updating the reflog /// The optional message to log in the /// A new . - public static Reference UpdateTarget(this ReferenceCollection refsColl, Reference directRef, string objectish, Signature signature, string logMessage) + public static Reference UpdateTarget(this ReferenceCollection refsColl, Reference directRef, string objectish, string logMessage) { Ensure.ArgumentNotNull(directRef, "directRef"); Ensure.ArgumentNotNull(objectish, "objectish"); @@ -109,7 +107,7 @@ namespace LibGit2Sharp Ensure.GitObjectIsNotNull(target, objectish); - return refsColl.UpdateTarget(directRef, target.Id, signature, logMessage); + return refsColl.UpdateTarget(directRef, target.Id, logMessage); } /// @@ -121,7 +119,7 @@ namespace LibGit2Sharp /// A new . public static Reference UpdateTarget(this ReferenceCollection refsColl, Reference directRef, string objectish) { - return UpdateTarget(refsColl, directRef, objectish, null, null); + return UpdateTarget(refsColl, directRef, objectish, null); } /// @@ -129,13 +127,12 @@ namespace LibGit2Sharp /// /// The canonical name of the reference to rename. /// The new canonical name. - /// The identity used for updating the reflog /// The optional message to log in the /// True to allow silent overwriting a potentially existing reference, false otherwise. /// The being worked with. /// A new . public static Reference Rename(this ReferenceCollection refsColl, string currentName, string newName, - Signature signature = null, string logMessage = null, bool allowOverwrite = false) + string logMessage = null, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName"); @@ -148,7 +145,7 @@ namespace LibGit2Sharp "Reference '{0}' doesn't exist. One cannot move a non existing reference.", currentName)); } - return refsColl.Rename(reference, newName, signature, logMessage, allowOverwrite); + return refsColl.Rename(reference, newName, logMessage, allowOverwrite); } /// @@ -157,19 +154,16 @@ namespace LibGit2Sharp /// The being worked with. /// The canonical name of the reference. /// The target which can be either the canonical name of a reference or a revparse spec. - /// The identity used for updating the reflog /// The optional message to log in the of the reference. /// A new . - public static Reference UpdateTarget(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, Signature signature, string logMessage) + public static Reference UpdateTarget(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, string logMessage) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(canonicalRefNameOrObjectish, "canonicalRefNameOrObjectish"); - signature = signature.OrDefault(refsColl.repo.Config); - if (name == "HEAD") { - return refsColl.UpdateHeadTarget(canonicalRefNameOrObjectish, signature, logMessage); + return refsColl.UpdateHeadTarget(canonicalRefNameOrObjectish, logMessage); } Reference reference = refsColl[name]; @@ -177,7 +171,7 @@ namespace LibGit2Sharp var directReference = reference as DirectReference; if (directReference != null) { - return refsColl.UpdateTarget(directReference, canonicalRefNameOrObjectish, signature, logMessage); + return refsColl.UpdateTarget(directReference, canonicalRefNameOrObjectish, logMessage); } var symbolicReference = reference as SymbolicReference; @@ -192,7 +186,7 @@ namespace LibGit2Sharp throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The reference specified by {0} is a Symbolic reference, you must provide a reference canonical name as the target.", name), "canonicalRefNameOrObjectish"); } - return refsColl.UpdateTarget(symbolicReference, targetRef, signature, logMessage); + return refsColl.UpdateTarget(symbolicReference, targetRef, logMessage); } throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Reference '{0}' has an unexpected type ('{1}').", name, reference.GetType())); @@ -207,7 +201,7 @@ namespace LibGit2Sharp /// A new . public static Reference UpdateTarget(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish) { - return UpdateTarget(refsColl, name, canonicalRefNameOrObjectish, null, null); + return UpdateTarget(refsColl, name, canonicalRefNameOrObjectish, null); } /// diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index cf94a8f7..f5712c37 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -92,6 +92,11 @@ namespace LibGit2Sharp configurationGlobalFilePath = options.GlobalConfigurationLocation; configurationXDGFilePath = options.XdgConfigurationLocation; configurationSystemFilePath = options.SystemConfigurationLocation; + + if (options.Identity != null) + { + Proxy.git_repository_set_ident(handle, options.Identity.Name, options.Identity.Email); + } } if (!isBare) @@ -602,9 +607,8 @@ namespace LibGit2Sharp /// /// A revparse spec for the commit or branch to checkout. /// controlling checkout behavior. - /// Identity for use when updating the reflog. /// The that was checked out. - public Branch Checkout(string committishOrBranchSpec, CheckoutOptions options, Signature signature) + public Branch Checkout(string committishOrBranchSpec, CheckoutOptions options) { Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec"); Ensure.ArgumentNotNull(options, "options"); @@ -626,7 +630,7 @@ namespace LibGit2Sharp if (reference.IsLocalBranch()) { Branch branch = Branches[reference.CanonicalName]; - return Checkout(branch, options, signature); + return Checkout(branch, options); } } @@ -640,7 +644,7 @@ namespace LibGit2Sharp } Commit commit = obj.DereferenceToCommit(true); - Checkout(commit.Tree, options, commit.Id.Sha, committishOrBranchSpec, signature); + Checkout(commit.Tree, options, committishOrBranchSpec); return Head; } @@ -652,9 +656,8 @@ namespace LibGit2Sharp /// /// The to check out. /// controlling checkout behavior. - /// Identity for use when updating the reflog. /// The that was checked out. - public Branch Checkout(Branch branch, CheckoutOptions options, Signature signature) + public Branch Checkout(Branch branch, CheckoutOptions options) { Ensure.ArgumentNotNull(branch, "branch"); Ensure.ArgumentNotNull(options, "options"); @@ -671,11 +674,11 @@ namespace LibGit2Sharp string.Equals(Refs[branch.CanonicalName].TargetIdentifier, branch.Tip.Id.Sha, StringComparison.OrdinalIgnoreCase)) { - Checkout(branch.Tip.Tree, options, branch.CanonicalName, branch.Name, signature); + Checkout(branch.Tip.Tree, options, branch.CanonicalName); } else { - Checkout(branch.Tip.Tree, options, branch.Tip.Id.Sha, branch.Name, signature); + Checkout(branch.Tip.Tree, options, branch.Tip.Id.Sha); } return Head; @@ -689,14 +692,13 @@ namespace LibGit2Sharp /// /// The to check out. /// controlling checkout behavior. - /// Identity for use when updating the reflog. /// The that was checked out. - public Branch Checkout(Commit commit, CheckoutOptions options, Signature signature) + public Branch Checkout(Commit commit, CheckoutOptions options) { Ensure.ArgumentNotNull(commit, "commit"); Ensure.ArgumentNotNull(options, "options"); - Checkout(commit.Tree, options, commit.Id.Sha, commit.Id.Sha, signature); + Checkout(commit.Tree, options, commit.Id.Sha); return Head; } @@ -707,22 +709,15 @@ namespace LibGit2Sharp /// /// The to checkout. /// controlling checkout behavior. - /// Target for the new HEAD. /// The spec which will be written as target in the reflog. - /// Identity for use when updating the reflog. private void Checkout( Tree tree, CheckoutOptions checkoutOptions, - string headTarget, string refLogHeadSpec, Signature signature) + string refLogHeadSpec) { - var previousHeadName = Info.IsHeadDetached ? Head.Tip.Sha : Head.Name; - CheckoutTree(tree, null, checkoutOptions); - Refs.UpdateTarget("HEAD", headTarget, signature, - string.Format( - CultureInfo.InvariantCulture, - "checkout: moving from {0} to {1}", previousHeadName, refLogHeadSpec)); + Refs.MoveHeadTarget(refLogHeadSpec); } /// @@ -750,11 +745,9 @@ namespace LibGit2Sharp /// /// Flavor of reset operation to perform. /// The target commit object. - /// Identity for use when updating the reflog. - /// Message to use when updating the reflog. - public void Reset(ResetMode resetMode, Commit commit, Signature signature, string logMessage) + public void Reset(ResetMode resetMode, Commit commit) { - Reset(resetMode, commit, new CheckoutOptions(), signature, logMessage); + Reset(resetMode, commit, new CheckoutOptions()); } /// @@ -764,23 +757,14 @@ namespace LibGit2Sharp /// Flavor of reset operation to perform. /// The target commit object. /// Collection of parameters controlling checkout behavior. - /// Identity for use when updating the reflog. - /// Message to use when updating the reflog. - private void Reset(ResetMode resetMode, Commit commit, IConvertableToGitCheckoutOpts opts, Signature signature, string logMessage) + private void Reset(ResetMode resetMode, Commit commit, IConvertableToGitCheckoutOpts opts) { Ensure.ArgumentNotNull(commit, "commit"); - if (logMessage == null) - { - logMessage = string.Format( - CultureInfo.InvariantCulture, - "reset: moving to {0}", commit.Sha); - } - using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(opts)) { var options = checkoutOptionsWrapper.Options; - Proxy.git_reset(handle, commit.Id, resetMode, ref options, signature.OrDefault(Config), logMessage); + Proxy.git_reset(handle, commit.Id, resetMode, ref options); } } @@ -904,7 +888,7 @@ namespace LibGit2Sharp { if (reference is DirectReference) { - Refs.UpdateTarget(reference, commit.Id, commit.Committer, reflogMessage); + Refs.UpdateTarget(reference, commit.Id, reflogMessage); return; } @@ -914,7 +898,7 @@ namespace LibGit2Sharp if (reference == null) { - Refs.Add(symRef.TargetIdentifier, commit.Id, commit.Committer, reflogMessage); + Refs.Add(symRef.TargetIdentifier, commit.Id, reflogMessage); return; } } @@ -1278,7 +1262,7 @@ namespace LibGit2Sharp throw new LibGit2SharpException("Unable to perform Fast-Forward merge with mith multiple merge heads."); } - mergeResult = FastForwardMerge(annotatedCommits[0], merger, options); + mergeResult = FastForwardMerge(annotatedCommits[0], options); } else if (mergeAnalysis.HasFlag(GitMergeAnalysis.GIT_MERGE_ANALYSIS_NORMAL)) { @@ -1294,7 +1278,7 @@ namespace LibGit2Sharp throw new LibGit2SharpException("Unable to perform Fast-Forward merge with mith multiple merge heads."); } - mergeResult = FastForwardMerge(annotatedCommits[0], merger, options); + mergeResult = FastForwardMerge(annotatedCommits[0], options); } else { @@ -1374,10 +1358,9 @@ namespace LibGit2Sharp /// Perform a fast-forward merge. /// /// The merge head handle to fast-forward merge. - /// The of who is performing the merge. /// Options controlling merge behavior. /// The of the merge. - private MergeResult FastForwardMerge(GitAnnotatedCommitHandle annotatedCommit, Signature merger, MergeOptions options) + private MergeResult FastForwardMerge(GitAnnotatedCommitHandle annotatedCommit, MergeOptions options) { ObjectId id = Proxy.git_annotated_commit_id(annotatedCommit); Commit fastForwardCommit = (Commit) Lookup(id, ObjectType.Commit); @@ -1394,12 +1377,12 @@ namespace LibGit2Sharp if (reference == null) { // Reference does not exist, create it. - Refs.Add(Refs.Head.TargetIdentifier, fastForwardCommit.Id, merger, refLogEntry); + Refs.Add(Refs.Head.TargetIdentifier, fastForwardCommit.Id, refLogEntry); } else { // Update target reference. - Refs.UpdateTarget(reference, fastForwardCommit.Id.Sha, merger, refLogEntry); + Refs.UpdateTarget(reference, fastForwardCommit.Id.Sha, refLogEntry); } return new MergeResult(MergeStatus.FastForward, fastForwardCommit); diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs index e5251429..6f265cad 100644 --- a/LibGit2Sharp/RepositoryExtensions.cs +++ b/LibGit2Sharp/RepositoryExtensions.cs @@ -121,11 +121,12 @@ namespace LibGit2Sharp /// /// The being worked with. /// The name of the branch to create. - /// Identification for use when updating the reflog - /// Message to append to the reflog - public static Branch CreateBranch(this IRepository repository, string branchName, Signature signature = null, string logMessage = null) + public static Branch CreateBranch(this IRepository repository, string branchName) { - return CreateBranch(repository, branchName, "HEAD", signature, logMessage); + var head = repository.Head; + var reflogName = head is DetachedHead ? head.Tip.Sha : head.Name; + + return CreateBranch(repository, branchName, reflogName); } /// @@ -134,11 +135,9 @@ namespace LibGit2Sharp /// The being worked with. /// The name of the branch to create. /// The commit which should be pointed at by the Branch. - /// Identification for use when updating the reflog - /// Message to append to the reflog - public static Branch CreateBranch(this IRepository repository, string branchName, Commit target, Signature signature = null, string logMessage = null) + public static Branch CreateBranch(this IRepository repository, string branchName, Commit target) { - return repository.Branches.Add(branchName, target, signature, logMessage); + return repository.Branches.Add(branchName, target); } /// @@ -147,11 +146,9 @@ namespace LibGit2Sharp /// The being worked with. /// The name of the branch to create. /// The revparse spec for the target commit. - /// Identification for use when updating the reflog - /// Message to append to the reflog - public static Branch CreateBranch(this IRepository repository, string branchName, string committish, Signature signature = null, string logMessage = null) + public static Branch CreateBranch(this IRepository repository, string branchName, string committish) { - return repository.Branches.Add(branchName, committish, signature, logMessage); + return repository.Branches.Add(branchName, committish); } /// @@ -161,16 +158,13 @@ namespace LibGit2Sharp /// The being worked with. /// Flavor of reset operation to perform. /// A revparse spec for the target commit object. - /// Identification for use when updating the reflog - /// Message to append to the reflog - public static void Reset(this IRepository repository, ResetMode resetMode, string committish = "HEAD", - Signature signature = null, string logMessage = null) + public static void Reset(this IRepository repository, ResetMode resetMode, string committish = "HEAD") { Ensure.ArgumentNotNullOrEmptyString(committish, "committish"); Commit commit = LookUpCommit(repository, committish); - repository.Reset(resetMode, commit, signature, logMessage); + repository.Reset(resetMode, commit); } /// @@ -260,12 +254,11 @@ namespace LibGit2Sharp /// /// The being worked with. /// A revparse spec for the commit or branch to checkout. - /// The identity used for updating the reflog /// The that was checked out. - public static Branch Checkout(this IRepository repository, string commitOrBranchSpec, Signature signature = null) + public static Branch Checkout(this IRepository repository, string commitOrBranchSpec) { CheckoutOptions options = new CheckoutOptions(); - return repository.Checkout(commitOrBranchSpec, options, signature); + return repository.Checkout(commitOrBranchSpec, options); } /// @@ -277,12 +270,11 @@ namespace LibGit2Sharp /// /// The being worked with. /// The to check out. - /// The identity used for updating the reflog /// The that was checked out. - public static Branch Checkout(this IRepository repository, Branch branch, Signature signature = null) + public static Branch Checkout(this IRepository repository, Branch branch) { CheckoutOptions options = new CheckoutOptions(); - return repository.Checkout(branch, options, signature); + return repository.Checkout(branch, options); } /// @@ -293,12 +285,11 @@ namespace LibGit2Sharp /// /// The being worked with. /// The to check out. - /// The identity used for updating the reflog /// The that was checked out. - public static Branch Checkout(this IRepository repository, Commit commit, Signature signature = null) + public static Branch Checkout(this IRepository repository, Commit commit) { CheckoutOptions options = new CheckoutOptions(); - return repository.Checkout(commit, options, signature); + return repository.Checkout(commit, options); } internal static string BuildRelativePathFrom(this Repository repo, string path) @@ -476,7 +467,7 @@ namespace LibGit2Sharp /// The that was checked out. public static Branch Checkout(this IRepository repository, Branch branch, CheckoutOptions options) { - return repository.Checkout(branch, options, null); + return repository.Checkout(branch, options); } /// @@ -491,7 +482,7 @@ namespace LibGit2Sharp /// The that was checked out. public static Branch Checkout(this IRepository repository, Commit commit, CheckoutOptions options) { - return repository.Checkout(commit, options, null); + return repository.Checkout(commit, options); } /// @@ -507,7 +498,7 @@ namespace LibGit2Sharp /// The that was checked out. public static Branch Checkout(this IRepository repository, string committishOrBranchSpec, CheckoutOptions options) { - return repository.Checkout(committishOrBranchSpec, options, null); + return repository.Checkout(committishOrBranchSpec, options); } /// @@ -533,7 +524,7 @@ namespace LibGit2Sharp /// The target commit object. public static void Reset(this IRepository repository, ResetMode resetMode, Commit commit) { - repository.Reset(resetMode, commit, null, null); + repository.Reset(resetMode, commit); } /// diff --git a/LibGit2Sharp/RepositoryOptions.cs b/LibGit2Sharp/RepositoryOptions.cs index 12a5751c..a8cf0c7f 100644 --- a/LibGit2Sharp/RepositoryOptions.cs +++ b/LibGit2Sharp/RepositoryOptions.cs @@ -52,5 +52,15 @@ /// /// public string SystemConfigurationLocation { get; set; } + + /// + /// Overrides the default identity to be used when creating reflog entries. + /// + /// When unset the identity will be retreived from the repository's configuration. + /// When no identity can be found in the repository configuration stores, a fake + /// identity ("unknown" as both name and email), will be used. + /// + /// + public Identity Identity { get; set; } } } diff --git a/LibGit2Sharp/ResetMode.cs b/LibGit2Sharp/ResetMode.cs index fa52d1e6..f1502891 100644 --- a/LibGit2Sharp/ResetMode.cs +++ b/LibGit2Sharp/ResetMode.cs @@ -1,7 +1,7 @@ namespace LibGit2Sharp { /// - /// Specifies the kind of operation that should perform. + /// Specifies the kind of operation that should perform. /// public enum ResetMode { diff --git a/LibGit2Sharp/SignatureExtensions.cs b/LibGit2Sharp/SignatureExtensions.cs deleted file mode 100644 index a4be1c4e..00000000 --- a/LibGit2Sharp/SignatureExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace LibGit2Sharp -{ - /// - /// Provides helper overloads for a - /// - internal static class SignatureExtensions - { - /// - /// If the signature is null, return the default using configuration values. - /// - /// The signature to test - /// The configuration to query for default values - /// A valid - public static Signature OrDefault(this Signature signature, Configuration config) - { - return signature ?? config.BuildSignature(DateTimeOffset.Now); - } - } -} diff --git a/LibGit2Sharp/SubmoduleCollection.cs b/LibGit2Sharp/SubmoduleCollection.cs index 7e76036f..33abfbf8 100644 --- a/LibGit2Sharp/SubmoduleCollection.cs +++ b/LibGit2Sharp/SubmoduleCollection.cs @@ -108,7 +108,7 @@ namespace LibGit2Sharp Version = 1, CheckoutOptions = gitCheckoutOptions, RemoteCallbacks = gitRemoteCallbacks, - CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE_CREATE + CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE }; Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts); diff --git a/LibGit2Sharp/libgit2_hash.txt b/LibGit2Sharp/libgit2_hash.txt index 4a8fde8a..1f04184d 100644 --- a/LibGit2Sharp/libgit2_hash.txt +++ b/LibGit2Sharp/libgit2_hash.txt @@ -1 +1 @@ -e0902fbce7d14631bd02091c1c70cde3e68f78ab +9bbc8f350b80a5a6e94651ec667cf9e5d545b317 diff --git a/libgit2 b/libgit2 index e0902fbc..9bbc8f35 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit e0902fbce7d14631bd02091c1c70cde3e68f78ab +Subproject commit 9bbc8f350b80a5a6e94651ec667cf9e5d545b317 diff --git a/nuget.package/build/LibGit2Sharp.props b/nuget.package/build/LibGit2Sharp.props index f9460e24..b12792b7 100644 --- a/nuget.package/build/LibGit2Sharp.props +++ b/nuget.package/build/LibGit2Sharp.props @@ -1,20 +1,20 @@  - - NativeBinaries\amd64\git2-e0902fb.dll + + NativeBinaries\amd64\git2-9bbc8f3.dll PreserveNewest - - NativeBinaries\amd64\git2-e0902fb.pdb + + NativeBinaries\amd64\git2-9bbc8f3.pdb PreserveNewest - - NativeBinaries\x86\git2-e0902fb.dll + + NativeBinaries\x86\git2-9bbc8f3.dll PreserveNewest - - NativeBinaries\x86\git2-e0902fb.pdb + + NativeBinaries\x86\git2-9bbc8f3.pdb PreserveNewest