Skip to content

Commit

Permalink
Add description parsing to allow subtree merges
Browse files Browse the repository at this point in the history
Now git commit messages are parsed so that their contents can be
examined. This is similar to the commits that are exempt from validation using
the bump prefix.
  • Loading branch information
Jeff Peeler committed Jun 15, 2017
1 parent cfe8621 commit 196dc11
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tools/rebasehelpers/commitchecker/commitchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ func main() {

// TODO: Filter out bump commits for now until we decide how to deal with
// them correctly.
// TODO: ...along with subtree merges.
nonbumpCommits := []util.Commit{}
for _, commit := range commits {
if !strings.HasPrefix(commit.Summary, "bump(") {
lastDescriptionLine := commit.Description[len(commit.Description)-1]
if !strings.HasPrefix(commit.Summary, "bump(") && !strings.HasPrefix(lastDescriptionLine, "git-subtree-split:") {
nonbumpCommits = append(nonbumpCommits, commit)
}
}
Expand Down
25 changes: 22 additions & 3 deletions tools/rebasehelpers/util/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ var SupportedHosts = map[string]int{
}

type Commit struct {
Sha string
Summary string
Files []File
Sha string
Summary string
Description []string
Files []File
}

func (c Commit) DeclaresUpstreamChange() bool {
Expand Down Expand Up @@ -214,12 +215,14 @@ func CommitsBetween(a, b string) ([]Commit, error) {

func NewCommitFromOnelineLog(log string) (Commit, error) {
var commit Commit
var err error
parts := strings.Split(log, " ")
if len(parts) < 2 {
return commit, fmt.Errorf("invalid log entry: %s", log)
}
commit.Sha = parts[0]
commit.Summary = strings.Join(parts[1:], " ")
commit.Description, err = descriptionInCommit(commit.Sha)
files, err := filesInCommit(commit.Sha)
if err != nil {
return commit, err
Expand Down Expand Up @@ -335,6 +338,22 @@ func filesInCommit(sha string) ([]File, error) {
return files, nil
}

func descriptionInCommit(sha string) ([]string, error) {
descriptionLines := []string{}
stdout, stderr, err := run("git", "show", "--quiet", sha)
if err != nil {
return descriptionLines, fmt.Errorf("%s: %s", stderr, err)
}

for _, commitLine := range strings.Split(stdout, "\n") {
if len(commitLine) == 0 {
continue
}
descriptionLines = append(descriptionLines, strings.Trim(commitLine, " "))
}
return descriptionLines, nil
}

func run(args ...string) (string, string, error) {
cmd := exec.Command(args[0], args[1:]...)
var stdout bytes.Buffer
Expand Down

0 comments on commit 196dc11

Please sign in to comment.