Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions LibGit2Sharp/Core/HistoryRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ private void RewriteCommit(Commit commit)
return;
}

var newCommit = repo.ObjectDatabase.CreateCommit(newHeader.Message, newHeader.Author,
newHeader.Committer, newTree,
var newCommit = repo.ObjectDatabase.CreateCommit(newHeader.Author,
newHeader.Committer,
newHeader.Message,
true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure whether or not we should prettify the message when rewriting the history.

/cc @dahlbyk @ben @carlosmn

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think any rewrite should be explicitly done by the user. I'm not all that familiar with this code, but it looks like the user gets to return the whole set, in which case they should run the text through the prettify function if they want to (e.g. the equivalent of the 'reword' option in git-rebase--interactive would likely want to do this, as the user was asked for input), but we shouldn't change the data the user told us to put into the commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create another issue to specifically deal with this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. See #621

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't change the data the user told us to put into the commit.

This

newTree,
mappedNewParents);

// Record the rewrite
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public static ObjectId git_commit_create(
string referenceName,
Signature author,
Signature committer,
string prettifiedMessage,
string message,
Tree tree,
GitOid[] parentIds)
{
Expand All @@ -331,7 +331,7 @@ public static ObjectId git_commit_create(

int res = NativeMethods.git_commit_create_from_oids(
out commitOid, repo, referenceName, authorHandle,
committerHandle, null, prettifiedMessage,
committerHandle, null, message,
ref treeOid, parentPtrs.Count, parentPtrs.ToArray());

Ensure.ZeroResult(res);
Expand Down
35 changes: 31 additions & 4 deletions LibGit2Sharp/ObjectDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,36 @@ public virtual Tree CreateTree(TreeDefinition treeDefinition)
/// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param>
/// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param>
/// <returns>The created <see cref="Commit"/>.</returns>
[Obsolete("This method will be removed in the next release. Please use CreateCommit(Signature, Signature, string, bool, Tree, IEnumerable<Commit>) instead.")]
public virtual Commit CreateCommit(string message, Signature author, Signature committer, Tree tree, IEnumerable<Commit> parents)
{
return CreateCommit(message, author, committer, tree, parents, null);
return CreateCommit(author, committer, message, true, tree, parents, null);
}

internal Commit CreateCommit(string message, Signature author, Signature committer, Tree tree, IEnumerable<Commit> parents, string referenceName)
/// <summary>
/// Inserts a <see cref="Commit"/> into the object database, referencing an existing <see cref="Tree"/>.
/// <para>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this whole <para/> section should be moved under the <summary/> one so that it reads like

/// <summary>
/// Inserts a <see cref="Commit"/> into the object database, referencing an existing <see cref="Tree"/>.
/// <para>
///   Prettifying the message includes:
///   * Removing empty lines from the beginning and end.
///   * Removing trailing spaces from every line.
///   * Turning multiple consecutive empty lines between paragraphs into just one empty line.
///   * Ensuring the commit message ends with a newline.
///   * Removing every line starting with "#".
/// </para>
/// </summary>

/// Prettifing the message includes:
/// * Removing empty lines from the beginning and end.
/// * Removing trailing spaces from every line.
/// * Turning multiple consecutive empty lines between paragraphs into just one empty line.
/// * Ensuring the commit message ends with a newline.
/// * Removing every line starting with "#".
/// </para>
/// </summary>
/// <param name="author">The <see cref="Signature"/> of who made the change.</param>
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
/// <param name="message">The description of why a change was made to the repository.</param>
/// <param name="prettifyMessage">True to prettify the message, or false to leave it as is</param>
/// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param>
/// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param>
/// <returns>The created <see cref="Commit"/>.</returns>
public virtual Commit CreateCommit(Signature author, Signature committer, string message, bool prettifyMessage, Tree tree, IEnumerable<Commit> parents)
{
return CreateCommit(author, committer, message, prettifyMessage, tree, parents, null);
}

internal Commit CreateCommit(Signature author, Signature committer, string message, bool prettifyMessage, Tree tree, IEnumerable<Commit> parents, string referenceName)
{
Ensure.ArgumentNotNull(message, "message");
Ensure.ArgumentDoesNotContainZeroByte(message, "message");
Expand All @@ -205,10 +229,13 @@ internal Commit CreateCommit(string message, Signature author, Signature committ
Ensure.ArgumentNotNull(tree, "tree");
Ensure.ArgumentNotNull(parents, "parents");

string prettifiedMessage = Proxy.git_message_prettify(message);
if (prettifyMessage)
{
message = Proxy.git_message_prettify(message);
}
GitOid[] parentIds = parents.Select(p => p.Id.Oid).ToArray();

ObjectId commitId = Proxy.git_commit_create(repo.Handle, referenceName, author, committer, prettifiedMessage, tree, parentIds);
ObjectId commitId = Proxy.git_commit_create(repo.Handle, referenceName, author, committer, message, tree, parentIds);

return repo.Lookup<Commit>(commitId);
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ public Commit Commit(string message, Signature author, Signature committer, bool

var parents = RetrieveParentsOfTheCommitBeingCreated(amendPreviousCommit);

Commit result = ObjectDatabase.CreateCommit(message, author, committer, tree, parents, "HEAD");
Commit result = ObjectDatabase.CreateCommit(author, committer, message, true, tree, parents, "HEAD");

Proxy.git_repository_state_cleanup(handle);

Expand Down