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

repo: Upgrade: use branch or commit #445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions newt/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ func (r *Repo) Upgrade(ver newtutil.RepoVersion) error {
return err
}

if branch := r.downloader.MainBranch(); branch != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you could just add if branch := r.downloader.MainBranch(); branch == "" { around the r.CommitFromVer call block, and avoid the r.updateRepo copypasta.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While doing newt upgrade the script tries to checkout to 'master' while there is 'main' instead. Now it is possible to use the 'branch: 'main'' in repository.yml file, and it doesn't only allow to fetch properly, but also to checkout.

About the code - you're right, sorry, I am new to 'go', maybe such solution would be better:

func (r *Repo) Upgrade(ver newtutil.RepoVersion) error {
	commit, err := r.CommitFromVer(ver)
	if err != nil {
		return err
	}

	if branch := r.downloader.MainBranch(); branch != "" {
		commit = branch
	}

	if err := r.updateRepo(commit); err != nil {
		return err
	}

	return nil
}

Let me know. Thank you

commit = branch
}

if err := r.updateRepo(commit); err != nil {
return err
}
Expand Down