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

commit 070430fc3c799bbc58f7a73b3fc50709c4a81cb7
Author: Christopher Collins <ccoll...@apache.org>
AuthorDate: Fri Oct 19 11:50:45 2018 -0700

    Allow branches with no default upstream
    
    Some commands would fail when a repo had a branch with no default
    upstream checked out.  The failures were as follows:
    
    * `newt info`: Displayed a git "fatal" error instead of the correct
    version (inferred version if `version.yml` is not present).
    
    * `newt upgrade`: Aborted without performing the upgrade (displayed the
    same "fatal" git error).
---
 newt/downloader/downloader.go | 9 +++++++--
 newt/install/install.go       | 8 ++++----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index ac0f113..02f54fa 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -557,13 +557,18 @@ func (gd *GenericDownloader) DirtyState(path string) 
(string, error) {
                return "staged changes", nil
        }
 
-       // If on a branch, check for unpushed commits.
+       // If on a branch with a configured upstream, check for unpushed 
commits.
        branch, err := gd.CurrentBranch(path)
        if err != nil {
                return "", err
        }
 
-       if branch != "" {
+       upstream, err := upstreamFor(path, "HEAD")
+       if err != nil {
+               return "", err
+       }
+
+       if upstream != "" && branch != "" {
                cmd = []string{
                        "rev-list",
                        "@{u}..",
diff --git a/newt/install/install.go b/newt/install/install.go
index e97eb0f..7f3d0d5 100644
--- a/newt/install/install.go
+++ b/newt/install/install.go
@@ -935,7 +935,7 @@ func (inst *Installer) Sync(candidates []*repo.Repo,
 }
 
 type repoInfo struct {
-       installedVer *newtutil.RepoVersion
+       installedVer *newtutil.RepoVersion // nil if not installed.
        errorText    string
        dirtyState   string
        needsUpgrade bool
@@ -953,12 +953,12 @@ func (inst *Installer) gatherInfo(r *repo.Repo,
                return ri
        }
 
-       ver, err := r.InstalledVersion()
+       ver, err := detectVersion(r)
        if err != nil {
                ri.errorText = strings.TrimSpace(err.Error())
                return ri
        }
-       ri.installedVer = ver
+       ri.installedVer = &ver
 
        dirty, err := r.DirtyState()
        if err != nil {
@@ -968,7 +968,7 @@ func (inst *Installer) gatherInfo(r *repo.Repo,
        ri.dirtyState = dirty
 
        if vm != nil {
-               if ver == nil || *ver != (*vm)[r.Name()] {
+               if ver != (*vm)[r.Name()] {
                        ri.needsUpgrade = true
                }
        }

Reply via email to