Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newt: Fix shallow upgrade with specific commit version #543

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions newt/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions newt/repo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading