summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorRyooooooga <ryoga_314@yahoo.co.jp>2021-03-02 12:04:12 +0900
committerJesse Duffield <jessedduffield@gmail.com>2021-03-13 11:02:31 +1100
commit9ed3a8ee0561f92ae75c739f0bad749e782bafa2 (patch)
tree63ccedb59352b8c05ae3782dcf6eeb4270ce300b /pkg/commands
parent64daf1310d63bb5c6334ce0cd06287869bac3218 (diff)
Fix staging/unstaging filenames that starts with `-` or `--`
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/files.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/pkg/commands/files.go b/pkg/commands/files.go
index 6938bd87b..a882d2b87 100644
--- a/pkg/commands/files.go
+++ b/pkg/commands/files.go
@@ -22,7 +22,7 @@ func (c *GitCommand) CatFile(fileName string) (string, error) {
func (c *GitCommand) StageFile(fileName string) error {
// renamed files look like "file1 -> file2"
fileNames := strings.Split(fileName, " -> ")
- return c.OSCommand.RunCommand("git add %s", c.OSCommand.Quote(fileNames[len(fileNames)-1]))
+ return c.OSCommand.RunCommand("git add -- %s", c.OSCommand.Quote(fileNames[len(fileNames)-1]))
}
// StageAll stages all files
@@ -37,9 +37,9 @@ func (c *GitCommand) UnstageAll() error {
// UnStageFile unstages a file
func (c *GitCommand) UnStageFile(fileName string, tracked bool) error {
- command := "git rm --cached --force %s"
+ command := "git rm --cached --force -- %s"
if tracked {
- command = "git reset HEAD %s"
+ command = "git reset HEAD -- %s"
}
// renamed files look like "file1 -> file2"
@@ -141,7 +141,7 @@ func (c *GitCommand) WorktreeFileDiff(file *models.File, plain bool, cached bool
func (c *GitCommand) WorktreeFileDiffCmdStr(file *models.File, plain bool, cached bool) string {
cachedArg := ""
- trackedArg := "--"
+ trackedArg := ""
colorArg := c.colorArg()
split := strings.Split(file.Name, " -> ") // in case of a renamed file we get the new filename
fileName := c.OSCommand.Quote(split[len(split)-1])
@@ -155,7 +155,7 @@ func (c *GitCommand) WorktreeFileDiffCmdStr(file *models.File, plain bool, cache
colorArg = "never"
}
- return fmt.Sprintf("git diff --submodule --no-ext-diff --color=%s %s %s %s", colorArg, cachedArg, trackedArg, fileName)
+ return fmt.Sprintf("git diff --submodule --no-ext-diff --color=%s %s %s -- %s", colorArg, cachedArg, trackedArg, fileName)
}
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {