Skip to content

Commit

Permalink
Allow variable expansion
Browse files Browse the repository at this point in the history
Allow the GETPATH to contain and then expand environmental variables.
This allows a user to set `$GOPATH/src` as their GETPATH.
  • Loading branch information
arbourd committed Apr 3, 2024
1 parent 5dab029 commit 8ffa2ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func Path() (string, error) {

p = filepath.Join(dir, p[1:])
}
p = os.ExpandEnv(p)

if !filepath.IsAbs(p) {
return "", fmt.Errorf("GETPATH is not an absolute path: \"%s\"", p)
Expand Down
14 changes: 14 additions & 0 deletions get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func TestPath(t *testing.T) {
t.Fatalf("unable to setup test fixture: %s", err)
}

homeVar := "HOME"
if runtime.GOOS == "windows" {
homeVar = "USERPROFILE"
}
getpathWithVar := filepath.FromSlash(fmt.Sprintf("$%s/src", homeVar))

cases := map[string]struct {
gitConfigGetpath string
envGetpath string
Expand All @@ -39,10 +45,18 @@ func TestPath(t *testing.T) {
gitConfigGetpath: configGetpath,
expectedPath: configGetpath,
},
"git config getpath with variable": {
gitConfigGetpath: getpathWithVar,
expectedPath: defaultGetpath,
},
"env var getpath": {
envGetpath: envGetpath,
expectedPath: envGetpath,
},
"env var getpath with variable": {
gitConfigGetpath: getpathWithVar,
expectedPath: defaultGetpath,
},
"git config getpath overrides env var getpath": {
gitConfigGetpath: configGetpath,
envGetpath: envGetpath,
Expand Down

0 comments on commit 8ffa2ba

Please sign in to comment.