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 2016/11/22 23:16:26 UTC

incubator-mynewt-newt git commit: newt - Fix for "local downloads" - checkout tag.

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop d971a4376 -> 6473f827c


newt - Fix for "local downloads" - checkout tag.

This is for the local download test feature (allow a repo to be
installed or upgraded from a local directory rather than github).  Now,
the correct tag is checked out in the copied repo.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/6473f827
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/6473f827
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/6473f827

Branch: refs/heads/develop
Commit: 6473f827c38cdbf1dc68a54239b39efc1e00eed9
Parents: d971a43
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 22 15:15:06 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 22 15:15:06 2016 -0800

----------------------------------------------------------------------
 newt/downloader/downloader.go | 67 +++++++++++++++++++++++++-------------
 1 file changed, 44 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6473f827/newt/downloader/downloader.go
----------------------------------------------------------------------
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 29c0677..7849feb 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -65,6 +65,43 @@ type LocalDownloader struct {
 	Path string
 }
 
+func checkout(repoDir string, commit string) error {
+	// Retrieve the current directory so that we can get back to where we
+	// started after the download completes.
+	pwd, err := os.Getwd()
+	if err != nil {
+		return util.NewNewtError(err.Error())
+	}
+
+	gitPath, err := exec.LookPath("git")
+	if err != nil {
+		return util.NewNewtError(fmt.Sprintf("Can't find git binary: %s\n",
+			err.Error()))
+	}
+
+	if err := os.Chdir(repoDir); err != nil {
+		return util.NewNewtError(err.Error())
+	}
+
+	// Checkout the specified commit.
+	cmds := []string{
+		gitPath,
+		"checkout",
+		commit,
+	}
+
+	if o, err := util.ShellCommand(strings.Join(cmds, " ")); err != nil {
+		return util.NewNewtError(string(o))
+	}
+
+	// Go back to original directory.
+	if err := os.Chdir(pwd); err != nil {
+		return util.NewNewtError(err.Error())
+	}
+
+	return nil
+}
+
 func (gd *GenericDownloader) Branch() string {
 	return gd.branch
 }
@@ -128,13 +165,6 @@ func (gd *GithubDownloader) FetchFile(name string, dest string) error {
 }
 
 func (gd *GithubDownloader) DownloadRepo(commit string) (string, error) {
-	// Retrieve the current directory so that we can get back to where we
-	// started after the download completes.
-	pwd, err := os.Getwd()
-	if err != nil {
-		return "", util.NewNewtError(err.Error())
-	}
-
 	// Get a temporary directory, and copy the repository into that directory.
 	tmpdir, err := ioutil.TempDir("", "newt-repo")
 	if err != nil {
@@ -177,23 +207,9 @@ func (gd *GithubDownloader) DownloadRepo(commit string) (string, error) {
 		}
 	}
 
-	if err := os.Chdir(tmpdir); err != nil {
-		return "", util.NewNewtError(err.Error())
-	}
-
 	// Checkout the specified commit.
-	cmds = []string{
-		gitPath,
-		"checkout",
-		commit,
-	}
-
-	if o, err := util.ShellCommand(strings.Join(cmds, " ")); err != nil {
-		return "", util.NewNewtError(string(o))
-	}
-
-	if err := os.Chdir(pwd); err != nil {
-		return "", util.NewNewtError(err.Error())
+	if err := checkout(tmpdir, commit); err != nil {
+		return "", err
 	}
 
 	return tmpdir, nil
@@ -228,6 +244,11 @@ func (ld *LocalDownloader) DownloadRepo(commit string) (string, error) {
 		return "", err
 	}
 
+	// Checkout the specified commit.
+	if err := checkout(tmpdir, commit); err != nil {
+		return "", err
+	}
+
 	return tmpdir, nil
 }