diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 23cfc2e46..d8530c209 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -433,8 +433,9 @@ func (c *GitCommand) RebaseMode() (string, error) { // RemoveFile directly func (c *GitCommand) RemoveFile(file *File) error { // if the file isn't tracked, we assume you want to delete it + quotedFileName := c.OSCommand.Quote(file.Name) if file.HasStagedChanges { - if err := c.OSCommand.RunCommand(fmt.Sprintf("git reset -- %s", file.Name)); err != nil { + if err := c.OSCommand.RunCommand(fmt.Sprintf("git reset -- %s", quotedFileName)); err != nil { return err } } @@ -442,7 +443,7 @@ func (c *GitCommand) RemoveFile(file *File) error { return c.removeFile(file.Name) } // if the file is tracked, we assume you want to just check it out - return c.OSCommand.RunCommand(fmt.Sprintf("git checkout -- %s", file.Name)) + return c.OSCommand.RunCommand(fmt.Sprintf("git checkout -- %s", quotedFileName)) } // Checkout checks out a branch, with --force if you set the force arg to true @@ -457,7 +458,7 @@ func (c *GitCommand) Checkout(branch string, force bool) error { // AddPatch prepares a subprocess for adding a patch by patch // this will eventually be swapped out for a better solution inside the Gui func (c *GitCommand) AddPatch(filename string) *exec.Cmd { - return c.OSCommand.PrepareSubProcess("git", "add", "--patch", filename) + return c.OSCommand.PrepareSubProcess("git", "add", "--patch", c.OSCommand.Quote(filename)) } // PrepareCommitSubProcess prepares a subprocess for `git commit` @@ -568,7 +569,7 @@ func (c *GitCommand) ApplyPatch(patch string) (string, error) { defer func() { _ = c.OSCommand.RemoveFile(filename) }() - return c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git apply --cached %s", filename)) + return c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git apply --cached %s", c.OSCommand.Quote(filename))) } func (c *GitCommand) FastForward(branchName string) error { diff --git a/pkg/commands/os.go b/pkg/commands/os.go index e5ae0a041..b6ef1a07f 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -208,7 +208,10 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error { defer f.Close() _, err = f.WriteString("\n" + line) - return errors.Wrap(err, 0) + if err != nil { + errors.Wrap(err, 0) + } + return nil } // CreateTempFile writes a string to a new temp file and returns the file's name