diff --git a/cmd/get_imports.go b/cmd/get_imports.go index 27b1eec6..662cd303 100644 --- a/cmd/get_imports.go +++ b/cmd/get_imports.go @@ -258,6 +258,29 @@ func VcsUpdate(dep *Dependency, vend string, force bool) error { } else if err != nil { return err } else { + // Check if the current version is a tag or commit id. If it is + // and that version is already checked out we can skip updating + // which is faster than going out to the Internet to perform + // an update. + if dep.Reference != "" { + version, err := repo.Version() + if err != nil { + return err + } + ib, err := isBranch(dep.Reference, repo) + if err != nil { + return err + } + + // If the current version equals the ref and it's not a + // branch it's a tag or commit id so we can skip + // performing an update. + if version == dep.Reference && !ib { + Info("%s is already set to version %s. Skipping update.", dep.Name, dep.Reference) + return nil + } + } + if err := repo.Update(); err != nil { Warn("Download failed.\n") return err diff --git a/cmd/semver.go b/cmd/semver.go index c922a17e..3853ff2b 100644 --- a/cmd/semver.go +++ b/cmd/semver.go @@ -58,6 +58,19 @@ func getAllVcsRefs(repo vcs.Repo) ([]string, error) { return refs, nil } +func isBranch(branch string, repo vcs.Repo) (bool, error) { + branches, err := repo.Branches() + if err != nil { + return false, err + } + for _, b := range branches { + if b == branch { + return true, nil + } + } + return false, nil +} + // From the refs find all of the ones fitting the SemVer pattern. // func findSemVerRefs(refs []string) ([]string, error) { //