accept replacements with branches of github forks (#51)

* accept replacements with branches of github forks

Closes #50

* remove `!filepath.IsAbs(repl)` when checking path of replacement

If the replacement path starts with a `.`, then the path is definitely not absolute.
This commit is contained in:
Mohammed Al Sahaf 2021-02-27 01:49:50 +03:00 committed by GitHub
parent 83655481bf
commit 83bc5a7c58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View file

@ -76,7 +76,7 @@ func runBuild(ctx context.Context, args []string) error {
})
if repl != "" {
// adjust relative replacements in current working directory since our temporary module is in a different directory
if !filepath.IsAbs(repl) {
if strings.HasPrefix(repl, ".") {
repl, err = filepath.Abs(repl)
if err != nil {
log.Fatalf("[FATAL] %v", err)
@ -288,9 +288,13 @@ func trapSignals(ctx context.Context, cancel context.CancelFunc) {
func splitWith(arg string) (module, version, replace string, err error) {
const versionSplit, replaceSplit = "@", "="
parts := strings.SplitN(arg, versionSplit, 2)
module = parts[0]
modules := strings.SplitN(arg, replaceSplit, 2)
if len(modules) > 1 {
replace = modules[1]
}
parts := strings.SplitN(modules[0], versionSplit, 2)
module = parts[0]
if len(parts) == 1 {
parts := strings.SplitN(module, replaceSplit, 2)
if len(parts) > 1 {

View file

@ -33,6 +33,17 @@ func TestSplitWith(t *testing.T) {
expectModule: "module",
expectReplace: "replace",
},
{
input: "module=replace@version",
expectModule: "module",
expectReplace: "replace@version",
},
{
input: "module@version=replace@version",
expectModule: "module",
expectVersion: "version",
expectReplace: "replace@version",
},
{
input: "=replace",
expectErr: true,