You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/06/30 01:20:39 UTC
[GitHub] ccollins476ad closed pull request #186: Upgrade: Ensure "origin"
points to correct URL
ccollins476ad closed pull request #186: Upgrade: Ensure "origin" points to correct URL
URL: https://github.com/apache/mynewt-newt/pull/186
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index af3458f8..e6af835a 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -53,6 +53,7 @@ type Downloader interface {
UpdateRepo(path string, branchName string) error
AreChanges(path string) (bool, error)
CommitType(path string, commit string) (DownloaderCommitType, error)
+ FixupOrigin(path string) error
}
type GenericDownloader struct {
@@ -238,9 +239,12 @@ func merge(repoDir string, commit string) error {
return err
}
- if _, err := executeGitCommand(
- repoDir, []string{"merge", full}, true); err != nil {
-
+ cmd := []string{
+ "merge",
+ "--no-commit",
+ "--no-ff",
+ full}
+ if _, err := executeGitCommand(repoDir, cmd, true); err != nil {
util.StatusMessage(util.VERBOSITY_VERBOSE,
"Merging changes from %s: %s\n", full, err)
return err
@@ -368,6 +372,43 @@ func showFile(
return nil
}
+func getRemoteUrl(path string, remote string) (string, error) {
+ cmd := []string{
+ "remote",
+ "get-url",
+ remote,
+ }
+
+ o, err := executeGitCommand(path, cmd, true)
+ if err != nil {
+ return "", err
+ }
+
+ return strings.TrimSpace(string(o)), nil
+}
+
+func setRemoteUrlCmd(remote string, url string) []string {
+ return []string{
+ "remote",
+ "set-url",
+ remote,
+ url,
+ }
+}
+
+func setRemoteUrl(path string, remote string, url string, logCmd bool) error {
+ cmd := setRemoteUrlCmd(remote, url)
+ _, err := executeGitCommand(path, cmd, logCmd)
+ return err
+}
+
+func warnWrongOriginUrl(path string, curUrl string, goodUrl string) {
+ util.StatusMessage(util.VERBOSITY_QUIET,
+ "WARNING: Repo's \"origin\" remote points to unexpected URL: "+
+ "%s; correcting it to %s. Repo contents may be incorrect.\n",
+ curUrl, goodUrl)
+}
+
func (gd *GenericDownloader) GetCommit() string {
return gd.commit
}
@@ -529,25 +570,15 @@ func (gd *GithubDownloader) remoteUrls() (string, string) {
}
func (gd *GithubDownloader) setOriginUrl(path string, url string) error {
- genCmdStrs := func(urlStr string) []string {
- return []string{
- "remote",
- "set-url",
- "origin",
- urlStr,
- }
- }
-
// Hide password in logged command.
safeUrl := url
pw := gd.password()
if pw != "" {
safeUrl = strings.Replace(safeUrl, pw, "<password-hidden>", -1)
}
- util.LogShellCmd(genCmdStrs(safeUrl), nil)
+ util.LogShellCmd(setRemoteUrlCmd("origin", safeUrl), nil)
- _, err := executeGitCommand(path, genCmdStrs(url), false)
- return err
+ return setRemoteUrl(path, "origin", url, false)
}
func (gd *GithubDownloader) clearRemoteAuth(path string) error {
@@ -612,6 +643,22 @@ func (gd *GithubDownloader) DownloadRepo(commit string, dstPath string) error {
return nil
}
+func (gd *GithubDownloader) FixupOrigin(path string) error {
+ curUrl, err := getRemoteUrl(path, "origin")
+ if err != nil {
+ return err
+ }
+
+ // Use the public URL, i.e., hide the login and password.
+ _, publicUrl := gd.remoteUrls()
+ if curUrl == publicUrl {
+ return nil
+ }
+
+ warnWrongOriginUrl(path, curUrl, publicUrl)
+ return gd.setOriginUrl(path, publicUrl)
+}
+
func NewGithubDownloader() *GithubDownloader {
return &GithubDownloader{}
}
@@ -699,6 +746,20 @@ func (gd *GitDownloader) DownloadRepo(commit string, dstPath string) error {
return nil
}
+func (gd *GitDownloader) FixupOrigin(path string) error {
+ curUrl, err := getRemoteUrl(path, "origin")
+ if err != nil {
+ return err
+ }
+
+ if curUrl == gd.Url {
+ return nil
+ }
+
+ warnWrongOriginUrl(path, curUrl, gd.Url)
+ return setRemoteUrl(path, "origin", gd.Url, true)
+}
+
func NewGitDownloader() *GitDownloader {
return &GitDownloader{}
}
@@ -742,6 +803,10 @@ func (ld *LocalDownloader) DownloadRepo(commit string, dstPath string) error {
return nil
}
+func (ld *LocalDownloader) FixupOrigin(path string) error {
+ return nil
+}
+
func NewLocalDownloader() *LocalDownloader {
return &LocalDownloader{}
}
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index ce0cff3d..ef8cc748 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -331,6 +331,13 @@ func (r *Repo) ensureExists() error {
}
}
+ // Make sure the repo's "origin" remote points to the correct URL. This is
+ // necessary in case the user changed his `project.yml` file to point to a
+ // different fork.
+ if err := r.downloader.FixupOrigin(r.localPath); err != nil {
+ return err
+ }
+
return nil
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services