Merge pull request #535 from Fugiman/resolve_vendor_dir_symlinks

Resolve vendor directory symlinks
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cd27a18..356b864 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+# Unreleased
+
+## Added
+- #533: Log VCS output with debug (`--debug` switch) when there was a VCS error (thanks @atombender)
+
+## Changed
+- #521: Sort subpackages for glide.yaml and glide.lock to avoid spurious diffs
+- #487: Skip lookup of subpackage location when parent repo is already known.
+  This skips unnecessary network requests (thanks @hori-ryota)
+
 # Release 0.11.1 (2016-07-21)
 
 ## Fixed
diff --git a/msg/msg.go b/msg/msg.go
index 34213fd..8b0f077 100644
--- a/msg/msg.go
+++ b/msg/msg.go
@@ -7,6 +7,8 @@
 	"os"
 	"strings"
 	"sync"
+
+	"github.com/Masterminds/vcs"
 )
 
 // Messenger provides the underlying implementation that displays output to
@@ -176,7 +178,6 @@
 	// locked to avoid displaying one message in the middle of another one.
 	m.Lock()
 	defer m.Unlock()
-
 	// Get rid of the annoying fact that messages need \n at the end, but do
 	// it in a backward compatible way.
 	if !strings.HasSuffix(msg, "\n") {
@@ -188,6 +189,21 @@
 	} else {
 		fmt.Fprintf(m.Stderr, msg, args...)
 	}
+
+	// If an arg is a vcs error print the output if in debug mode. This is
+	// capured here rather than calling Debug because concurrent operations
+	// could cause other messages to appear between the initial error and the
+	// debug output by unlocking and calling Debug.
+	if len(args) != 0 && !m.Quiet && m.IsDebugging {
+		if err, ok := args[len(args)-1].(error); ok {
+			switch t := err.(type) {
+			case *vcs.LocalError:
+				fmt.Fprintf(m.Stderr, "[DEBUG]\tOutput was: %s", strings.TrimSpace(t.Out()))
+			case *vcs.RemoteError:
+				fmt.Fprintf(m.Stderr, "[DEBUG]\tOutput was: %s", strings.TrimSpace(t.Out()))
+			}
+		}
+	}
 }
 
 // Msg prints a message with optional arguments, that can be printed, of
diff --git a/util/normalizename_test.go b/util/normalizename_test.go
index c6f4d02..d5a454b 100644
--- a/util/normalizename_test.go
+++ b/util/normalizename_test.go
@@ -31,11 +31,18 @@
 			extra: "",
 		},
 		{
+			input: "otherurl/example/root/sub",
+			root:  "otherurl/example/root",
+			extra: "sub",
+		},
+		{
 			input: "net",
 			root:  "net",
 			extra: "",
 		},
 	}
+	remotePackageCache["otherurl/example/root"] = "otherurl/example/root"
+
 	for _, test := range packages {
 		root, extra := NormalizeName(test.input)
 		if root != test.root {
diff --git a/util/util.go b/util/util.go
index a5b346f..f0854d2 100644
--- a/util/util.go
+++ b/util/util.go
@@ -110,7 +110,7 @@
 
 func checkRemotePackageCache(pkg string) (string, bool) {
 	for k, v := range remotePackageCache {
-		if pkg == k {
+		if pkg == k || strings.HasPrefix(pkg, k + "/") {
 			return v, true
 		}
 	}
@@ -290,7 +290,7 @@
 		out, err := exec.Command(goExecutable, "env", "GOROOT").Output()
 		if goRoot = strings.TrimSpace(string(out)); len(goRoot) == 0 || err != nil {
 			return nil, fmt.Errorf("Please set the $GOROOT environment " +
-				"variable to use this command\n")
+			"variable to use this command\n")
 		}
 		buildContext.GOROOT = goRoot
 	}