aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-14 06:01:04 +0700
committerShulhan <ms@kilabit.info>2026-01-14 06:01:04 +0700
commit3a5a19786171b7db01b490f68c791fcfc89647f5 (patch)
treeeaf4fff139107fa6e95f91fbfc243f32dff40e93
parentd18ec5d8635bf3dc02b23acdbf861ce518e54058 (diff)
downloadpakakeh.go-3a5a19786171b7db01b490f68c791fcfc89647f5.tar.xz
lib/git: pass "--" when running LogFollow command
The "--" prevent ambiguous argument, to separate a path from revision. While at it, add more test case for LogFollow.
-rw-r--r--lib/git/git.go2
-rw-r--r--lib/git/git_test.go49
2 files changed, 34 insertions, 17 deletions
diff --git a/lib/git/git.go b/lib/git/git.go
index 3ee5c376..3e41f16d 100644
--- a/lib/git/git.go
+++ b/lib/git/git.go
@@ -284,7 +284,7 @@ func (git *Git) LogFollow(path, format string) (logs []string, err error) {
var cmd *exec.Cmd
cmd = exec.Command(`git`)
- cmd.Args = append(cmd.Args, `--no-pager`, `log`, `--follow`, `--format=`+format, path)
+ cmd.Args = append(cmd.Args, `--no-pager`, `log`, `--follow`, `--format=`+format, `--`, path)
cmd.Dir = git.absDir
cmd.Stderr = _stderr
diff --git a/lib/git/git_test.go b/lib/git/git_test.go
index e4cb5a26..f67fa1aa 100644
--- a/lib/git/git_test.go
+++ b/lib/git/git_test.go
@@ -199,23 +199,40 @@ func TestGit_LogFollow(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- path := `lib/_hunspell/affix.go`
- logs, err := agit.LogFollow(path, ``)
- if err != nil {
- t.Fatal(err)
- }
- exp := []string{
- `144549f8,1737804887,Shulhan,ms@kilabit.info,lib/hunspell: rename the package to "_hunspell"`,
- `66e6542e,1694357806,Shulhan,ms@kilabit.info,lib/hunspell: realign struct for better size allocation`,
- `0c9abc1a,1652108042,Shulhan,ms@kilabit.info,all: reformat all codes using gofmt 1.19 (the Go tip)`,
- `9ca9757d,1591803682,Shulhan,m.shulhan@gmail.com,all: update email address`,
- `b0fa5a47,1585156612,Shulhan,m.shulhan@gmail.com,all: fix and suppress linter warnings`,
- `33d58b98,1585151378,Shulhan,m.shulhan@gmail.com,hunspell: add field Parent to Stem`,
- `367e15a8,1585139124,Shulhan,m.shulhan@gmail.com,hunspell: change the stem.apply parameter from string to *Stem`,
- `099a24de,1579628651,Shulhan,m.shulhan@gmail.com,hunspell: split the affix options and dictionary into different types`,
- `3d772dff,1572967023,Shulhan,m.shulhan@gmail.com,lib/hunspell: implementation of hunspell in pure Go`,
+ listCase := []struct {
+ path string
+ expError string
+ exp []string
+ }{{
+ path: `lib/_hunspell/affix.go`,
+ exp: []string{
+ `144549f8,1737804887,Shulhan,ms@kilabit.info,lib/hunspell: rename the package to "_hunspell"`,
+ `66e6542e,1694357806,Shulhan,ms@kilabit.info,lib/hunspell: realign struct for better size allocation`,
+ `0c9abc1a,1652108042,Shulhan,ms@kilabit.info,all: reformat all codes using gofmt 1.19 (the Go tip)`,
+ `9ca9757d,1591803682,Shulhan,m.shulhan@gmail.com,all: update email address`,
+ `b0fa5a47,1585156612,Shulhan,m.shulhan@gmail.com,all: fix and suppress linter warnings`,
+ `33d58b98,1585151378,Shulhan,m.shulhan@gmail.com,hunspell: add field Parent to Stem`,
+ `367e15a8,1585139124,Shulhan,m.shulhan@gmail.com,hunspell: change the stem.apply parameter from string to *Stem`,
+ `099a24de,1579628651,Shulhan,m.shulhan@gmail.com,hunspell: split the affix options and dictionary into different types`,
+ `3d772dff,1572967023,Shulhan,m.shulhan@gmail.com,lib/hunspell: implementation of hunspell in pure Go`,
+ },
+ }, {
+ path: `lib/contact/yahoo/testdata/contact.json`,
+ exp: []string{
+ `9229335b,1538392744,Shulhan,ms@kilabit.info,Merge package "github.com/shuLhan/gontacts"`,
+ },
+ }, {
+ path: `not_exist`,
+ expError: `LogFollow not_exist: exit status 128`,
+ }}
+ for _, tc := range listCase {
+ logs, err := agit.LogFollow(tc.path, ``)
+ if err != nil {
+ test.Assert(t, tc.path+` error`, tc.expError, err.Error())
+ continue
+ }
+ test.Assert(t, tc.path, tc.exp, logs)
}
- test.Assert(t, path, exp, logs)
}
func TestGetRemoteURL(t *testing.T) {