Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use git root dir for .tools #37

Merged
merged 1 commit into from Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
viktorvoltaire marked this conversation as resolved.
Show resolved Hide resolved

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