Repository navigation
fix: refresh repository identity after SSH translation #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c04dd5f
0a8aabd
125442e
1117f89
393ceb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,42 @@ func (rs RemoteSet) FilterByHosts(hosts []string) RemoteSet { | |
| return filtered | ||
| } | ||
|
|
||
| // Translate rewrites the URLs of every remote and re-derives each remote's | ||
| // repository identity from the result. | ||
| func (rs RemoteSet) Translate(translate func(*url.URL) *url.URL) { | ||
| for _, r := range rs { | ||
| r.Translate(translate) | ||
| } | ||
| } | ||
|
|
||
| // Translate rewrites the remote's URLs and re-derives its repository identity | ||
| // from the result. | ||
| func (r *Remote) Translate(translate func(*url.URL) *url.URL) { | ||
| if r.FetchURL != nil { | ||
| r.FetchURL = translate(r.FetchURL) | ||
| } | ||
| if r.PushURL != nil { | ||
| r.PushURL = translate(r.PushURL) | ||
| } | ||
| r.resolveIdentity() | ||
| } | ||
|
|
||
| // resolveIdentity sets the remote's repository from its fetch URL, falling back | ||
| // to its push URL. Like gh, a remote whose URLs don't name a repository has no | ||
| // identity. | ||
| func (r *Remote) resolveIdentity() { | ||
| r.Host, r.Owner, r.Repo = "", "", "" | ||
| for _, u := range []*url.URL{r.FetchURL, r.PushURL} { | ||
| if u == nil { | ||
| continue | ||
| } | ||
| if host, owner, repo, err := RepoInfoFromURL(u); err == nil { | ||
| r.Host, r.Owner, r.Repo = host, owner, repo | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+91
to
+102
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: I know this is meant to simplify the old In this old would result in a different state with this PR's changes: I know it's super unlikely for a user to have such a weird config, so I think we're fine shipping the changes. Just wanted to call out in case you think otherwise.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think your specific example is right because
Thanks for your diligence! |
||
|
|
||
| func listRemotes() ([]string, error) { | ||
| stdOut, _, err := Exec("remote", "-v") | ||
| if err != nil { | ||
|
|
@@ -88,7 +124,6 @@ func parseRemotes(gitRemotes []string) RemoteSet { | |
| if err != nil { | ||
| continue | ||
| } | ||
| host, owner, repo, _ := RepoInfoFromURL(url) | ||
|
|
||
| var rem *Remote | ||
| if len(remotes) > 0 { | ||
|
|
@@ -105,22 +140,13 @@ func parseRemotes(gitRemotes []string) RemoteSet { | |
| switch urlType { | ||
| case "fetch": | ||
| rem.FetchURL = url | ||
| rem.Host = host | ||
| rem.Owner = owner | ||
| rem.Repo = repo | ||
| case "push": | ||
| rem.PushURL = url | ||
| if rem.Host == "" { | ||
| rem.Host = host | ||
| } | ||
| if rem.Owner == "" { | ||
| rem.Owner = owner | ||
| } | ||
| if rem.Repo == "" { | ||
| rem.Repo = repo | ||
| } | ||
| } | ||
| } | ||
| for _, rem := range remotes { | ||
| rem.resolveIdentity() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a cleanup that allows the |
||
| } | ||
| return remotes | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved translation here rather than keeping it in
Currentbecause the pattern exhibited a bit of https://refactoring.guru/smells/feature-envy