You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2020/03/09 21:11:00 UTC
[mynewt-newt] branch master updated: upgrade: Don't warn on fixup
to an equivalent URL
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
The following commit(s) were added to refs/heads/master by this push:
new 45add9e upgrade: Don't warn on fixup to an equivalent URL
45add9e is described below
commit 45add9ee283c1bfd1a5a80fce694451e1cdffcd8
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Mar 5 17:00:31 2020 -0800
upgrade: Don't warn on fixup to an equivalent URL
If `project.yml` specifies a repo with a different URL than the current
`origin`, newt fixes the `origin` URL and produces a warning like this:
WARNING: Repo's "origin" remote points to unexpected URL:
git@github.com:apache/mynewt-nimble.git; correcting it to
https://github.com/apache/mynewt-nimble.git. Repo contents may be
incorrect.
This commit suppresses the warning if the two URLs are "equivalent".
URLs are considered equivalent if:
1. The strings are identical after the optional ".git" suffixes are
stripped,
OR
2. One is a "git@" URL and the other is an "https://" URL for the same
repo. For example:
git@github.com:apache/mynewt-core.git
https://github.com/apache/mynewt-core
---
newt/downloader/downloader.go | 55 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 53 insertions(+), 2 deletions(-)
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 474309d..506b798 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -314,6 +314,57 @@ func getCommits(path string) (map[string]Commit, error) {
return m, nil
}
+// urlsEquivalent determines if two URLs point to the same repo. URLs are
+// equivalent if:
+// 1. The strings are identical after the optional ".git" suffixes are
+// stripped,
+// OR
+// 2. One is a "git@" URL and the other is an "https://" URL for the same
+// repo. For example:
+// git@github.com:apache/mynewt-core.git
+// https://github.com/apache/mynewt-core
+func urlsEquivalent(a string, b string) bool {
+ // Strip optional `.git` suffix.
+ a = strings.TrimSuffix(a, ".git")
+ b = strings.TrimSuffix(b, ".git")
+
+ if a == b {
+ return true
+ }
+
+ gitRE := regexp.MustCompile(`git@([^:]+):(.*)`)
+
+ parseGit := func(s string) string {
+ groups := gitRE.FindStringSubmatch(s)
+ if len(groups) != 3 {
+ return ""
+ }
+
+ return groups[1] + "/" + groups[2]
+ }
+
+ parseHttps := func(s string) string {
+ if !strings.HasPrefix(s, "https://") {
+ return ""
+ }
+
+ return strings.TrimPrefix(s, "https://")
+ }
+
+ var git string
+ var https string
+
+ git = parseGit(a)
+ if git == "" {
+ git = parseGit(b)
+ https = parseHttps(a)
+ } else {
+ https = parseHttps(b)
+ }
+
+ return git != "" && git == https
+}
+
// init populates a generic downloader with branch and tag information.
func (gd *GenericDownloader) init(path string) error {
cmap, err := getCommits(path)
@@ -848,7 +899,7 @@ func (gd *GithubDownloader) FixupOrigin(path string) error {
// Use the public URL, i.e., hide the login and password.
_, publicUrl := gd.remoteUrls()
- if curUrl == publicUrl {
+ if urlsEquivalent(curUrl, publicUrl) {
return nil
}
@@ -925,7 +976,7 @@ func (gd *GitDownloader) FixupOrigin(path string) error {
return err
}
- if curUrl == gd.Url {
+ if urlsEquivalent(curUrl, gd.Url) {
return nil
}