diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-21 21:59:25 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-21 22:07:14 +1100 |
commit | e18e81f5eb8eebf80f6e597c2d52823bb2c8ff14 (patch) | |
tree | 6ffb247d42e09a0e3c992f14dd9e73f1a0a6da90 | |
parent | 67a446234c678fe56f1c209b8b75d511cc2d1d94 (diff) |
don't pass single commands directly to RunCommand (or equivalent function)
when it contains percentages.
This is a really strange one. It's a linting warning in my editor
and it doesn't stop me from compiling, but it breaks `go test`.
A basic file to reproduce what I'm talking about:
package main
import "fmt"
func main() {
notSprintf("test %s") // compiler complains here thinking %s needs a corresponding argument
}
func notSprintf(formatStr string, formatArgs ...interface{}) string {
if formatArgs != nil {
return formatStr
}
return fmt.Sprintf(formatStr, formatArgs...)
}
-rw-r--r-- | pkg/commands/branch_list_builder.go | 4 | ||||
-rw-r--r-- | pkg/commands/git.go | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/pkg/commands/branch_list_builder.go b/pkg/commands/branch_list_builder.go index d7a232055..e5af76853 100644 --- a/pkg/commands/branch_list_builder.go +++ b/pkg/commands/branch_list_builder.go @@ -47,7 +47,9 @@ func (b *BranchListBuilder) obtainCurrentBranch() *Branch { func (b *BranchListBuilder) obtainReflogBranches() []*Branch { branches := make([]*Branch, 0) - rawString, err := b.GitCommand.OSCommand.RunCommandWithOutput("git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD") + // if we directly put this string in RunCommandWithOutput the compiler complains because it thinks it's a format string + unescaped := "git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD" + rawString, err := b.GitCommand.OSCommand.RunCommandWithOutput(unescaped) if err != nil { return branches } diff --git a/pkg/commands/git.go b/pkg/commands/git.go index fe0600065..3464215c7 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -157,7 +157,9 @@ func findDotGitDir(stat func(string) (os.FileInfo, error), readFile func(filenam // GetStashEntries stash entries func (c *GitCommand) GetStashEntries() []*StashEntry { - rawString, _ := c.OSCommand.RunCommandWithOutput("git stash list --pretty='%gs'") + // if we directly put this string in RunCommandWithOutput the compiler complains because it thinks it's a format string + unescaped := "git stash list --pretty='%gs'" + rawString, _ := c.OSCommand.RunCommandWithOutput(unescaped) stashEntries := []*StashEntry{} for i, line := range utils.SplitLines(rawString) { stashEntries = append(stashEntries, stashEntryFromLine(line, i)) |