From 6a983e9d32396fd1c011fe53fd8a74c318f2bf88 Mon Sep 17 00:00:00 2001 From: Viktor Voltaire Date: Thu, 23 Dec 2021 11:11:40 +0100 Subject: [PATCH] fix: use git root dir for .tools --- .mage/tools.mk | 2 +- mgtool/configuration.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.mage/tools.mk b/.mage/tools.mk index 96340178..97ed4db3 100644 --- a/.mage/tools.mk +++ b/.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) diff --git a/mgtool/configuration.go b/mgtool/configuration.go index 310382e4..fbcec001 100644 --- a/mgtool/configuration.go +++ b/mgtool/configuration.go @@ -5,6 +5,8 @@ import ( "os" "path/filepath" "strings" + + "github.com/magefile/mage/sh" ) const ( @@ -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() @@ -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")