1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

more support for files with spaces

This commit is contained in:
Jesse Duffield
2019-02-20 20:01:29 +11:00
committed by Jesse Duffield Duffield
parent 0173fdb9df
commit cdc50e8557
2 changed files with 9 additions and 5 deletions

View File

@ -433,8 +433,9 @@ func (c *GitCommand) RebaseMode() (string, error) {
// RemoveFile directly // RemoveFile directly
func (c *GitCommand) RemoveFile(file *File) error { func (c *GitCommand) RemoveFile(file *File) error {
// if the file isn't tracked, we assume you want to delete it // if the file isn't tracked, we assume you want to delete it
quotedFileName := c.OSCommand.Quote(file.Name)
if file.HasStagedChanges { 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 return err
} }
} }
@ -442,7 +443,7 @@ func (c *GitCommand) RemoveFile(file *File) error {
return c.removeFile(file.Name) return c.removeFile(file.Name)
} }
// if the file is tracked, we assume you want to just check it out // 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 // 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 // AddPatch prepares a subprocess for adding a patch by patch
// this will eventually be swapped out for a better solution inside the Gui // this will eventually be swapped out for a better solution inside the Gui
func (c *GitCommand) AddPatch(filename string) *exec.Cmd { 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` // 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) }() 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 { func (c *GitCommand) FastForward(branchName string) error {

View File

@ -208,7 +208,10 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error {
defer f.Close() defer f.Close()
_, err = f.WriteString("\n" + line) _, 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 // CreateTempFile writes a string to a new temp file and returns the file's name