-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESCAPE_COMMIT_MSG Escaping Double Quotes In Merge Commit Message If It Exists #7796
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, have not run
GitCommands/Git/GitCommandHelpers.cs
Outdated
@@ -1024,6 +1026,11 @@ public static ArgumentString MergeBranchCmd(string branch, bool allowFastForward | |||
}; | |||
} | |||
|
|||
private static string EscapeDoubleQuotes(string message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should rather be named EscapeQuotes
.
Code block can be omitted, i.e. turn into => message?.Replace("\"", "\\\"");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to escape quotes and slashes is like opening a Pandora box of pain.
Instead I propose use --file
option similar to how we run the commit
command:
gitextensions/GitCommands/Git/GitModule.cs
Lines 2144 to 2156 in 85fde1c
public ArgumentString CommitCmd(bool amend, bool signOff = false, string author = "", bool useExplicitCommitMessage = true, bool noVerify = false, bool gpgSign = false, string gpgKeyId = "") | |
{ | |
return new GitArgumentBuilder("commit") | |
{ | |
{ amend, "--amend" }, | |
{ noVerify, "--no-verify" }, | |
{ signOff, "--signoff" }, | |
{ !string.IsNullOrEmpty(author), $"--author=\"{author?.Trim().Trim('"')}\"" }, | |
{ gpgSign && string.IsNullOrWhiteSpace(gpgKeyId), "-S" }, | |
{ gpgSign && !string.IsNullOrWhiteSpace(gpgKeyId), $"-S{gpgKeyId}" }, | |
{ useExplicitCommitMessage, $"-F \"{Path.Combine(GetGitDirectory(), "COMMITMESSAGE")}\"" } | |
}; | |
} |
@RussKie Is there a method or a property that I can use to get this value? Also the algorithm will be:
|
If you have an instance of a `GitModule`, you can get its repo path from
`Working Dir`.
|
@RussKie now the merge happens through MERGE_MSG file. I had to shuffle some methods around. Also updated the tests. |
public static string FormatCommitMessageFromTextBox( | ||
string commitMessageText, bool usingCommitTemplate, bool ensureCommitMessageSecondLineEmpty) | ||
{ | ||
if (commitMessageText == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about commitMessageText == ""
or commitMessageText == " "
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pre-existing code. If replacing the above with IsNullOrWhitespace()
is not going to affect the existing logic, I can push the change.
var lineNumber = 1; | ||
foreach (var line in commitMessageText.Split('\n')) | ||
{ | ||
string nonNullLine = line ?? string.Empty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can line == null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a preexisting method that I pulled from GitUI/CommandsDialogs/FormCommit.cs
@@ -1007,30 +1008,23 @@ private static GitItemStatus GitItemStatusFromStatusCharacter(StagedStatus stage | |||
}; | |||
} | |||
|
|||
public static ArgumentString MergeBranchCmd(string branch, bool allowFastForward, bool squash, bool noCommit, string strategy, bool allowUnrelatedHistories, string message, int? log) | |||
public static ArgumentString MergeBranchCmd(string branch, bool allowFastForward, bool squash, bool noCommit, string strategy, bool allowUnrelatedHistories, string folderPath, int? log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for this method that at least cover the -F
flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the test cases now accept a path instead of a message.
The response has -F
flag.
Assert.AreEqual( |
@@ -102,6 +109,21 @@ private void OkClick(object sender, EventArgs e) | |||
} | |||
} | |||
|
|||
private void WriteMessageToMergeFile(string mergeMessage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please expose it via a TestAccessor
and add unit tests using ReferenceRepository
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #3954
Before
Merge commit message with quotes was failing the merge
test "message text" test
After
The merge succeeds.
Test methodology
Test environment(s)
✒️ I contribute this code under The Developer Certificate of Origin.