aboutsummaryrefslogtreecommitdiff
path: root/internal/rtree/repo.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/repo.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/repo.go')
-rw-r--r--internal/rtree/repo.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/rtree/repo.go b/internal/rtree/repo.go
index 4af51c1..8529bfa 100644
--- a/internal/rtree/repo.go
+++ b/internal/rtree/repo.go
@@ -40,8 +40,8 @@ type Repo struct {
//Remote describes a remote that is configured in a Repo.
type Remote struct {
- Name string `yaml:"name"`
- URL string `yaml:"url"`
+ Name string `yaml:"name"`
+ URL RemoteURL `yaml:"url"`
}
//AbsolutePath returns the absolute CheckoutPath of this repo.
@@ -73,7 +73,7 @@ func NewRepoFromAbsolutePath(path string) (repo Repo, err error) {
}
repo.Remotes = append(repo.Remotes, Remote{
Name: match[1],
- URL: match[2],
+ URL: ParseRemoteURL(match[2]),
})
}
return
@@ -81,8 +81,8 @@ func NewRepoFromAbsolutePath(path string) (repo Repo, err error) {
//NewRepoFromRemoteURL initializes a Repo instance for checking out a remote
//for the first time. The checkout does not happen until Checkout() is called.
-func NewRepoFromRemoteURL(remoteURL string) (Repo, error) {
- checkoutPath, err := CheckoutPathForRemoteURL(ExpandRemoteURL(remoteURL))
+func NewRepoFromRemoteURL(remoteURL RemoteURL) (Repo, error) {
+ checkoutPath, err := remoteURL.CheckoutPath()
return Repo{
CheckoutPath: checkoutPath,
Remotes: []Remote{
@@ -130,7 +130,7 @@ func ForeachPhysicalRepo(action func(repo Repo) error) error {
//working copy will only be initialized if there is an "origin" remote.
func (r Repo) Checkout() error {
//check if we have an "origin" remote to clone from
- var originURL string
+ var originURL RemoteURL
for _, remote := range r.Remotes {
if remote.Name == "origin" {
originURL = remote.URL
@@ -148,7 +148,7 @@ func (r Repo) Checkout() error {
cli.Interface.ShowWarning(`will not checkout anything since there is no remote named "origin"`)
} else {
err := cli.Interface.Run(cli.Command{
- Program: []string{"git", "clone", originURL, r.AbsolutePath()},
+ Program: []string{"git", "clone", originURL.CompactURL(), r.AbsolutePath()},
})
if err != nil {
return err
@@ -159,7 +159,7 @@ func (r Repo) Checkout() error {
for _, remote := range r.Remotes {
if remote.Name != "origin" {
err := cli.Interface.Run(cli.Command{
- Program: []string{"git", "remote", "add", remote.Name, remote.URL},
+ Program: []string{"git", "remote", "add", remote.Name, remote.URL.CompactURL()},
WorkDir: r.AbsolutePath(),
})
if err != nil {