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

Don't uninstall stable keg with --HEAD #11438

Merged
merged 5 commits into from May 29, 2021

Conversation

cnnrmnn
Copy link
Contributor

@cnnrmnn cnnrmnn commented May 25, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

At the moment, installing the head version of a formula with brew install --HEAD uninstalls the stable version of the formula if it is installed. This is obviously undesirable if you want to have the head and stable versions of a formula installed simultaneously.

This behavior seemed odd when I first discovered it, but it's actually the product of brew install uninstalling any kegs that have older versions than the one being installed. The stable keg is obviously older than the head keg, so it's uninstalled.

This PR changes brew install so that it doesn't do any clean-up if --HEAD is given.

@Rylan12
Copy link
Member

Rylan12 commented May 26, 2021

I may be backtracking a bit on what I said in #11397 but I wonder if what needs to be fixed is that installing a stable version doesn't remove the HEAD version.

I think that's more consistent with what we do elsewhere in Homebrew (i.e. installing a formula removes the other versions unless HOMEBREW_NO_INSTALL_CLEANUP is set).

Is there a specific reason you have in mind for this?

@cnnrmnn
Copy link
Contributor Author

cnnrmnn commented May 26, 2021

Is there a specific reason you have in mind for this?

It would make it easier to have head and stable versions installed simultaneously. I think that this is a more common use case than just keeping older kegs when a new keg is installed (think people who keep "stable" and "nightly" builds installed simultaneously). I like the idea of being able to have head and stable kegs installed without keeping every old keg as would happen if HOMEBREW_NO_INSTALL_CLEANUP were set. I don't think having this as a default does any harm or is particularly confusing.

I think that's more consistent with what we do elsewhere in Homebrew (i.e. installing a formula removes the other versions unless HOMEBREW_NO_INSTALL_CLEANUP is set).

That is true, but I think that the inconsistency could be warranted. Also, installing a formula only removes older versions unless HOMEBREW_NO_INSTALL_CLEANUP is set.

I may be backtracking a bit on what I said in #11397 but I wonder if what needs to be fixed is that installing a stable version doesn't remove the HEAD version.

This is a fair option as well. The use case I'm describing may be rare enough where it makes sense to require users to set HOMEBREW_NO_INSTALL_CLEANUP.

@cnnrmnn
Copy link
Contributor Author

cnnrmnn commented May 26, 2021

I'm happy to make changes if you'd like to go in the other direction.

@Rylan12
Copy link
Member

Rylan12 commented May 26, 2021

Yeah, I see you're point. I guess I'm not sure what the best thing is. Let's get some feedback from other maintainers.

@Rylan12 Rylan12 added the discussion Input solicited from others label May 26, 2021
@carlocab
Copy link
Member

carlocab commented May 27, 2021

I'd find this useful. I also view HOMEBREW_NO_INSTALL_CLEANUP as doing something different: setting it means you don't want brew cleanup to remove outdated formula installs. Having HEAD installed doesn't make stable outdated. (cf. brew outdated --fetch-HEAD foo when the stable version of foo is installed)

On the other hand, we've removed support for switching between arbitrary versions of formulae on purpose, and perhaps some of the reasons we did that apply here.

@Rylan12
Copy link
Member

Rylan12 commented May 27, 2021

In that case, I'm fine with this change.

To me, switching between arbitrary version does feel different from switching between a head and stable version, so I think this change is fine.

I think, though, that the change should probably be made to the Formula#eligible_kegs_for_cleanup method rather than just conditionally running Cleanup::install_formula_clean!. The latter also does some other cleanup that I think we still want to occur (e.g. Cleanup#cleanup_lockfiles)

@cnnrmnn
Copy link
Contributor Author

cnnrmnn commented May 28, 2021

I think, though, that the change should probably be made to the Formula#eligible_kegs_for_cleanup method rather than just conditionally running Cleanup::install_formula_clean!. The latter also does some other cleanup that I think we still want to occur (e.g. Cleanup#cleanup_lockfiles)

Good point, my mistake. I've pushed a fix.

Formula#eligible_kegs_for_cleanup now returns all installed kegs except the newest head keg (compared only with other head kegs) and the newest non-head keg (compared only with other non-head kegs).

Rylan12
Rylan12 previously approved these changes May 29, 2021
Copy link
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks @cnnrmnn!

@Rylan12
Copy link
Member

Rylan12 commented May 29, 2021

Hmm, how do you re-link the stable version once you've installed a HEAD version?

If I check out this PR and install a stable version, then install the head version, then try to link the stable version with brew link foo, it links the HEAD version.

@carlocab
Copy link
Member

Just to be sure:

With this PR, if I have the stable version of foo installed, I should be able to install the HEAD version with brew unlink foo && brew install --HEAD foo, correct?

What about if I have HEAD installed, and want the stable one? Would brew unlink foo && brew install foo also work?

@Rylan12
Copy link
Member

Rylan12 commented May 29, 2021

Okay, I think the issue I was having was that this PR was created before #11397 was merged. Here's what I did to test (after rebasing the PR). I used htop because it has a head block and doesn't take too long to build:

$ brew install htop # install stable version

$ ls $(brew --cellar htop)
3.0.5

$ brew unlink htop
Unlinking /usr/local/Cellar/htop/3.0.5... 5 symlinks removed.

$ brew install --HEAD htop # install HEAD version

$ ls $(brew --cellar htop)
3.0.5        HEAD-c752c54

$ brew unlink htop
Unlinking /usr/local/Cellar/htop/HEAD-c752c54... 5 symlinks removed.

$ brew link htop
Linking /usr/local/Cellar/htop/3.0.5... 5 symlinks created.

$ brew unlink htop
Unlinking /usr/local/Cellar/htop/3.0.5... 5 symlinks removed.

$ brew link --HEAD htop
Linking /usr/local/Cellar/htop/HEAD-c752c54... 5 symlinks created.

$ brew uninstall --force htop # uninstall everything

$ brew install --HEAD htop # try installing HEAD first this time

$ ls $(brew --cellar htop)
HEAD-c752c54

$ brew unlink htop
Unlinking /usr/local/Cellar/htop/HEAD-c752c54... 5 symlinks removed.

$ brew install htop # links stable version

$ ls $(brew --cellar htop)
3.0.5        HEAD-c752c54

$ brew unlink htop
Unlinking /usr/local/Cellar/htop/3.0.5... 5 symlinks removed.

$ brew link htop
Linking /usr/local/Cellar/htop/3.0.5... 5 symlinks created.

$ brew unlink htop
Unlinking /usr/local/Cellar/htop/3.0.5... 5 symlinks removed.

$ brew link --HEAD htop
Linking /usr/local/Cellar/htop/HEAD-c752c54... 5 symlinks created.

Everything there looks good to me. Does that help, @carlocab? Is there something else to test?

@Rylan12
Copy link
Member

Rylan12 commented May 29, 2021

@cnnrmnn can you rebase this PR onto the latest master branch? I don't expect there will be any issues but because it goes alongside #11397 I'd like to make sure they both get through CI together

@cnnrmnn
Copy link
Contributor Author

cnnrmnn commented May 29, 2021

Did I do that incorrectly? I had to force push it. I ran git rebase master on no-uninstall-stable. Would it have been better to just merge master into no-uninstall-stable?

@carlocab
Copy link
Member

You did fine. git rebase master (or git rebase origin/master) is definitely what you want here. git merge will create a merge commit, and we don't want one of those until a PR is merged.

@Rylan12
Copy link
Member

Rylan12 commented May 29, 2021

Did I do that incorrectly? I had to force push it. I ran git rebase master on no-uninstall-stable. Would it have been better to just merge master into no-uninstall-stable?

You're good! You do need to force push after a rebase because you're modifying the history of the commits on the PR branch rather than just adding new ones. Here's a quick article about rebase in case you're curious: https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase or https://www.atlassian.com/git/tutorials/merging-vs-rebasing

@Rylan12 Rylan12 merged commit eeef3f4 into Homebrew:master May 29, 2021
@cnnrmnn cnnrmnn deleted the no-uninstall-stable branch May 30, 2021 16:48
@carlocab
Copy link
Member

I think this is a regression:

❯ brew upgrade --fetch-HEAD neovim
...
==> Summary
🍺  /usr/local/Cellar/neovim/HEAD-3cd688f_2: 1,542 files, 21.2MB, built in 2 minutes 36 seconds
Warning: Skipping (old) /usr/local/Cellar/neovim/HEAD-3cd688f_2 due to it being linked
❯ brew info neovim
neovim: stable 0.4.4 (bottled), HEAD
Ambitious Vim-fork focused on extensibility and agility
https://neovim.io/
/usr/local/Cellar/neovim/HEAD-3cd688f_2 (1,542 files, 21.2MB) *
  Built from source on 2021-05-31 at 14:06:26
/usr/local/Cellar/neovim/HEAD-43956de_2 (1,542 files, 21.2MB)
  Built from source on 2021-05-29 at 13:24:08

It seems if I have an older HEAD version installed, it will no longer be unlinked automatically when I do brew upgrade.

@Rylan12
Copy link
Member

Rylan12 commented May 31, 2021

Is there an easy way to determine which HEAD keg is the "latest" one? I wonder if that's where the problem is coming from. Haven't looked into it. Are there easy reproduction steps for what you're seeing, @carlocab, or do I need to simulate an old HEAD keg to see this behavior?

@carlocab
Copy link
Member

Is there an easy way to determine which HEAD keg is the "latest" one?

Not that I know of... I know brew outdated --fetch-HEAD always knows which one.

Are there easy reproduction steps for what you're seeing, @carlocab, or do I need to simulate an old HEAD keg to see this behavior?

Simulating an old HEAD might be the only way here. It might also be enough to rename the directory with the version/commit hash to something that isn't the latest commit on the default branch.

@Rylan12
Copy link
Member

Rylan12 commented Jun 1, 2021

I think I've got it. PR opened: #11475

@cnnrmnn
Copy link
Contributor Author

cnnrmnn commented Jun 1, 2021

Thanks for the fix, @Rylan12! Sorry I couldn't get to it myself; I've been traveling.

@github-actions github-actions bot added the outdated PR was locked due to age label Jul 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
discussion Input solicited from others outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants