package util import ( "encoding/json" "strings" ) type CommitInfo struct { ChangedPaths []string `json:"changed_paths"` } // GetCommitInfo() works inside of a post-commit Git hook. // It assumes that the current working directory is inside a Git repo. func GetCommitInfo() (*CommitInfo, error) { stdout, _, err := Run( "git", "diff", "--cached", "--name-only", "--diff-filter=ACM", ) if err != nil { return nil, err } lines := strings.Split(stdout, "\n") for len(lines) > 0 && lines[len(lines)-1] == "" { lines = lines[:len(lines)-1] } return &CommitInfo{ChangedPaths: lines}, nil } func (ci *CommitInfo) DebugString() string { b, _ := json.MarshalIndent(ci, "", " ") return string(b) }