From ee06f6c9e204c5161b27062020ea3dca62c42e16 Mon Sep 17 00:00:00 2001 From: Brian Gillespie Date: Wed, 28 Oct 2015 11:05:23 -0700 Subject: [PATCH 1/6] Fixes #1217 Added CustomHeaders member to GitPushOptions to match underlying c struct for marshalling. Added tests suggested by @nulltoken to PushFixture.cs --- LibGit2Sharp.Tests/PushFixture.cs | 38 +++++++++++++++++++++++++++++ LibGit2Sharp/Core/GitPushOptions.cs | 1 + 2 files changed, 39 insertions(+) diff --git a/LibGit2Sharp.Tests/PushFixture.cs b/LibGit2Sharp.Tests/PushFixture.cs index 7dde5efd6..1826e54e6 100644 --- a/LibGit2Sharp.Tests/PushFixture.cs +++ b/LibGit2Sharp.Tests/PushFixture.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using LibGit2Sharp.Handlers; @@ -60,6 +61,43 @@ private void AssertPush(Action push) } } + [Fact] + public void e1217() + { + var scd = BuildSelfCleaningDirectory(); + + string clonedRepoPath = Repository.Clone("https://github.com/nulltoken/lg2s_issues_1217.git", scd.DirectoryPath, + new CloneOptions + { + CredentialsProvider = dd, + }); + + PushOptions options = new PushOptions() + { + CredentialsProvider = dd, + OnPushStatusError = ss, + }; + + using (var repo = new Repository(clonedRepoPath)) + { + var file = Guid.NewGuid().ToString(); + Touch(repo.Info.WorkingDirectory, file, "tada"); + repo.Stage(file); + repo.Commit("de", Constants.Signature, Constants.Signature); + repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options); + } + } + + private Credentials dd(string url, string usernamefromurl, SupportedCredentialTypes types) + { + return new UsernamePasswordCredentials { Username = "your_name", Password = "your_password" }; + } + + private void ss(PushStatusError pushstatuserrors) + { + Trace.WriteLine(pushstatuserrors.Message); + } + [Fact] public void CanPushABranchTrackingAnUpstreamBranch() { diff --git a/LibGit2Sharp/Core/GitPushOptions.cs b/LibGit2Sharp/Core/GitPushOptions.cs index d4bbcdc3f..075a62b6b 100644 --- a/LibGit2Sharp/Core/GitPushOptions.cs +++ b/LibGit2Sharp/Core/GitPushOptions.cs @@ -8,5 +8,6 @@ internal class GitPushOptions public int Version = 1; public int PackbuilderDegreeOfParallelism; public GitRemoteCallbacks RemoteCallbacks; + public GitStrArrayManaged CustomHeaders; } } From 35d45cc9cb7a919b1de2ba67fccf70cfe3b43b91 Mon Sep 17 00:00:00 2001 From: Vogel612 Date: Tue, 8 Sep 2015 00:42:12 +0200 Subject: [PATCH 2/6] Adjusted Commit indexer xml doc see and fixes #966 --- LibGit2Sharp/Commit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibGit2Sharp/Commit.cs b/LibGit2Sharp/Commit.cs index d878655ef..ea7844477 100644 --- a/LibGit2Sharp/Commit.cs +++ b/LibGit2Sharp/Commit.cs @@ -54,7 +54,7 @@ internal Commit(Repository repo, ObjectId id) /// /// Gets the pointed at by the in the . /// - /// The relative path to the from the working directory. + /// Path to the from the tree in this /// null if nothing has been found, the otherwise. public virtual TreeEntry this[string relativePath] { From 69cdbb48b767e2698c2dde5d7bd44b9aee0d5b02 Mon Sep 17 00:00:00 2001 From: Vogel612 Date: Tue, 8 Sep 2015 13:52:47 +0200 Subject: [PATCH 3/6] Added Prettifying Option to RewriteHistoryOptions see #621. The default prettifying behabiour now is: do not prettify Documentation for the new property of RewriteHistoryOptions --- LibGit2Sharp.Tests/FilterBranchFixture.cs | 10 +++++----- LibGit2Sharp/Core/HistoryRewriter.cs | 6 +++--- LibGit2Sharp/RewriteHistoryOptions.cs | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/LibGit2Sharp.Tests/FilterBranchFixture.cs b/LibGit2Sharp.Tests/FilterBranchFixture.cs index 2199cea4c..d71cb22d8 100644 --- a/LibGit2Sharp.Tests/FilterBranchFixture.cs +++ b/LibGit2Sharp.Tests/FilterBranchFixture.cs @@ -191,10 +191,10 @@ public void CanRewriteAuthorOfCommitsOnlyBeingPointedAtByTags() AssertSucceedingButNotError(); var lightweightTag = repo.Tags["so-lonely"]; - Assert.Equal("Bam!\n", ((Commit)lightweightTag.Target).Message); + Assert.Equal("Bam!", ((Commit)lightweightTag.Target).Message); var annotatedTag = repo.Tags["so-lonely-but-annotated"]; - Assert.Equal("Bam!\n", ((Commit)annotatedTag.Target).Message); + Assert.Equal("Bam!", ((Commit)annotatedTag.Target).Message); } [Fact] @@ -495,7 +495,7 @@ public void DoesNotRewriteRefsThatDontChange() var parents = repo.Branches["br2"].Tip.Parents.ToList(); Assert.Equal(2, parents.Count()); Assert.NotEmpty(parents.Where(c => c.Sha.StartsWith("9fd738e"))); - Assert.Equal("abc\n", parents.Single(c => !c.Sha.StartsWith("9fd738e")).Message); + Assert.Equal("abc", parents.Single(c => !c.Sha.StartsWith("9fd738e")).Message); } [Fact] @@ -530,7 +530,7 @@ public void CanNotOverWriteBackedUpReferences() AssertErrorFired(ex); AssertSucceedingNotFired(); - Assert.Equal("abc\n", repo.Head.Tip.Message); + Assert.Equal("abc", repo.Head.Tip.Message); var newOriginalRefs = repo.Refs.FromGlob("refs/original/*").OrderBy(r => r.CanonicalName).ToArray(); Assert.Equal(originalRefs, newOriginalRefs); @@ -791,7 +791,7 @@ public void HandlesNameRewritingOfChainedTags() var newCommit = newAnnotationC.Target as Commit; Assert.NotNull(newCommit); Assert.NotEqual(newCommit, theCommit); - Assert.Equal("Rewrote\n", newCommit.Message); + Assert.Equal("Rewrote", newCommit.Message); // Ensure the original tag doesn't exist anymore Assert.Null(repo.Tags["lightweightA"]); diff --git a/LibGit2Sharp/Core/HistoryRewriter.cs b/LibGit2Sharp/Core/HistoryRewriter.cs index a805a6a1a..c4cc2be8b 100644 --- a/LibGit2Sharp/Core/HistoryRewriter.cs +++ b/LibGit2Sharp/Core/HistoryRewriter.cs @@ -52,7 +52,7 @@ public void Execute() var commits = repo.Commits.QueryBy(filter); foreach (var commit in commits) { - RewriteCommit(commit); + RewriteCommit(commit, options); } // Ordering matters. In the case of `A -> B -> commit`, we need to make sure B is rewritten @@ -199,7 +199,7 @@ private Reference RewriteReference( return refMap[oldRef] = movedRef; } - private void RewriteCommit(Commit commit) + private void RewriteCommit(Commit commit, RewriteHistoryOptions options) { var newHeader = CommitRewriteInfo.From(commit); var newTree = commit.Tree; @@ -248,7 +248,7 @@ private void RewriteCommit(Commit commit) newHeader.Message, newTree, mappedNewParents, - true); + options.PrettifyMessages); // Record the rewrite objectMap[commit] = newCommit; diff --git a/LibGit2Sharp/RewriteHistoryOptions.cs b/LibGit2Sharp/RewriteHistoryOptions.cs index 031839c38..59a982dc2 100644 --- a/LibGit2Sharp/RewriteHistoryOptions.cs +++ b/LibGit2Sharp/RewriteHistoryOptions.cs @@ -77,5 +77,13 @@ public RewriteHistoryOptions() /// /// public Action OnError { get; set; } + + /// + /// Specifies Commit message prettifying behavior during rewrite. + /// NOTE: Prettifying may result in losing one or multiple lines in the commit message. + /// As such it is recommended to leave this set to false. + /// + /// true if Commit messages are prettified; otherwise, false. + public bool PrettifyMessages { get; set; } } } From 30c9ca1bc7025c0e1d3ca1b52314a339e9f98c8c Mon Sep 17 00:00:00 2001 From: Brian Gillespie Date: Wed, 28 Oct 2015 11:05:23 -0700 Subject: [PATCH 4/6] Fixes #1217 Added CustomHeaders member to GitPushOptions to match underlying c struct for marshalling. Added tests suggested by @nulltoken to PushFixture.cs --- LibGit2Sharp.Tests/PushFixture.cs | 38 +++++++++++++++++++++++++++++ LibGit2Sharp/Core/GitPushOptions.cs | 1 + 2 files changed, 39 insertions(+) diff --git a/LibGit2Sharp.Tests/PushFixture.cs b/LibGit2Sharp.Tests/PushFixture.cs index 7dde5efd6..1826e54e6 100644 --- a/LibGit2Sharp.Tests/PushFixture.cs +++ b/LibGit2Sharp.Tests/PushFixture.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using LibGit2Sharp.Handlers; @@ -60,6 +61,43 @@ private void AssertPush(Action push) } } + [Fact] + public void e1217() + { + var scd = BuildSelfCleaningDirectory(); + + string clonedRepoPath = Repository.Clone("https://github.com/nulltoken/lg2s_issues_1217.git", scd.DirectoryPath, + new CloneOptions + { + CredentialsProvider = dd, + }); + + PushOptions options = new PushOptions() + { + CredentialsProvider = dd, + OnPushStatusError = ss, + }; + + using (var repo = new Repository(clonedRepoPath)) + { + var file = Guid.NewGuid().ToString(); + Touch(repo.Info.WorkingDirectory, file, "tada"); + repo.Stage(file); + repo.Commit("de", Constants.Signature, Constants.Signature); + repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options); + } + } + + private Credentials dd(string url, string usernamefromurl, SupportedCredentialTypes types) + { + return new UsernamePasswordCredentials { Username = "your_name", Password = "your_password" }; + } + + private void ss(PushStatusError pushstatuserrors) + { + Trace.WriteLine(pushstatuserrors.Message); + } + [Fact] public void CanPushABranchTrackingAnUpstreamBranch() { diff --git a/LibGit2Sharp/Core/GitPushOptions.cs b/LibGit2Sharp/Core/GitPushOptions.cs index d4bbcdc3f..075a62b6b 100644 --- a/LibGit2Sharp/Core/GitPushOptions.cs +++ b/LibGit2Sharp/Core/GitPushOptions.cs @@ -8,5 +8,6 @@ internal class GitPushOptions public int Version = 1; public int PackbuilderDegreeOfParallelism; public GitRemoteCallbacks RemoteCallbacks; + public GitStrArrayManaged CustomHeaders; } } From 537d910bcf9e0502352b9c2cd87d79a2eb01d3d2 Mon Sep 17 00:00:00 2001 From: Brian Gillespie Date: Thu, 12 Nov 2015 08:32:01 -0800 Subject: [PATCH 5/6] Remove manual tests from test fixture. --- LibGit2Sharp.Tests/PushFixture.cs | 37 ------------------------------- 1 file changed, 37 deletions(-) diff --git a/LibGit2Sharp.Tests/PushFixture.cs b/LibGit2Sharp.Tests/PushFixture.cs index 1826e54e6..63703d57f 100644 --- a/LibGit2Sharp.Tests/PushFixture.cs +++ b/LibGit2Sharp.Tests/PushFixture.cs @@ -61,43 +61,6 @@ private void AssertPush(Action push) } } - [Fact] - public void e1217() - { - var scd = BuildSelfCleaningDirectory(); - - string clonedRepoPath = Repository.Clone("https://github.com/nulltoken/lg2s_issues_1217.git", scd.DirectoryPath, - new CloneOptions - { - CredentialsProvider = dd, - }); - - PushOptions options = new PushOptions() - { - CredentialsProvider = dd, - OnPushStatusError = ss, - }; - - using (var repo = new Repository(clonedRepoPath)) - { - var file = Guid.NewGuid().ToString(); - Touch(repo.Info.WorkingDirectory, file, "tada"); - repo.Stage(file); - repo.Commit("de", Constants.Signature, Constants.Signature); - repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options); - } - } - - private Credentials dd(string url, string usernamefromurl, SupportedCredentialTypes types) - { - return new UsernamePasswordCredentials { Username = "your_name", Password = "your_password" }; - } - - private void ss(PushStatusError pushstatuserrors) - { - Trace.WriteLine(pushstatuserrors.Message); - } - [Fact] public void CanPushABranchTrackingAnUpstreamBranch() { From f73f38753404e6041b3bf220f542ff979e0bcf6c Mon Sep 17 00:00:00 2001 From: Brian Gillespie Date: Thu, 12 Nov 2015 08:35:03 -0800 Subject: [PATCH 6/6] Remove tests that must be run manually --- LibGit2Sharp.Tests/PushFixture.cs | 37 ------------------------------- 1 file changed, 37 deletions(-) diff --git a/LibGit2Sharp.Tests/PushFixture.cs b/LibGit2Sharp.Tests/PushFixture.cs index 1826e54e6..63703d57f 100644 --- a/LibGit2Sharp.Tests/PushFixture.cs +++ b/LibGit2Sharp.Tests/PushFixture.cs @@ -61,43 +61,6 @@ private void AssertPush(Action push) } } - [Fact] - public void e1217() - { - var scd = BuildSelfCleaningDirectory(); - - string clonedRepoPath = Repository.Clone("https://github.com/nulltoken/lg2s_issues_1217.git", scd.DirectoryPath, - new CloneOptions - { - CredentialsProvider = dd, - }); - - PushOptions options = new PushOptions() - { - CredentialsProvider = dd, - OnPushStatusError = ss, - }; - - using (var repo = new Repository(clonedRepoPath)) - { - var file = Guid.NewGuid().ToString(); - Touch(repo.Info.WorkingDirectory, file, "tada"); - repo.Stage(file); - repo.Commit("de", Constants.Signature, Constants.Signature); - repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options); - } - } - - private Credentials dd(string url, string usernamefromurl, SupportedCredentialTypes types) - { - return new UsernamePasswordCredentials { Username = "your_name", Password = "your_password" }; - } - - private void ss(PushStatusError pushstatuserrors) - { - Trace.WriteLine(pushstatuserrors.Message); - } - [Fact] public void CanPushABranchTrackingAnUpstreamBranch() {