This is an automated email from the ASF dual-hosted git repository.
janc 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 4632ba20 newt: Fix shallow upgrade with specific commit version
4632ba20 is described below
commit 4632ba209543c4163ffbb1153b5f75a37d35e514
Author: Michal Gorecki <[email protected]>
AuthorDate: Fri Feb 23 09:49:09 2024 +0100
newt: Fix shallow upgrade with specific commit version
Upgrading project using shallow option was causing an error if
repository version was specified as specific commit.
Because this specific commit could not yet be fetched
it could not be found during version validation.
Now if specific commit could not be found, instead of returning
an error immediately, we first try to fetch it.
---
newt/downloader/downloader.go | 18 ++++++++++++++++++
newt/repo/version.go | 9 +++++++++
2 files changed, 27 insertions(+)
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 8ed2927b..eea3249a 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -61,6 +61,9 @@ type Downloader interface {
// Fetches all remotes.
Fetch(path string) error
+ // Fetches specific commit
+ FetchCommit(path string, commit string) error
+
// Checks out the specified commit (hash, tag, or branch). Always puts
the
// repo in a "detached head" state.
Checkout(path string, commit string) error
@@ -774,6 +777,11 @@ func (gd *GithubDownloader) Fetch(repoDir string) error {
})
}
+func (gd *GithubDownloader) FetchCommit(repoDir string, commit string) error {
+ _, err := executeGitCommand(repoDir, []string{"fetch", "--depth=1",
"origin", commit}, true)
+ return err
+}
+
func (gd *GithubDownloader) password() string {
if gd.Password != "" {
return gd.Password
@@ -943,6 +951,11 @@ func (gd *GitDownloader) Fetch(repoDir string) error {
})
}
+func (gd *GitDownloader) FetchCommit(repoDir string, commit string) error {
+ _, err := executeGitCommand(repoDir, []string{"fetch", "--depth=1",
"origin", commit}, true)
+ return err
+}
+
func (gd *GitDownloader) FetchFile(
commit string, path string, filename string, dstDir string) error {
@@ -1043,6 +1056,11 @@ func (ld *LocalDownloader) Fetch(path string) error {
return ld.Clone(ld.MainBranch(), path)
}
+func (ld *LocalDownloader) FetchCommit(path string, commit string) error {
+ _, err := executeGitCommand(path, []string{"fetch", "--depth=1",
"origin", commit}, true)
+ return err
+}
+
func (ld *LocalDownloader) Checkout(path string, commit string) error {
_, err := executeGitCommand(path, []string{"checkout", commit}, true)
return err
diff --git a/newt/repo/version.go b/newt/repo/version.go
index 5f0329be..b4aa09c5 100644
--- a/newt/repo/version.go
+++ b/newt/repo/version.go
@@ -126,6 +126,15 @@ func (r *Repo) VersionIsValid(ver newtutil.RepoVersion)
bool {
}
cs, _ := r.downloader.CommitsFor(r.Path(), ver.Commit)
+
+ // Try to fetch commit if it was not found
+ if len(cs) <= 0 {
+ err := r.Downloader().FetchCommit(r.Path(), ver.Commit)
+ if err != nil {
+ return false
+ }
+ cs, _ = r.downloader.CommitsFor(r.Path(), ver.Commit)
+ }
return len(cs) > 0
}