I'm trying to invoke git shortlog
from Go to grab the output, but I'm running into a wall.
Here's a working example of how I'm able to do this with git log
:
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
runBasicExample()
}
func runBasicExample() {
cmdOut, err := exec.Command("git", "log").Output()
if err != nil {
fmt.Fprintln(os.Stderr, "There was an error running the git command: ", err)
os.Exit(1)
}
output := string(cmdOut)
fmt.Printf("Output:
%s
", output)
}
Which gives expected output:
$> go run show-commits.go
Output:
commit 4abb96396c69fa4e604c9739abe338e03705f9d4
Author: TheAndruu
Date: Tue Aug 21 21:55:07 2018 -0400
Updating readme
But I really want to do this with git shortlog
.
For some reason... I just can't get it to work with shortlog. Here's the program again, with the only change being the git command line:
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
runBasicExample()
}
func runBasicExample() {
cmdOut, err := exec.Command("git", "shortlog").Output()
if err != nil {
fmt.Fprintln(os.Stderr, "There was an error running the git command: ", err)
os.Exit(1)
}
output := string(cmdOut)
fmt.Printf("Output:
%s
", output)
}
With empty output:
$> go run show-commits.go
Output:
I can run git shortlog
directly from the command line and it seems to work fine. Checking the docs, I'm led to believe the 'shortlog' command is part of git itself.
Can anyone help point out what I could do different?
Thanks