diff --git a/refactor/rename/mvpkg.go b/refactor/rename/mvpkg.go index c2258d95..4d922f76 100644 --- a/refactor/rename/mvpkg.go +++ b/refactor/rename/mvpkg.go @@ -255,12 +255,8 @@ func (m *mover) move() error { } } - // For each affected package, rewrite all imports of the package to - // use the new import path. + // Update import paths for all imports by affected packages. for ap := range m.affectedPackages { - if ap == m.from { - continue - } info, ok := m.iprog.Imported[ap] if !ok { log.Fatalf("unexpected: package %s is not in import map", ap) diff --git a/refactor/rename/mvpkg_test.go b/refactor/rename/mvpkg_test.go index 7245ce37..b9f29d6b 100644 --- a/refactor/rename/mvpkg_test.go +++ b/refactor/rename/mvpkg_test.go @@ -182,6 +182,31 @@ type T int "/go/src/bar/sub/0.go": `package sub; type T int`, }, }, + + // References into subpackages + { + ctxt: fakeContext(map[string][]string{ + "foo": {`package foo; import "foo/a"; var _ a.T`}, + "foo/a": {`package a; type T int`}, + "foo/b": {`package b; import "foo/a"; var _ a.T`}, + }), + from: "foo", to: "bar", + want: map[string]string{ + "/go/src/bar/0.go": `package bar + +import "bar/a" + +var _ a.T +`, + "/go/src/bar/a/0.go": `package a; type T int`, + "/go/src/bar/b/0.go": `package b + +import "bar/a" + +var _ a.T +`, + }, + }, } for _, test := range tests {