-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow relative paths in GOHACK env var (#45)
Prior to this change, we were using `filepath.Join()` to derive a replacement for the module dir. But this is not enough to support relative directories, as `Join()` cleans the resulting path, removing any `"./"` prefix (which is needed by the replace drective when using a local directory). This change adds the `"./"` prefix if the user specified it in the GOHACK env var. Note that relative parent directory `".."` is not cleaned by `filepath.Join()`, so we do not need to cater to this case, and an added test proves that this works. fixes #44
- Loading branch information
1 parent
dfc57bb
commit 01736fb
Showing
3 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cd repo | ||
go get rsc.io/[email protected] | ||
env GOHACK=../gohack/ | ||
gohack get rsc.io/quote | ||
stdout '^rsc.io/quote => \.\./gohack/rsc.io/quote$' | ||
! stderr .+ | ||
|
||
# Check that the replace statement is there. | ||
grep -count=1 '^replace rsc\.io/quote => \.\./gohack/rsc.io/quote$' go.mod | ||
|
||
# Check that the source files have been copied. | ||
exists ../gohack/rsc.io/quote/quote.go | ||
|
||
# Check that we can compile the command OK. | ||
go install example.com/repo | ||
|
||
-- repo/main.go -- | ||
package main | ||
import ( | ||
"fmt" | ||
"rsc.io/quote" | ||
) | ||
|
||
func main() { | ||
fmt.Println(quote.Glass()) | ||
} | ||
|
||
-- repo/go.mod -- | ||
module example.com/repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cd repo | ||
go get rsc.io/[email protected] | ||
env GOHACK=. | ||
gohack get rsc.io/quote | ||
stdout '^rsc.io/quote => \./rsc.io/quote$' | ||
! stderr .+ | ||
|
||
# Check that the replace statement is there. | ||
grep -count=1 '^replace rsc\.io/quote => \./rsc.io/quote$' go.mod | ||
|
||
# Check that the source files have been copied. | ||
exists ./rsc.io/quote/quote.go | ||
|
||
# It should not be a git repository. | ||
! exists ./rsc.io/quote/.git | ||
|
||
# Check that we can compile the command OK. | ||
go install example.com/repo | ||
|
||
-- repo/main.go -- | ||
package main | ||
import ( | ||
"fmt" | ||
"rsc.io/quote" | ||
) | ||
|
||
func main() { | ||
fmt.Println(quote.Glass()) | ||
} | ||
|
||
-- repo/go.mod -- | ||
module example.com/repo |