aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Matloob <matloob@google.com>2015-02-10 13:18:58 -0800
committerAlan Donovan <adonovan@google.com>2015-02-11 15:58:22 +0000
commitd29758bc2ee3aad47371bd6918424054ea9c1029 (patch)
tree4dc07893f4792bcd7c1bead524500959e8c1d802
parent88df7a741d4e0719f78564b5102e94665c3d742c (diff)
downloadtools-d29758bc2ee3aad47371bd6918424054ea9c1029.tar.gz
cmd/gomvpkg: fix import rewrites for top-level moved package
The top-level moved package was skipped when doing import rewrites. Don't skip that package. Fixes #9811 Change-Id: I1c524ed44606586b5231e5adb6168079aa0e0228 Reviewed-on: https://go-review.googlesource.com/4470 Reviewed-by: Alan Donovan <adonovan@google.com>
-rw-r--r--refactor/rename/mvpkg.go6
-rw-r--r--refactor/rename/mvpkg_test.go25
2 files changed, 26 insertions, 5 deletions
diff --git a/refactor/rename/mvpkg.go b/refactor/rename/mvpkg.go
index c2258d9..4d922f7 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 7245ce3..b9f29d6 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 {