Skip to content

Commit

Permalink
Merge pull request #165 from k2tzumi/refer-to-next-version-with-command
Browse files Browse the repository at this point in the history
Refer to the next version with command
  • Loading branch information
Songmu authored Dec 31, 2023
2 parents d7ae971 + 417a3f7 commit 85c77ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package tagpr

import (
"bytes"
"fmt"
"io"
"log"
"os"
"os/exec"
"strings"
)
Expand All @@ -20,14 +22,20 @@ func (c *commander) getGitPath() string {
return c.gitPath
}

func (c *commander) Cmd(prog string, args ...string) (string, string, error) {
func (c *commander) Cmd(prog string, args []string, env map[string]string) (string, string, error) {
log.Println(prog, args)

var (
outBuf bytes.Buffer
errBuf bytes.Buffer
)
cmd := exec.Command(prog, args...)
if env != nil {
cmd.Env = os.Environ()
for k, v := range env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
}
}
cmd.Stdout = io.MultiWriter(&outBuf, c.outStream)
cmd.Stderr = io.MultiWriter(&errBuf, c.errStream)
if c.dir != "" {
Expand All @@ -38,5 +46,5 @@ func (c *commander) Cmd(prog string, args ...string) (string, string, error) {
}

func (c *commander) Git(args ...string) (string, string, error) {
return c.Cmd(c.getGitPath(), args...)
return c.Cmd(c.getGitPath(), args, nil)
}
5 changes: 4 additions & 1 deletion tagpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ OUT:
progArgs = []string{"-c", prog}
prog = "sh"
}
tp.c.Cmd(prog, progArgs...)
tp.c.Cmd(prog, progArgs, map[string]string{
"TAGPR_CURRENT_VERSION": currVer.Tag(),
"TAGPR_NEXT_VERSION": nextVer.Tag(),
})
}

if len(vfiles) > 0 && vfiles[0] != "" {
Expand Down

0 comments on commit 85c77ac

Please sign in to comment.