Added method to get remote location for dependency
This was previously re-implemented code in numerous places
A central location provides an single place to handle global
overrides
diff --git a/action/config_wizard.go b/action/config_wizard.go
index 1257980..ea627b4 100644
--- a/action/config_wizard.go
+++ b/action/config_wizard.go
@@ -67,12 +67,7 @@
var changes int
for _, dep := range deps {
- var remote string
- if dep.Repository != "" {
- remote = dep.Repository
- } else {
- remote = "https://" + dep.Name
- }
+ remote := dep.Remote()
// First check, ask if the tag should be used instead of the commit id for it.
cur := cache.MemCurrent(remote)
@@ -262,12 +257,7 @@
msg.Debug("Problem detecting cache location: %s", err)
return
}
- var remote string
- if d.Repository != "" {
- remote = d.Repository
- } else {
- remote = "https://" + d.Name
- }
+ remote := d.Remote()
key, err := cache.Key(remote)
if err != nil {
diff --git a/action/get.go b/action/get.go
index 5c34d5e..03c6c67 100644
--- a/action/get.go
+++ b/action/get.go
@@ -234,12 +234,7 @@
}
func getWizard(dep *cfg.Dependency) {
- var remote string
- if dep.Repository != "" {
- remote = dep.Repository
- } else {
- remote = "https://" + dep.Name
- }
+ remote := dep.Remote()
// Lookup dependency info and store in cache.
msg.Info("--> Gathering release information for %s", dep.Name)
diff --git a/cfg/config.go b/cfg/config.go
index 115c76d..60d385b 100644
--- a/cfg/config.go
+++ b/cfg/config.go
@@ -460,6 +460,16 @@
return newDep, nil
}
+// Remote returns the remote location to fetch source from. This location is
+// the central place where overrides happen from.
+func (d *Dependency) Remote() string {
+ if d.Repository != "" {
+ return d.Repository
+ }
+
+ return "https://" + d.Name
+}
+
// GetRepo retrieves a Masterminds/vcs repo object configured for the root
// of the package being retrieved.
func (d *Dependency) GetRepo(dest string) (vcs.Repo, error) {
diff --git a/repo/installer.go b/repo/installer.go
index 13d3fb0..c13bfe0 100644
--- a/repo/installer.go
+++ b/repo/installer.go
@@ -358,12 +358,7 @@
for {
select {
case dep := <-ch:
- var loc string
- if dep.Repository != "" {
- loc = dep.Repository
- } else {
- loc = "https://" + dep.Name
- }
+ loc := dep.Remote()
key, err := cache.Key(loc)
if err != nil {
msg.Die(err.Error())
diff --git a/repo/vcs.go b/repo/vcs.go
index 3f5f80d..e77e870 100644
--- a/repo/vcs.go
+++ b/repo/vcs.go
@@ -339,12 +339,7 @@
branch := findCurrentBranch(repo)
if branch != "" {
// we know the default branch so we can store it in the cache
- var loc string
- if dep.Repository != "" {
- loc = dep.Repository
- } else {
- loc = "https://" + dep.Name
- }
+ loc := dep.Remote()
key, err := cp.Key(loc)
if err == nil {
msg.Debug("Saving default branch for %s", repo.Remote())
@@ -370,12 +365,7 @@
// If opting in to caching attempt to put it in the cache folder
if cache {
// Check if the cache has a viable version and try to use that.
- var loc string
- if dep.Repository != "" {
- loc = dep.Repository
- } else {
- loc = "https://" + dep.Name
- }
+ loc := dep.Remote()
key, err := cp.Key(loc)
if err == nil {
location, err := cp.Location()
@@ -398,12 +388,7 @@
branch := findCurrentBranch(repo)
if branch != "" {
// we know the default branch so we can store it in the cache
- var loc string
- if dep.Repository != "" {
- loc = dep.Repository
- } else {
- loc = "https://" + dep.Name
- }
+ loc := dep.Remote()
key, err := cp.Key(loc)
if err == nil {
msg.Debug("Saving default branch for %s", repo.Remote())
@@ -449,12 +434,7 @@
if cache {
if branch := findCurrentBranch(repo); branch != "" {
// we know the default branch so we can store it in the cache
- var loc string
- if dep.Repository != "" {
- loc = dep.Repository
- } else {
- loc = "https://" + dep.Name
- }
+ loc := dep.Remote()
key, err := cp.Key(loc)
if err == nil {
msg.Debug("Saving default branch for %s", repo.Remote())