From 21f97eebd2d486ea0ee3659044ab85391d5cddba Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 7 Mar 2021 17:05:10 +0100 Subject: [PATCH] fix(git): use exact executable name can conflict with git.cmd relates to #315 --- src/segment_git.go | 6 ++++-- src/segment_git_test.go | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/segment_git.go b/src/segment_git.go index 6f6bd8caa02b..199b1584c068 100644 --- a/src/segment_git.go +++ b/src/segment_git.go @@ -112,8 +112,6 @@ const ( BehindColor Property = "behind_color" // AheadColor if set, the color to use when the branch is ahead and behind the remote AheadColor Property = "ahead_color" - - gitCommand = "git" ) func (g *git) enabled() bool { @@ -272,6 +270,10 @@ func (g *git) getStatusColor(defaultValue string) string { } func (g *git) getGitCommandOutput(args ...string) string { + gitCommand := "git" + if g.env.getRuntimeGOOS() == "windows" { + gitCommand = "git.exe" + } args = append([]string{"--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false"}, args...) val, _ := g.env.runCommand(gitCommand, args...) return val diff --git a/src/segment_git_test.go b/src/segment_git_test.go index 16ebaa92ef50..df713c896199 100644 --- a/src/segment_git_test.go +++ b/src/segment_git_test.go @@ -59,6 +59,7 @@ func TestGetGitOutputForCommand(t *testing.T) { want := "je suis le output" env := new(MockedEnvironment) env.On("runCommand", "git", append(args, commandArgs...)).Return(want, nil) + env.On("getRuntimeGOOS", nil).Return("unix") g := &git{ env: env, } @@ -103,6 +104,7 @@ func setupHEADContextEnv(context *detachedContext) *git { env.mockGitCommand(context.tagName, "describe", "--tags", "--exact-match") env.mockGitCommand(context.origin, "name-rev", "--name-only", "--exclude=tags/*", context.origin) env.mockGitCommand(context.onto, "name-rev", "--name-only", "--exclude=tags/*", context.onto) + env.On("getRuntimeGOOS", nil).Return("unix") g := &git{ env: env, repo: &gitRepo{ @@ -401,6 +403,7 @@ func TestParseGitStatsInvalidLine(t *testing.T) { func bootstrapUpstreamTest(upstream string) *git { env := &MockedEnvironment{} env.On("runCommand", "git", []string{"--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false", "remote", "get-url", "origin"}).Return(upstream, nil) + env.On("getRuntimeGOOS", nil).Return("unix") props := &properties{ values: map[Property]interface{}{ GithubIcon: "GH",