Skip to content
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

"--format" must be quoted #9679

Merged
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
6 changes: 3 additions & 3 deletions GitCommands/Git/Commands/GitCommandHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static ArgumentString SortCriteria(bool needTags, GitRefsSortBy sortBy, GitRefsS
string order = sortOrder == GitRefsSortOrder.Ascending ? string.Empty : "-";
if (!needTags)
{
return $"--sort={order}{sortBy}";
return $@"--sort=""{order}{sortBy}""";
}

// Sort by dereferenced data
Expand All @@ -124,7 +124,7 @@ static ArgumentString SortCriteria(bool needTags, GitRefsSortBy sortBy, GitRefsS
// ref ordering (i.e. local and remote branches), and this is generally a significantly
// greater of two evils.
// Refer to https://github.com/gitextensions/gitextensions/issues/8621 for more info.
return $"--sort={order}*{sortBy} --sort={order}{sortBy}";
return $@"--sort=""{order}*{sortBy}"" --sort=""{order}{sortBy}""";
}

static ArgumentString GitRefsFormat(bool needTags)
Expand Down Expand Up @@ -303,7 +303,7 @@ public static ArgumentString MergedBranchesCmd(bool includeRemote = false, bool
{
return new GitArgumentBuilder("branch")
{
{ fullRefname, "--format=%(refname)" },
{ fullRefname, @"--format=""%(refname)""" },
{ includeRemote, "-a" },
"--merged",
commit
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void Save_Click(object sender, EventArgs e)
{
string format = GetSelectedOutputFormat() == OutputFormat.Zip ? "zip" : "tar";

var arguments = string.Format("archive --format={0} {1} --output \"{2}\" {3}", format, revision, saveFileDialog.FileName, GetPathArgumentFromGui());
var arguments = string.Format(@"archive --format=""{0}"" {1} --output ""{2}"" {3}", format, revision, saveFileDialog.FileName, GetPathArgumentFromGui());
FormProcess.ShowDialog(this, arguments, Module.WorkingDir, input: null, useDialogSettings: true);
Close();
}
Expand Down
4 changes: 2 additions & 2 deletions GitUI/CommitInfo/CommitInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ private void ShowAll(string? what)
{
GitArgumentBuilder args = new("for-each-ref")
{
"--sort=-taggerdate",
"--format=\"%(refname)\"",
@"--sort=""-taggerdate""",
@"--format=""%(refname)""",
"refs/tags/"
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void GetSortedTags_should_throw_on_git_warning()
{
RunCommitInfoTest(commitInfo =>
{
_gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/",
_gitExecutable.StageOutput(@"for-each-ref --sort=""-taggerdate"" --format=""%(refname)"" refs/tags/",
"refs/heads/master\nwarning: message");

((Action)(() => commitInfo.GetTestAccessor().GetSortedTags())).Should().Throw<RefsWarningException>();
Expand All @@ -68,7 +68,7 @@ public void GetSortedTags_should_split_output_if_no_warning()
{
RunCommitInfoTest(commitInfo =>
{
_gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/",
_gitExecutable.StageOutput(@"for-each-ref --sort=""-taggerdate"" --format=""%(refname)"" refs/tags/",
"refs/remotes/origin/master\nrefs/heads/master\nrefs/heads/warning"); // does not contain "warning:"

Dictionary<string, int> expected = new()
Expand All @@ -90,7 +90,7 @@ public void GetSortedTags_should_load_ref_different_in_case()
{
RunCommitInfoTest(commitInfo =>
{
_gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/",
_gitExecutable.StageOutput(@"for-each-ref --sort=""-taggerdate"" --format=""%(refname)"" refs/tags/",
"refs/remotes/origin/master\nrefs/heads/master\nrefs/remotes/origin/bugfix/YS-38651-test-twist-changes-r100-on-s375\nrefs/remotes/origin/bugfix/ys-38651-test-twist-changes-r100-on-s375"); // case sensitive duplicates

Dictionary<string, int> expected = new()
Expand All @@ -113,7 +113,7 @@ public void GetSortedTags_should_load_ref_with_extra_spaces()
{
RunCommitInfoTest(commitInfo =>
{
_gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/",
_gitExecutable.StageOutput(@"for-each-ref --sort=""-taggerdate"" --format=""%(refname)"" refs/tags/",
"refs/remotes/origin/master\nrefs/heads/master\nrefs/tags/v3.1\nrefs/tags/v3.1 \n refs/tags/v3.1"); // have leading and trailing spaces

Dictionary<string, int> expected = new()
Expand All @@ -137,7 +137,7 @@ public void GetSortedTags_should_remove_duplicate_refs()
{
RunCommitInfoTest(commitInfo =>
{
_gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/",
_gitExecutable.StageOutput(@"for-each-ref --sort=""-taggerdate"" --format=""%(refname)"" refs/tags/",
"refs/remotes/origin/master\nrefs/remotes/foo/duplicate\nrefs/remotes/foo/bar\nrefs/remotes/foo/duplicate\nrefs/remotes/foo/last"); // exact duplicates

Dictionary<string, int> expected = new()
Expand All @@ -164,7 +164,7 @@ private void RunCommitInfoTest(Action<GitUI.CommitInfo.CommitInfo> runTest)
uiCommandsSource.UICommands.Returns(x => _commands);

// the following assignment of CommitInfo.UICommandsSource will already call this command
_gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/", "");
_gitExecutable.StageOutput(@"for-each-ref --sort=""-taggerdate"" --format=""%(refname)"" refs/tags/", "");

return new GitUI.CommitInfo.CommitInfo
{
Expand Down
2 changes: 1 addition & 1 deletion Plugins/FindLargeFiles/FindLargeFilesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private void Delete_Click(object sender, EventArgs e)
AppSettings.GitCommand, gitObject.Path));
}

sb.AppendLine(string.Format("for /f %%a IN ('\"{0}\" for-each-ref --format=%%^(refname^) refs/original/') DO \"{0}\" update-ref -d %%a",
sb.AppendLine(string.Format(@"for /f %%a IN ('""{0}"" for-each-ref --format=""%%^(refname^)"" refs/original/') DO ""{0}"" update-ref -d %%a",
AppSettings.GitCommand));
sb.AppendLine(string.Format("\"{0}\" reflog expire --expire=now --all",
AppSettings.GitCommand));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void TestFetchArguments()
public void TestMergedBranchesCmd([Values(true, false)] bool includeRemote, [Values(true, false)] bool fullRefname,
[Values(null, "", " ", "HEAD", "1234567890")] string commit)
{
string formatArg = fullRefname ? " --format=%(refname)" : string.Empty;
string formatArg = fullRefname ? @" --format=""%(refname)""" : string.Empty;
string remoteArg = includeRemote ? " -a" : string.Empty;
string commitArg = string.IsNullOrWhiteSpace(commit) ? string.Empty : $" {commit}";
string expected = $"branch{formatArg}{remoteArg} --merged{commitArg}";
Expand Down Expand Up @@ -653,8 +653,8 @@ private static IEnumerable<TestCaseData> GetRefsCommandTestData
else
{
string prefix = sortOrder == GitRefsSortOrder.Ascending ? string.Empty : "-";
sortCondition = $" --sort={prefix}{sortBy}";
sortConditionRef = $" --sort={prefix}*{sortBy}";
sortCondition = $@" --sort=""{prefix}{sortBy}""";
sortConditionRef = $@" --sort=""{prefix}*{sortBy}""";
}

yield return new TestCaseData(RefsFilter.Tags | RefsFilter.Heads | RefsFilter.Remotes, /* noLocks */ false, sortBy, sortOrder, 0,
Expand Down