From 72c757b7a44dc5d19d821f7c2fa36bb082e4f2e3 Mon Sep 17 00:00:00 2001 From: Sandro Jäckel Date: Mon, 17 Apr 2023 13:28:47 +0200 Subject: Save rtree with go 1.20 --- internal/rtree/repo.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'internal/rtree/repo.go') diff --git a/internal/rtree/repo.go b/internal/rtree/repo.go index f710666..5cdd39f 100644 --- a/internal/rtree/repo.go +++ b/internal/rtree/repo.go @@ -28,7 +28,7 @@ import ( "github.com/majewsky/gofu/internal/cli" ) -//Repo describes the entry for a repository in the index file. +// Repo describes the entry for a repository in the index file. type Repo struct { //CheckoutPath shall be relative to the RootPath. CheckoutPath string `yaml:"path"` @@ -38,24 +38,24 @@ type Repo struct { Remotes []Remote `yaml:"remotes"` } -//Remote describes a remote that is configured in a Repo. +// Remote describes a remote that is configured in a Repo. type Remote struct { Name string `yaml:"name"` URL RemoteURL `yaml:"url"` } -//AbsolutePath returns the absolute CheckoutPath of this repo. +// AbsolutePath returns the absolute CheckoutPath of this repo. func (r Repo) AbsolutePath() string { return filepath.Join(RootPath, r.CheckoutPath) } -//GitDirPath returns the path of the .git directory of this repo. +// GitDirPath returns the path of the .git directory of this repo. func (r Repo) GitDirPath() string { return filepath.Join(r.AbsolutePath(), ".git") } -//NewRepoFromAbsolutePath initializes a Repo instance by scanning the existing -//checkout at the given path. +// NewRepoFromAbsolutePath initializes a Repo instance by scanning the existing +// checkout at the given path. func NewRepoFromAbsolutePath(path string) (repo Repo, err error) { repo.CheckoutPath, err = filepath.Rel(RootPath, path) if err != nil { @@ -84,8 +84,8 @@ func NewRepoFromAbsolutePath(path string) (repo Repo, err error) { return } -//NewRepoFromRemoteURL initializes a Repo instance for checking out a remote -//for the first time. The checkout does not happen until Checkout() is called. +// 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 RemoteURL) (Repo, error) { checkoutPath, err := remoteURL.CheckoutPath() return Repo{ @@ -101,9 +101,9 @@ func NewRepoFromRemoteURL(remoteURL RemoteURL) (Repo, error) { var remoteConfigRx = regexp.MustCompile(`remote\.([^=]+)\.url=(.+)`) -//ForeachPhysicalRepo walks over the repository tree, executing the action -//function once for every repo encountered (but *not* for repos contained -//within other repos, e.g. submodules). +// ForeachPhysicalRepo walks over the repository tree, executing the action +// function once for every repo encountered (but *not* for repos contained +// within other repos, e.g. submodules). func ForeachPhysicalRepo(action func(repo Repo) error) error { return filepath.Walk(RootPath, func(path string, info os.FileInfo, err error) error { if err != nil { @@ -131,8 +131,8 @@ func ForeachPhysicalRepo(action func(repo Repo) error) error { }) } -//Checkout creates the repo in the given path with the given remotes. The -//working copy will only be initialized if there is an "origin" remote. +// Checkout creates the repo in the given path with the given remotes. The +// 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 RemoteURL @@ -183,8 +183,8 @@ func (r Repo) Checkout() error { return nil } -//Exec implements the meat of the `rtree exec` command. It returns -//true iff the command exited successfully. +// Exec implements the meat of the `rtree exec` command. It returns +// true iff the command exited successfully. func (r Repo) Exec(cmdline ...string) error { cli.Interface.ShowProgress(r.AbsolutePath()) return cli.Interface.Run(cli.Command{ @@ -193,9 +193,9 @@ func (r Repo) Exec(cmdline ...string) error { }) } -//Move sets the CheckoutPath to the given value and moves the existing repo -//from the old to the new checkoutPath. If makeSymlink is given, a symlink will -//be created from the old to the new location. +// Move sets the CheckoutPath to the given value and moves the existing repo +// from the old to the new checkoutPath. If makeSymlink is given, a symlink will +// be created from the old to the new location. func (r *Repo) Move(checkoutPath string, makeSymlink bool) error { sourcePath := filepath.Join(RootPath, r.CheckoutPath) targetPath := filepath.Join(RootPath, checkoutPath) @@ -229,8 +229,8 @@ func (r *Repo) Move(checkoutPath string, makeSymlink bool) error { return nil } -//ReformatRemoteURLs rewrites the remote URLs in this repo's .git/config into -//their compact forms. +// ReformatRemoteURLs rewrites the remote URLs in this repo's .git/config into +// their compact forms. func (r Repo) ReformatRemoteURLs() error { for _, remote := range r.Remotes { err := cli.Interface.Run(cli.Command{ -- cgit v1.3.1 From d0059fcb87312d296a31d6965d6db84e499fe020 Mon Sep 17 00:00:00 2001 From: Sandro Jäckel Date: Mon, 17 Apr 2023 14:43:15 +0200 Subject: Only use compact URL in UI, not in written files many tools like eg some vscode extensions can parse the git remotes but do not respect git aliases and fail to understand shorthands like gh:majewsky/gofu --- internal/rtree/get_test.go | 8 ++++---- internal/rtree/remote.go | 2 +- internal/rtree/repo.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'internal/rtree/repo.go') diff --git a/internal/rtree/get_test.go b/internal/rtree/get_test.go index a438234..789e903 100644 --- a/internal/rtree/get_test.go +++ b/internal/rtree/get_test.go @@ -35,7 +35,7 @@ var testIndexWithTwoRepos = Index{ { CheckoutPath: "github.com/git/git", Remotes: []Remote{ - {Name: "origin", URL: "gh:git/git"}, + {Name: "origin", URL: "https://github.com/git/git"}, }, }, }, @@ -65,14 +65,14 @@ func TestGetNewRepo(t *testing.T) { Args: []string{"get", remoteURL}, Index: testIndexWithTwoRepos, ExpectOutput: target + "\n", - ExpectExecution: Recorded("git clone gh:another/repo " + target), + ExpectExecution: Recorded("git clone https://github.com/another/repo " + target), ExpectIndex: &Index{ Repos: []*Repo{ { CheckoutPath: "github.com/another/repo", Remotes: []Remote{ //regardless of the remote URL used, we expect the contracted form to be used - {Name: "origin", URL: "gh:another/repo"}, + {Name: "origin", URL: "https://github.com/another/repo"}, }, }, testIndexWithTwoRepos.Repos[0], @@ -106,7 +106,7 @@ func TestGetNewForkAsRemote(t *testing.T) { { CheckoutPath: "github.com/git/git", Remotes: []Remote{ - {Name: "origin", URL: "gh:git/git"}, + {Name: "origin", URL: "https://github.com/git/git"}, {Name: "myfork", URL: "https://example.com/git"}, }, }, diff --git a/internal/rtree/remote.go b/internal/rtree/remote.go index 2973b8c..36e12dd 100644 --- a/internal/rtree/remote.go +++ b/internal/rtree/remote.go @@ -104,7 +104,7 @@ func (u RemoteURL) CheckoutPath() (string, error) { // MarshalYAML implements the yaml.Marshaler interface. func (u RemoteURL) MarshalYAML() (interface{}, error) { //store URLs in the index in the compact format - return u.CompactURL(), nil + return u.CanonicalURL(), nil } // UnmarshalYAML implements the yaml.Unmarshaler interface. diff --git a/internal/rtree/repo.go b/internal/rtree/repo.go index 5cdd39f..2267666 100644 --- a/internal/rtree/repo.go +++ b/internal/rtree/repo.go @@ -153,7 +153,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.CompactURL(), r.AbsolutePath()}, + Program: []string{"git", "clone", originURL.CanonicalURL(), r.AbsolutePath()}, }) if err != nil { return err @@ -164,7 +164,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.CompactURL()}, + Program: []string{"git", "remote", "add", remote.Name, remote.URL.CanonicalURL()}, WorkDir: r.AbsolutePath(), }) if err != nil { @@ -234,7 +234,7 @@ func (r *Repo) Move(checkoutPath string, makeSymlink bool) error { func (r Repo) ReformatRemoteURLs() error { for _, remote := range r.Remotes { err := cli.Interface.Run(cli.Command{ - Program: []string{"git", "remote", "set-url", remote.Name, remote.URL.CompactURL()}, + Program: []string{"git", "remote", "set-url", remote.Name, remote.URL.CanonicalURL()}, WorkDir: r.AbsolutePath(), }) if err != nil { -- cgit v1.3.1