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: Don't stop upgrade when some repos are in dirty state #546

Merged
merged 1 commit into from
Apr 5, 2024
Merged
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
62 changes: 17 additions & 45 deletions newt/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (inst *Installer) installPrompt(vm deprepo.VersionMap, op installOp,
}

util.StatusMessage(util.VERBOSITY_DEFAULT,
"Making the following changes to the project:\n")
"Trying to make the following changes to the project:\n")

names := vm.SortedNames()
for _, name := range names {
Expand Down Expand Up @@ -488,46 +488,6 @@ func (inst *Installer) calcVersionMap(candidates []*repo.Repo) (
return vm, nil
}

// Checks if any repos in the specified slice are in a dirty state. If any
// repos are dirty and `force` is *not* enabled, an error is returned. If any
// repos are dirty and `force` is enabled, a warning is displayed.
func verifyRepoDirtyState(repos []*repo.Repo, force bool) error {
// [repo] => dirty-state.
var m map[*repo.Repo]string

// Collect all dirty repos and insert them into m.
for _, r := range repos {
dirtyState, err := r.DirtyState()
if err != nil {
return err
}

if dirtyState != "" {
if m == nil {
m = make(map[*repo.Repo]string)
m[r] = dirtyState
}
}
}

if len(m) > 0 {
s := "some repos are in a dirty state:\n"
for r, d := range m {
s += fmt.Sprintf(" %s: contains %s\n", r.Name(), d)
}

if !force {
s += "Specify the `-f` (force) switch to attempt anyway"
return util.NewNewtError(s)
} else {
util.OneTimeWarning("%s", s)
}
}

return nil

}

func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error {
var errors []string

Expand All @@ -554,10 +514,6 @@ func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error {
func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool,
ask bool) error {

if err := verifyRepoDirtyState(candidates, force); err != nil {
return err
}

vm, err := inst.calcVersionMap(candidates)
if err != nil {
return err
Expand Down Expand Up @@ -591,6 +547,22 @@ func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool,
// Upgrade each repo in the version map.
for _, r := range repos {
destVer := vm[r.Name()]
dirtyState, err := r.DirtyState()
if err != nil {
return err
}

if dirtyState != "" {
if !force {
util.StatusMessage(util.VERBOSITY_DEFAULT,
"%s is in dirty state, it won't be upgraded\n",
r.Name())
continue
} else {
util.OneTimeWarning("forced update of repo in dirty state: %s", r.Name())
}
}

if err := r.Upgrade(destVer); err != nil {
return err
}
Expand Down
Loading