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
4 changes: 2 additions & 2 deletions src/Commands/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public Add(string repo, Models.Change change)
{
WorkingDirectory = repo;
Context = repo;
Args = $"add -- \"{change.Path}\"";
Args = $"add -- {change.Path.Quoted()}";
}

public Add(string repo, string pathspecFromFile)
{
WorkingDirectory = repo;
Context = repo;
Args = $"add --pathspec-from-file=\"{pathspecFromFile}\"";
Args = $"add --pathspec-from-file={pathspecFromFile.Quoted()}";
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/Apply.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceM
Args += $"--whitespace={whitespaceMode} ";
if (!string.IsNullOrEmpty(extra))
Args += $"{extra} ";
Args += $"\"{file}\"";
Args += $"{file.Quoted()}";
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public Archive(string repo, string revision, string saveTo)
{
WorkingDirectory = repo;
Context = repo;
Args = $"archive --format=zip --verbose --output=\"{saveTo}\" {revision}";
Args = $"archive --format=zip --verbose --output={saveTo.Quoted()} {revision}";
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/AssumeUnchanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public AssumeUnchanged(string repo, string file, bool bAdd)

WorkingDirectory = repo;
Context = repo;
Args = $"update-index {mode} -- \"{file}\"";
Args = $"update-index {mode} -- {file.Quoted()}";
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/Blame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Blame(string repo, string file, string revision)
{
WorkingDirectory = repo;
Context = repo;
Args = $"blame -t {revision} -- \"{file}\"";
Args = $"blame -t {revision} -- {file.Quoted()}";
RaiseError = false;

_result.File = file;
Expand Down
14 changes: 3 additions & 11 deletions src/Commands/Checkout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ public async Task<bool> UseTheirsAsync(List<string> files)
var builder = new StringBuilder();
builder.Append("checkout --theirs --");
foreach (var f in files)
{
builder.Append(" \"");
builder.Append(f);
builder.Append("\"");
}
builder.Append(' ').Append(f.Quoted());
Args = builder.ToString();
return await ExecAsync().ConfigureAwait(false);
}
Expand All @@ -65,19 +61,15 @@ public async Task<bool> UseMineAsync(List<string> files)
var builder = new StringBuilder();
builder.Append("checkout --ours --");
foreach (var f in files)
{
builder.Append(" \"");
builder.Append(f);
builder.Append("\"");
}
builder.Append(' ').Append(f.Quoted());

Args = builder.ToString();
return await ExecAsync().ConfigureAwait(false);
}

public async Task<bool> FileWithRevisionAsync(string file, string revision)
{
Args = $"checkout --no-overlay {revision} -- \"{file}\"";
Args = $"checkout --no-overlay {revision} -- {file.Quoted()}";
return await ExecAsync().ConfigureAwait(false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ private ProcessStartInfo CreateGitStartInfo(bool redirect)
// Force using this app as git editor.
start.Arguments += Editor switch
{
EditorType.CoreEditor => $"""-c core.editor="\"{selfExecFile}\" --core-editor" """,
EditorType.RebaseEditor => $"""-c core.editor="\"{selfExecFile}\" --rebase-message-editor" -c sequence.editor="\"{selfExecFile}\" --rebase-todo-editor" -c rebase.abbreviateCommands=true """,
EditorType.CoreEditor => $"""-c core.editor="{selfExecFile.Quoted()} --core-editor" """,
EditorType.RebaseEditor => $"""-c core.editor="{selfExecFile.Quoted()} --rebase-message-editor" -c sequence.editor="{selfExecFile.Quoted()} --rebase-todo-editor" -c rebase.abbreviateCommands=true """,
_ => "-c core.editor=true ",
};

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public Commit(string repo, string message, bool signOff, bool amend, bool resetA

WorkingDirectory = repo;
Context = repo;
Args = $"commit --allow-empty --file=\"{_tmpFile}\"";
Args = $"commit --allow-empty --file={_tmpFile.Quoted()}";
if (signOff)
Args += " --signoff";
if (amend)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/CompareRevisions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CompareRevisions(string repo, string start, string end, string path)
Context = repo;

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

public async Task<List<Models.Change>> ReadAsync()
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task<bool> SetAsync(string key, string value, bool allowEmpty = fal
if (!allowEmpty && string.IsNullOrWhiteSpace(value))
Args = $"config {scope} --unset {key}";
else
Args = $"config {scope} {key} \"{value}\"";
Args = $"config {scope} {key} {value.Quoted()}";

return await ExecAsync().ConfigureAwait(false);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/DiffTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void Open()
}
else if (File.Exists(_exec))
{
Args = $"-c difftool.sourcegit.cmd=\"\\\"{_exec}\\\" {_merger.DiffCmd}\" difftool --tool=sourcegit --no-prompt {_option}";
var cmd = $"{_exec.Quoted()} {_merger.DiffCmd}";
Args = $"-c difftool.sourcegit.cmd={cmd.Quoted()} difftool --tool=sourcegit --no-prompt {_option}";
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/FormatPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public FormatPatch(string repo, string commit, string saveTo)
WorkingDirectory = repo;
Context = repo;
Editor = EditorType.None;
Args = $"format-patch {commit} -1 --output=\"{saveTo}\"";
Args = $"format-patch {commit} -1 --output={saveTo.Quoted()}";
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/IsBinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public IsBinary(string repo, string commit, string path)
{
WorkingDirectory = repo;
Context = repo;
Args = $"diff {Models.Commit.EmptyTreeSHA1} {commit} --numstat -- \"{path}\"";
Args = $"diff {Models.Commit.EmptyTreeSHA1} {commit} --numstat -- {path.Quoted()}";
RaiseError = false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/IsLFSFiltered.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public IsLFSFiltered(string repo, string path)
{
WorkingDirectory = repo;
Context = repo;
Args = $"check-attr -z filter \"{path}\"";
Args = $"check-attr -z filter {path.Quoted()}";
RaiseError = false;
}

public IsLFSFiltered(string repo, string sha, string path)
{
WorkingDirectory = repo;
Context = repo;
Args = $"check-attr --source {sha} -z filter \"{path}\"";
Args = $"check-attr --source {sha} -z filter {path.Quoted()}";
RaiseError = false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Commands/LFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<bool> InstallAsync(Models.ICommandLog log)
public async Task<bool> TrackAsync(string pattern, bool isFilenameMode, Models.ICommandLog log)
{
var opt = isFilenameMode ? "--filename" : "";
return await new SubCmd(_repo, $"lfs track {opt} \"{pattern}\"", log).ExecAsync().ConfigureAwait(false);
return await new SubCmd(_repo, $"lfs track {opt} {pattern.Quoted()}", log).ExecAsync().ConfigureAwait(false);
}

public async Task FetchAsync(string remote, Models.ICommandLog log)
Expand Down Expand Up @@ -101,13 +101,13 @@ public async Task PruneAsync(Models.ICommandLog log)

public async Task<bool> LockAsync(string remote, string file, Models.ICommandLog log)
{
return await new SubCmd(_repo, $"lfs lock --remote={remote} \"{file}\"", log).ExecAsync().ConfigureAwait(false);
return await new SubCmd(_repo, $"lfs lock --remote={remote} {file.Quoted()}", log).ExecAsync().ConfigureAwait(false);
}

public async Task<bool> UnlockAsync(string remote, string file, bool force, Models.ICommandLog log)
{
var opt = force ? "-f" : "";
return await new SubCmd(_repo, $"lfs unlock --remote={remote} {opt} \"{file}\"", log).ExecAsync().ConfigureAwait(false);
return await new SubCmd(_repo, $"lfs unlock --remote={remote} {opt} {file.Quoted()}", log).ExecAsync().ConfigureAwait(false);
}

public async Task<bool> UnlockAsync(string remote, long id, bool force, Models.ICommandLog log)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Merge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Merge(string repo, List<string> targets, bool autoCommit, string strategy
var builder = new StringBuilder();
builder.Append("merge --progress ");
if (!string.IsNullOrEmpty(strategy))
builder.Append($"--strategy={strategy} ");
builder.Append("--strategy=").Append(strategy).Append(' ');
if (!autoCommit)
builder.Append("--no-commit ");

Expand Down
5 changes: 3 additions & 2 deletions src/Commands/MergeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public MergeTool(string repo, int type, string exec, string file)

_merger = Models.ExternalMerger.Supported.Find(x => x.Type == type);
_exec = exec;
_file = string.IsNullOrEmpty(file) ? "" : $"\"{file}\"";
_file = string.IsNullOrEmpty(file) ? "" : $"{file.Quoted()}";
}

public async Task<bool> OpenAsync()
Expand All @@ -29,7 +29,8 @@ public async Task<bool> OpenAsync()
}
else if (File.Exists(_exec))
{
Args = $"-c mergetool.sourcegit.cmd=\"\\\"{_exec}\\\" {_merger.Cmd}\" -c mergetool.writeToTemp=true -c mergetool.keepBackup=false -c mergetool.trustExitCode=true mergetool --tool=sourcegit {_file}";
var cmd = $"{_exec.Quoted()} {_merger.Cmd}";
Args = $"-c mergetool.sourcegit.cmd={cmd.Quoted()} -c mergetool.writeToTemp=true -c mergetool.keepBackup=false -c mergetool.trustExitCode=true mergetool --tool=sourcegit {_file}";
}
else
{
Expand Down
8 changes: 3 additions & 5 deletions src/Commands/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ public Move(string repo, string oldPath, string newPath, bool force)
builder.Append("mv -v ");
if (force)
builder.Append("-f ");
builder.Append('"');
builder.Append(oldPath);
builder.Append("\" \"");
builder.Append(newPath);
builder.Append('"');
builder.Append(oldPath.Quoted());
builder.Append(' ');
builder.Append(newPath.Quoted());

Args = builder.ToString();
}
Expand Down
15 changes: 6 additions & 9 deletions src/Commands/QueryCommits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method

if (method == Models.CommitSearchMethod.ByAuthor)
{
search += $"-i --author=\"{filter}\"";
search += $"-i --author={filter.Quoted()}";
}
else if (method == Models.CommitSearchMethod.ByCommitter)
{
search += $"-i --committer=\"{filter}\"";
search += $"-i --committer={filter.Quoted()}";
}
else if (method == Models.CommitSearchMethod.ByMessage)
{
Expand All @@ -34,21 +34,18 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method

var words = filter.Split([' ', '\t', '\r'], StringSplitOptions.RemoveEmptyEntries);
foreach (var word in words)
{
var escaped = word.Trim().Replace("\"", "\\\"", StringComparison.Ordinal);
argsBuilder.Append($"--grep=\"{escaped}\" ");
}
argsBuilder.Append("--grep=").Append(word.Trim().Quoted()).Append(' ');
argsBuilder.Append("--all-match -i");

search = argsBuilder.ToString();
}
else if (method == Models.CommitSearchMethod.ByPath)
{
search += $"-- \"{filter}\"";
search += $"-- {filter.Quoted()}";
}
else
{
search = $"-G\"{filter}\"";
search = $"-G{filter.Quoted()}";
}

WorkingDirectory = repo;
Expand Down Expand Up @@ -126,7 +123,7 @@ private void ParseParent(string data)

private async Task MarkFirstMergedAsync()
{
Args = $"log --since=\"{_commits[^1].CommitterTimeStr}\" --format=\"%H\"";
Args = $"log --since={_commits[^1].CommitterTimeStr.Quoted()} --format=\"%H\"";

var rs = await ReadToEndAsync().ConfigureAwait(false);
var shas = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/QueryFileContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static async Task<Stream> RunAsync(string repo, string revision, string f
var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitExecutable;
starter.Arguments = $"show {revision}:\"{file}\"";
starter.Arguments = $"show {revision}:{file.Quoted()}";
starter.UseShellExecute = false;
starter.CreateNoWindow = true;
starter.WindowStyle = ProcessWindowStyle.Hidden;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/QueryFileSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public QueryFileSize(string repo, string file, string revision)
{
WorkingDirectory = repo;
Context = repo;
Args = $"ls-tree {revision} -l -- \"{file}\"";
Args = $"ls-tree {revision} -l -- {file.Quoted()}";
}

public async Task<long> GetResultAsync()
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/QueryRevisionObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public QueryRevisionObjects(string repo, string sha, string parentFolder)
Args = $"ls-tree {sha}";

if (!string.IsNullOrEmpty(parentFolder))
Args += $" -- \"{parentFolder}\"";
Args += $" -- {parentFolder.Quoted()}";
}

public async Task<List<Models.Object>> GetResultAsync()
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/QueryStagedFileBlobGuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public QueryStagedFileBlobGuid(string repo, string file)
{
WorkingDirectory = repo;
Context = repo;
Args = $"ls-files -s -- \"{file}\"";
Args = $"ls-files -s -- {file.Quoted()}";
}

public async Task<string> GetResultAsync()
Expand Down
6 changes: 1 addition & 5 deletions src/Commands/QuerySubmodules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ public QuerySubmodules(string repo)
foreach (var kv in map)
{
if (kv.Value.Status == Models.SubmoduleStatus.Normal)
{
builder.Append('"');
builder.Append(kv.Key);
builder.Append("\" ");
}
builder.Append(kv.Key.Quoted()).Append(' ');
}

Args = $"--no-optional-locks status --porcelain -- {builder}";
Expand Down
14 changes: 3 additions & 11 deletions src/Commands/Restore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ public Restore(string repo, Models.Change stagedChange)
Context = repo;

var builder = new StringBuilder();
builder.Append("restore --staged -- \"");
builder.Append(stagedChange.Path);
builder.Append('"');
builder.Append("restore --staged -- ").Append(stagedChange.Path.Quoted());

if (stagedChange.Index == Models.ChangeState.Renamed)
{
builder.Append(" \"");
builder.Append(stagedChange.OriginalPath);
builder.Append('"');
}
builder.Append(' ').Append(stagedChange.OriginalPath.Quoted());

Args = builder.ToString();
}
Expand All @@ -43,9 +37,7 @@ public Restore(string repo, string pathspecFile, bool isStaged)
var builder = new StringBuilder();
builder.Append("restore ");
builder.Append(isStaged ? "--staged " : "--worktree --recurse-submodules ");
builder.Append("--pathspec-from-file=\"");
builder.Append(pathspecFile);
builder.Append('"');
builder.Append("--pathspec-from-file=").Append(pathspecFile.Quoted());

Args = builder.ToString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/SaveRevisionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static async Task RunAsync(string repo, string revision, string file, str
}
else
{
await ExecCmdAsync(repo, $"show {revision}:\"{file}\"", saveTo).ConfigureAwait(false);
await ExecCmdAsync(repo, $"show {revision}:{file.Quoted()}", saveTo).ConfigureAwait(false);
}
}

Expand Down
Loading