1
0
Fork 0
mirror of https://github.com/Luzifer/git-changerelease.git synced 2024-12-20 19:11:17 +00:00
git-changerelease/git.go
Knut Ahlers fa7cfd9e9e
fix wrong bump when patch and minor are included
In previous versions the bump type was not calculated correctly when a
minor commit and a patch type commit were included in a release. Instead
of using the minor-bump it used the patch-bump because minor was the
default and patch overruled minor.
2016-07-21 17:51:08 +02:00

78 lines
1.3 KiB
Go

package main
import (
"bytes"
"errors"
"os"
"os/exec"
"strings"
)
var (
gitLogFormat string
gitLogFormatParts = []string{
`%h`, // ShortHash
`%s`, // Subject
`%an`, // AuthorName
`%ae`, // AuthorEmail
}
)
func init() {
gitLogFormat = strings.Join(gitLogFormatParts, `%x09`)
}
type commit struct {
ShortHash string
Subject string
AuthorName string
AuthorEmail string
BumpType semVerBump
}
func parseCommit(line string) (*commit, error) {
t := strings.Split(line, "\t")
if len(t) != 4 {
return nil, errors.New("Unexpected line format")
}
c := &commit{
ShortHash: t[0],
Subject: t[1],
AuthorName: t[2],
AuthorEmail: t[3],
}
for rex, bt := range matchers {
if rex.MatchString(c.Subject) && bt > c.BumpType {
c.BumpType = bt
}
}
if c.BumpType == semVerBumpUndecided {
c.BumpType = semVerBumpMinor
}
return c, nil
}
func git(stderrEnabled bool, args ...string) (string, error) {
buf := bytes.NewBuffer([]byte{})
cmd := exec.Command("git", args...)
cmd.Stdout = buf
if stderrEnabled {
cmd.Stderr = os.Stderr
}
err := cmd.Run()
return strings.TrimSpace(buf.String()), err
}
func gitErr(args ...string) (string, error) {
return git(true, args...)
}
func gitSilent(args ...string) (string, error) {
return git(false, args...)
}