Skip to content

Commit

Permalink
fix: use git root dir for .tools
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 2a2a790 commit 6a983e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .mage/tools.mk
@@ -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
mage := $(mage_generated_path)/local-mage 2> /dev/null

include $(mage_targets_file)

Expand Down
12 changes: 11 additions & 1 deletion mgtool/configuration.go
Expand Up @@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"strings"

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

const (
Expand All @@ -15,7 +17,7 @@ const (
// Path This should only be used to set a custom value.
// Targets should use path() instead which performs
// validation on whether a path is set.
var mgToolPath = GetCWDPath(".tools")
var mgToolPath = GetGitRootPath(".tools")

func GetCWDPath(path string) string {
cwd, err := os.Getwd()
Expand All @@ -25,6 +27,14 @@ func GetCWDPath(path string) string {
return filepath.Join(cwd, path)
}

func GetGitRootPath(path string) string {
root, err := sh.Output("git", "rev-parse", "--show-toplevel")
if err != nil {
panic(err)
}
return filepath.Join(root, path)
}

func GetPath() string {
if mgToolPath == "" {
panic("No tools path set")
Expand Down

0 comments on commit 6a983e9

Please sign in to comment.