Skip to content

Commit 7ccd1c8

Browse files
committed
gp git-commit-message-helper to use git interpret-trailers
1 parent ec1be43 commit 7ccd1c8

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

components/gitpod-cli/cmd/git-commit-message-helper.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"os"
11-
"strings"
11+
"os/exec"
1212
"time"
1313

1414
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
@@ -32,25 +32,22 @@ var gitCommitMessageHelper = &cobra.Command{
3232

3333
wsInfo, err := gitpod.GetWSInfo(ctx)
3434
if err != nil {
35-
return err
35+
log.WithError(err).Fatal("error getting workspace info")
36+
return nil // don't block commit
3637
}
3738

38-
content, err := os.ReadFile(gitCommitMessageHelperOpts.CommitMessageFile)
39-
if err != nil {
40-
log.WithError(err).Fatal("error reading commit message file")
41-
return err
42-
}
39+
trailerCmd := exec.Command("git", "interpret-trailers",
40+
"--if-exists", "addIfDifferent",
41+
"--trailer", fmt.Sprintf("Tool: gitpod/%s", wsInfo.GitpodApi.Host),
42+
gitCommitMessageHelperOpts.CommitMessageFile)
4343

44-
toolAttribution := fmt.Sprintf("Tool: gitpod/%s", wsInfo.GitpodApi.Host)
45-
46-
msg := string(content)
47-
if strings.Contains(msg, toolAttribution) {
48-
return nil
44+
output, err := trailerCmd.Output()
45+
if err != nil {
46+
log.WithError(err).Fatal("error adding trailer")
47+
return nil // don't block commit
4948
}
5049

51-
newMsg := fmt.Sprintf("%s\n\n%s", msg, toolAttribution)
52-
53-
err = os.WriteFile(gitCommitMessageHelperOpts.CommitMessageFile, []byte(newMsg), 0644)
50+
err = os.WriteFile(gitCommitMessageHelperOpts.CommitMessageFile, output, 0644)
5451
if err != nil {
5552
log.WithError(err).Fatal("error writing commit message file")
5653
return err

0 commit comments

Comments
 (0)