Skip to content

Commit

Permalink
newt: Upgrade repos specified in project and package once
Browse files Browse the repository at this point in the history
Now repos that are specified in both project.yml and pkg.yml
will be upgraded only once - to the version specified in
project.yml
  • Loading branch information
m-gorecki committed Feb 23, 2024
1 parent 6cffebf commit ed57277
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
7 changes: 7 additions & 0 deletions newt/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ func (inst *Installer) shouldUpgradeRepo(
return true, nil
}

if r.IsUpgradedFromProjectYml() {
return false, nil
}

if !r.VersionsEqual(*curVer, destVer) {
return true, nil
}
Expand Down Expand Up @@ -590,6 +594,9 @@ func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool,
if err := r.Upgrade(destVer); err != nil {
return err
}
if r.IsFromProjectYml() {
r.SetIsUpgradedFromProjectYml()
}
util.StatusMessage(util.VERBOSITY_DEFAULT,
"%s successfully upgraded to version %s\n",
r.Name(), destVer.String())
Expand Down
20 changes: 16 additions & 4 deletions newt/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func NewProject(dir string, download bool) (*Project, error) {
return proj, nil
}

func (proj *Project) isRepoAdded(r *repo.Repo) bool {
for _, pr := range proj.repos {
if pr.Name() == r.Name() {
return true
}
}
return false
}

func (proj *Project) GetPkgRepos() error {

for _, pkgList := range proj.packages {
Expand Down Expand Up @@ -199,10 +208,13 @@ func (proj *Project) GetPkgRepos() error {
repoName, fields["vers"], err.Error())
}
r.SetPkgName(pkg.Name())
if err := proj.addRepo(r, true); err != nil {
return err

if !proj.isRepoAdded(r) {
if err := proj.addRepo(r, true); err != nil {
return err
}
proj.rootRepoReqs[repoName] = verReq
}
proj.rootRepoReqs[repoName] = verReq
}
}
}
Expand Down Expand Up @@ -623,7 +635,7 @@ func (proj *Project) loadConfig(download bool) error {
"%s (%s)",
repoName, fields["vers"], err.Error())
}

r.SetIsFromProjectYml()
if err := proj.addRepo(r, download); err != nil {
return err
}
Expand Down
24 changes: 24 additions & 0 deletions newt/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ type Repo struct {
// version => commit
vers map[newtutil.RepoVersion]string

// Since we are calling upgrade twice - first time for repos from project.yml
// and second time for repos from packages, we need to keep track on status
// of each repo. If repo is defined in project.yml we want to upgrade it only
// once so the version from project.yml stays valid. These flags are used for
// this purpose.
isFromProjectYml bool
isUpgradedFromProjectYml bool

hasSubmodules bool
submodules []string
}
Expand Down Expand Up @@ -201,6 +209,22 @@ func (r *Repo) patchesFilePath() string {
"/.patches/"
}

func (r *Repo) IsUpgradedFromProjectYml() bool {
return r.isUpgradedFromProjectYml
}

func (r *Repo) SetIsUpgradedFromProjectYml() {
r.isUpgradedFromProjectYml = true
}

func (r *Repo) IsFromProjectYml() bool {
return r.isFromProjectYml
}

func (r *Repo) SetIsFromProjectYml() {
r.isFromProjectYml = true
}

// Checks for repository.yml file presence in specified repo folder.
// If there is no such file, the repo in specified folder is external.
func (r *Repo) IsExternal(dir string) bool {
Expand Down

0 comments on commit ed57277

Please sign in to comment.