summaryrefslogtreecommitdiff
path: root/internal/rtree/index.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2020-03-30 20:40:25 +0200
committerStefan Majewsky <majewsky@gmx.net>2020-03-30 20:40:25 +0200
commit0361bc3af31a06ec64adeab0ca2d1534a1c35ed0 (patch)
treeca25c6aa4f7052617664b456096e0d42acd5eef2 /internal/rtree/index.go
parentfdffeee7dc2a4869c85f0c298e3d12924846724b (diff)
downloadgofu-0361bc3af31a06ec64adeab0ca2d1534a1c35ed0.tar.gz
rtree: always store compact remote URLs in the index file
Includes a refactor to use a type RemoteURL with a more natural API.
Diffstat (limited to 'internal/rtree/index.go')
-rw-r--r--internal/rtree/index.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/internal/rtree/index.go b/internal/rtree/index.go
index 4ca7a41..64c8c74 100644
--- a/internal/rtree/index.go
+++ b/internal/rtree/index.go
@@ -146,10 +146,10 @@ func (i *Index) Rebuild() error {
var remoteURLs []string
for _, remote := range repo.Remotes {
if remote.Name == "origin" {
- remoteURLs = []string{remote.URL}
+ remoteURLs = []string{remote.URL.CompactURL()}
break
}
- remoteURLs = append(remoteURLs, remote.URL)
+ remoteURLs = append(remoteURLs, remote.URL.CompactURL())
}
var selection string
@@ -212,12 +212,12 @@ func (i *Index) Rebuild() error {
//FindRepo locates the repo with the given remote if it exists on disk or (if
//allowClone is set) clones it and adds it to the index. This is the meat of
//`rtree get`, and is also used by `rtree drop`.
-func (i *Index) FindRepo(remoteURL string, allowClone bool) (*Repo, error) {
+func (i *Index) FindRepo(rawRemoteURL string, allowClone bool) (*Repo, error) {
//make sure that stdout is not used for prompts
cli.Interface.StdoutProtected = true
- expandedRemoteURL := ExpandRemoteURL(remoteURL)
- basename := path.Base(expandedRemoteURL)
+ remoteURL := ParseRemoteURL(rawRemoteURL)
+ basename := path.Base(remoteURL.CanonicalURL())
//is this remote already checked out directly? also look for repos with the
//same basename that could be forks
@@ -225,11 +225,10 @@ func (i *Index) FindRepo(remoteURL string, allowClone bool) (*Repo, error) {
for _, repo := range i.Repos {
isCandidate := false
for _, remote := range repo.Remotes {
- otherExpandedRemoteURL := ExpandRemoteURL(remote.URL)
- if expandedRemoteURL == otherExpandedRemoteURL {
+ if remoteURL == remote.URL {
return repo, nil
}
- if basename == path.Base(otherExpandedRemoteURL) {
+ if basename == path.Base(remote.URL.CanonicalURL()) {
isCandidate = true
}
}
@@ -310,7 +309,7 @@ func (i *Index) FindRepo(remoteURL string, allowClone bool) (*Repo, error) {
//report the existing remotes, and ask for the name of the new remote
prompt := "Existing remotes:\n"
for _, remote := range target.Remotes {
- prompt += fmt.Sprintf("\t(%s) %s\n", remote.Name, remote.URL)
+ prompt += fmt.Sprintf("\t(%s) %s\n", remote.Name, remote.URL.CompactURL())
}
prompt += fmt.Sprintf("Enter remote name for %s:", remoteURL)
remoteName, err := cli.Interface.ReadLine(prompt)
@@ -319,7 +318,7 @@ func (i *Index) FindRepo(remoteURL string, allowClone bool) (*Repo, error) {
}
err = cli.Interface.Run(cli.Command{
- Program: []string{"git", "remote", "add", remoteName, remoteURL},
+ Program: []string{"git", "remote", "add", remoteName, remoteURL.CompactURL()},
WorkDir: target.AbsolutePath(),
})
if err != nil {
@@ -363,7 +362,7 @@ func (i *Index) ImportRepo(dirPath string) error {
choices := make([]cli.Choice, len(repo.Remotes))
var checkoutPath string
for idx, remote := range repo.Remotes {
- thisPath, err := CheckoutPathForRemoteURL(ExpandRemoteURL(remote.URL))
+ thisPath, err := remote.URL.CheckoutPath()
if err != nil {
return err
}