Skip to content

Commit

Permalink
fix(mgtool): use exec.command to solve unwanted logging from global
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Voltaire authored and viktorvoltaire committed Dec 23, 2021
1 parent 6a983e9 commit 9c42c21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .mage/tools.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mage_folder := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
mage_generated_path := $(mage_folder)/gen
mage_targets_file := $(mage_generated_path)/targets.mk
mage := $(mage_generated_path)/local-mage 2> /dev/null
mage := $(mage_generated_path)/local-mage

include $(mage_targets_file)

Expand Down
18 changes: 13 additions & 5 deletions mgtool/configuration.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package mgtool

import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/magefile/mage/sh"
)

const (
Expand All @@ -28,11 +28,19 @@ func GetCWDPath(path string) string {
}

func GetGitRootPath(path string) string {
root, err := sh.Output("git", "rev-parse", "--show-toplevel")
if err != nil {
// We use exec.command here because this command runs in a global,
// which is set up before mage has configured logging resulting in unwanted log prints
output := &bytes.Buffer{}
c := exec.Command("git", []string{"rev-parse", "--show-toplevel"}...)
c.Env = os.Environ()
c.Stderr = os.Stderr
c.Stdout = output
c.Stdin = os.Stdin

if err := c.Run(); err != nil {
panic(err)
}
return filepath.Join(root, path)
return filepath.Join(output.String(), path)
}

func GetPath() string {
Expand Down

0 comments on commit 9c42c21

Please sign in to comment.