]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: skip deleted entries in UpdateWorkFile
authorBryan C. Mills <bcmills@google.com>
Tue, 1 Feb 2022 21:35:02 +0000 (16:35 -0500)
committerBryan Mills <bcmills@google.com>
Thu, 3 Feb 2022 05:53:37 +0000 (05:53 +0000)
Fixes #50958

Change-Id: I25b4f34bea7705525217296471ce97e6a2ab99f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/382245
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/modload/init.go
src/cmd/go/testdata/script/work_use_issue50958.txt [new file with mode: 0644]

index cdcfbeb8dedfb47f23a507abf73ac438e2e31260..23f4efd02ad6f9a78772e3cb8f05f1ba6ec03200 100644 (file)
@@ -610,6 +610,9 @@ func UpdateWorkFile(wf *modfile.WorkFile) {
        missingModulePaths := map[string]string{} // module directory listed in file -> abspath modroot
 
        for _, d := range wf.Use {
+               if d.Path == "" {
+                       continue // d is marked for deletion.
+               }
                modRoot := d.Path
                if d.ModulePath == "" {
                        missingModulePaths[d.Path] = modRoot
diff --git a/src/cmd/go/testdata/script/work_use_issue50958.txt b/src/cmd/go/testdata/script/work_use_issue50958.txt
new file mode 100644 (file)
index 0000000..7a25531
--- /dev/null
@@ -0,0 +1,17 @@
+go work use -r .
+cmp go.work go.work.want
+
+-- go.mod --
+module example
+go 1.18
+-- go.work --
+go 1.18
+
+use sub
+-- go.work.want --
+go 1.18
+
+use .
+-- sub/README.txt --
+This directory no longer contains a go.mod file.
+