TheJet 1
TheJet 1

Reputation: 123

Using golang exec library to pass gitconfig arguments into git bash

I am trying to write a go script to setup the user's name in the gitconfig file.

I tried the following arguments shown in the code below in the terminal and it works when I manually input the arguments sequentially, but it does not work from golang.

cl := exec.Command("git", "-C", "config", "--global", "user.name", 
"myname")
stdout, err := cl.CombinedOutput()
if err != nil {
    log.Fatal(err)
}
fmt.Printf("%s", stdout)

From the code snippet I expect the code to generate a .gitconfig file and for the file to contain the name of the user. When I run the code I get exit status 128.

Upvotes: 1

Views: 275

Answers (1)

orirawlings
orirawlings

Reputation: 744

You probably shouldn't include the -C option without also giving it a path. If you are trying to add something to the global config, you probably don't need the -C option at all.

Upvotes: 2

Related Questions