1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-06 23:46:13 +02:00

handle filenames with spaces better

This commit is contained in:
Jesse Duffield 2018-08-19 20:13:29 +10:00
parent 2008607108
commit 35884f81e9
2 changed files with 10 additions and 13 deletions

View File

@ -83,7 +83,7 @@ func (c *GitCommand) GetStatusFiles() []File {
filename := statusString[3:] filename := statusString[3:]
tracked := !includes([]string{"??", "A ", "AM"}, change) tracked := !includes([]string{"??", "A ", "AM"}, change)
file := File{ file := File{
Name: filename, Name: c.OSCommand.Unquote(filename),
DisplayString: statusString, DisplayString: statusString,
HasStagedChanges: !includes([]string{" ", "U", "?"}, stagedChange), HasStagedChanges: !includes([]string{" ", "U", "?"}, stagedChange),
HasUnstagedChanges: unstagedChange != " ", HasUnstagedChanges: unstagedChange != " ",
@ -321,24 +321,24 @@ func (c *GitCommand) SquashFixupCommit(branchName string, shaValue string) error
} }
// CatFile obtain the contents of a file // CatFile obtain the contents of a file
func (c *GitCommand) CatFile(file string) (string, error) { func (c *GitCommand) CatFile(fileName string) (string, error) {
return c.OSCommand.RunCommandWithOutput("cat " + file) return c.OSCommand.RunCommandWithOutput("cat " + c.OSCommand.Quote(fileName))
} }
// StageFile stages a file // StageFile stages a file
func (c *GitCommand) StageFile(file string) error { func (c *GitCommand) StageFile(fileName string) error {
return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(file)) return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(fileName))
} }
// UnStageFile unstages a file // UnStageFile unstages a file
func (c *GitCommand) UnStageFile(file string, tracked bool) error { func (c *GitCommand) UnStageFile(fileName string, tracked bool) error {
var command string var command string
if tracked { if tracked {
command = "git reset HEAD " command = "git reset HEAD "
} else { } else {
command = "git rm --cached " command = "git rm --cached "
} }
return c.OSCommand.RunCommand(command + file) return c.OSCommand.RunCommand(command + c.OSCommand.Quote(fileName))
} }
// GitStatus returns the plaintext short status of the repo // GitStatus returns the plaintext short status of the repo
@ -364,7 +364,7 @@ func (c *GitCommand) RemoveFile(file File) error {
} }
} }
if !file.Tracked { if !file.Tracked {
return os.RemoveAll(c.OSCommand.Unquote(file.Name)) return os.RemoveAll(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("git checkout -- " + file.Name) return c.OSCommand.RunCommand("git checkout -- " + file.Name)
@ -479,12 +479,9 @@ func (c *GitCommand) Show(sha string) string {
// Diff returns the diff of a file // Diff returns the diff of a file
func (c *GitCommand) Diff(file File) string { func (c *GitCommand) Diff(file File) string {
cachedArg := "" cachedArg := ""
fileName := file.Name fileName := c.OSCommand.Quote(file.Name)
if file.HasStagedChanges && !file.HasUnstagedChanges { if file.HasStagedChanges && !file.HasUnstagedChanges {
cachedArg = "--cached" cachedArg = "--cached"
} else {
// if the file is staged and has spaces in it, it comes pre-quoted
fileName = c.OSCommand.Quote(fileName)
} }
trackedArg := "--" trackedArg := "--"
if !file.Tracked && !file.HasStagedChanges { if !file.Tracked && !file.HasStagedChanges {

View File

@ -45,7 +45,7 @@ func TestDiff(t *testing.T) {
DisplayString: " D deleted_staged", DisplayString: " D deleted_staged",
}, },
{ {
Name: "\"file with space staged\"", Name: "file with space staged",
HasStagedChanges: true, HasStagedChanges: true,
HasUnstagedChanges: false, HasUnstagedChanges: false,
Tracked: false, Tracked: false,