Skip to content

Commit

Permalink
fix(git): use exact executable name
Browse files Browse the repository at this point in the history
can conflict with git.cmd

relates to #315
  • Loading branch information
JanDeDobbeleer committed Mar 7, 2021
1 parent f96f7ec commit 21f97ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/segment_git.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/segment_git_test.go
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 21f97ee

Please sign in to comment.