From 68da2e5a227e23043455ceb3b26c5abaae168372 Mon Sep 17 00:00:00 2001 From: Zou Guangxian Date: Sun, 2 Aug 2020 14:33:27 +0800 Subject: [PATCH] support replace directive with local path in go.mod --- main.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 07a4932..a7036e9 100644 --- a/main.go +++ b/main.go @@ -75,7 +75,7 @@ func main() { if line[0] == 35 { s := strings.Split(line, " ") - if (len(s) != 6 && len(s) != 3) || s[1] == "explicit" { + if (len(s) != 5 && len(s) != 6 && len(s) != 3) || s[1] == "explicit" { continue } @@ -90,9 +90,16 @@ func main() { } // Handle "replace" in module file if any if len(s) > 3 && s[3] == "=>" { - mod.SourcePath = s[4] - mod.SourceVersion = s[5] - mod.Dir = pkgModPath(mod.SourcePath, mod.SourceVersion) + switch(len(s)) { + case 5: + mod.SourcePath = s[4] + mod.SourceVersion = s[2] + mod.Dir = filepath.Join(cwd, s[4]) + case 6: + mod.SourcePath = s[4] + mod.SourceVersion = s[5] + mod.Dir = pkgModPath(mod.SourcePath, mod.SourceVersion) + } } else { mod.Dir = pkgModPath(mod.ImportPath, mod.Version) }