mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
support files with spaces in name
This commit is contained in:
parent
77080f44a4
commit
574b34930c
@ -327,7 +327,7 @@ func (c *GitCommand) CatFile(file string) (string, error) {
|
|||||||
|
|
||||||
// StageFile stages a file
|
// StageFile stages a file
|
||||||
func (c *GitCommand) StageFile(file string) error {
|
func (c *GitCommand) StageFile(file string) error {
|
||||||
return c.OSCommand.RunCommand("git add " + file)
|
return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(file))
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnStageFile unstages a file
|
// UnStageFile unstages a file
|
||||||
@ -474,8 +474,12 @@ 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
|
||||||
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)
|
||||||
}
|
}
|
||||||
deletedArg := ""
|
deletedArg := ""
|
||||||
if file.Deleted {
|
if file.Deleted {
|
||||||
@ -485,7 +489,8 @@ func (c *GitCommand) Diff(file File) string {
|
|||||||
if !file.Tracked && !file.HasStagedChanges {
|
if !file.Tracked && !file.HasStagedChanges {
|
||||||
trackedArg = "--no-index /dev/null"
|
trackedArg = "--no-index /dev/null"
|
||||||
}
|
}
|
||||||
command := "git diff --color " + cachedArg + deletedArg + trackedArg + file.Name
|
command := fmt.Sprintf("%s %s %s %s %s", "git diff --color ", cachedArg, deletedArg, trackedArg, fileName)
|
||||||
|
|
||||||
// for now we assume an error means the file was deleted
|
// for now we assume an error means the file was deleted
|
||||||
s, _ := c.OSCommand.RunCommandWithOutput(command)
|
s, _ := c.OSCommand.RunCommandWithOutput(command)
|
||||||
return s
|
return s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user