Skip to content

Commit 9c03921

Browse files
authored
fix: escape double quotes in quoted git command strings (#1559)
1 parent bfd639c commit 9c03921

31 files changed

+86
-102
lines changed

src/Commands/Add.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public Add(string repo, Models.Change change)
1313
{
1414
WorkingDirectory = repo;
1515
Context = repo;
16-
Args = $"add -- \"{change.Path}\"";
16+
Args = $"add -- {change.Path.Quoted()}";
1717
}
1818

1919
public Add(string repo, string pathspecFromFile)
2020
{
2121
WorkingDirectory = repo;
2222
Context = repo;
23-
Args = $"add --pathspec-from-file=\"{pathspecFromFile}\"";
23+
Args = $"add --pathspec-from-file={pathspecFromFile.Quoted()}";
2424
}
2525
}
2626
}

src/Commands/Apply.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceM
1313
Args += $"--whitespace={whitespaceMode} ";
1414
if (!string.IsNullOrEmpty(extra))
1515
Args += $"{extra} ";
16-
Args += $"\"{file}\"";
16+
Args += $"{file.Quoted()}";
1717
}
1818
}
1919
}

src/Commands/Archive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public Archive(string repo, string revision, string saveTo)
66
{
77
WorkingDirectory = repo;
88
Context = repo;
9-
Args = $"archive --format=zip --verbose --output=\"{saveTo}\" {revision}";
9+
Args = $"archive --format=zip --verbose --output={saveTo.Quoted()} {revision}";
1010
}
1111
}
1212
}

src/Commands/AssumeUnchanged.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public AssumeUnchanged(string repo, string file, bool bAdd)
88

99
WorkingDirectory = repo;
1010
Context = repo;
11-
Args = $"update-index {mode} -- \"{file}\"";
11+
Args = $"update-index {mode} -- {file.Quoted()}";
1212
}
1313
}
1414
}

src/Commands/Blame.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public Blame(string repo, string file, string revision)
1414
{
1515
WorkingDirectory = repo;
1616
Context = repo;
17-
Args = $"blame -t {revision} -- \"{file}\"";
17+
Args = $"blame -t {revision} -- {file.Quoted()}";
1818
RaiseError = false;
1919

2020
_result.File = file;

src/Commands/Checkout.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ public async Task<bool> UseTheirsAsync(List<string> files)
5151
var builder = new StringBuilder();
5252
builder.Append("checkout --theirs --");
5353
foreach (var f in files)
54-
{
55-
builder.Append(" \"");
56-
builder.Append(f);
57-
builder.Append("\"");
58-
}
54+
builder.Append(' ').Append(f.Quoted());
5955
Args = builder.ToString();
6056
return await ExecAsync().ConfigureAwait(false);
6157
}
@@ -65,19 +61,15 @@ public async Task<bool> UseMineAsync(List<string> files)
6561
var builder = new StringBuilder();
6662
builder.Append("checkout --ours --");
6763
foreach (var f in files)
68-
{
69-
builder.Append(" \"");
70-
builder.Append(f);
71-
builder.Append("\"");
72-
}
64+
builder.Append(' ').Append(f.Quoted());
7365

7466
Args = builder.ToString();
7567
return await ExecAsync().ConfigureAwait(false);
7668
}
7769

7870
public async Task<bool> FileWithRevisionAsync(string file, string revision)
7971
{
80-
Args = $"checkout --no-overlay {revision} -- \"{file}\"";
72+
Args = $"checkout --no-overlay {revision} -- {file.Quoted()}";
8173
return await ExecAsync().ConfigureAwait(false);
8274
}
8375
}

src/Commands/Command.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ private ProcessStartInfo CreateGitStartInfo(bool redirect)
187187
// Force using this app as git editor.
188188
start.Arguments += Editor switch
189189
{
190-
EditorType.CoreEditor => $"""-c core.editor="\"{selfExecFile}\" --core-editor" """,
191-
EditorType.RebaseEditor => $"""-c core.editor="\"{selfExecFile}\" --rebase-message-editor" -c sequence.editor="\"{selfExecFile}\" --rebase-todo-editor" -c rebase.abbreviateCommands=true """,
190+
EditorType.CoreEditor => $"""-c core.editor="{selfExecFile.Quoted()} --core-editor" """,
191+
EditorType.RebaseEditor => $"""-c core.editor="{selfExecFile.Quoted()} --rebase-message-editor" -c sequence.editor="{selfExecFile.Quoted()} --rebase-todo-editor" -c rebase.abbreviateCommands=true """,
192192
_ => "-c core.editor=true ",
193193
};
194194

src/Commands/Commit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public Commit(string repo, string message, bool signOff, bool amend, bool resetA
1212

1313
WorkingDirectory = repo;
1414
Context = repo;
15-
Args = $"commit --allow-empty --file=\"{_tmpFile}\"";
15+
Args = $"commit --allow-empty --file={_tmpFile.Quoted()}";
1616
if (signOff)
1717
Args += " --signoff";
1818
if (amend)

src/Commands/CompareRevisions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public CompareRevisions(string repo, string start, string end, string path)
2727
Context = repo;
2828

2929
var based = string.IsNullOrEmpty(start) ? "-R" : start;
30-
Args = $"diff --name-status {based} {end} -- \"{path}\"";
30+
Args = $"diff --name-status {based} {end} -- {path.Quoted()}";
3131
}
3232

3333
public async Task<List<Models.Change>> ReadAsync()

src/Commands/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async Task<bool> SetAsync(string key, string value, bool allowEmpty = fal
5555
if (!allowEmpty && string.IsNullOrWhiteSpace(value))
5656
Args = $"config {scope} --unset {key}";
5757
else
58-
Args = $"config {scope} {key} \"{value}\"";
58+
Args = $"config {scope} {key} {value.Quoted()}";
5959

6060
return await ExecAsync().ConfigureAwait(false);
6161
}

0 commit comments

Comments
 (0)