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

update: Don't report formulae that are moved within a tap but not renamed #480

Merged
merged 4 commits into from
Jul 16, 2016
Merged

update: Don't report formulae that are moved within a tap but not renamed #480

merged 4 commits into from
Jul 16, 2016

Conversation

jawshooah
Copy link
Contributor

@jawshooah jawshooah commented Jul 9, 2016

  • 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 tests with your changes locally?

It's misleading to report a formula as "new" when it's only been moved from one directory to another within the same tap.

Ref: caskroom/homebrew-cask#22669 (comment)

# Don't report formulae that are moved within a tap but not renamed
next if src_full_name == dst_full_name
@report[:D] << src_full_name if tap.formula_file?(src)
@report[:A] << dst_full_name if tap.formula_file?(dst)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a very subtle problem with these two lines. If formulae happen to be moved within a tap and a formula gets renamed before or afterwards (thus src_full_name != dst_full_name) and the update covers both operations, then the report will look something like this (I experimented a bit with my local copy of the homebrew/gui tap):

Updated 1 tap (homebrew/gui).
==> New Formulae
homebrew/gui/xchat2

But it should have looked something like this:

Updated 1 tap (homebrew/gui).
==> Renamed Formulae
homebrew/gui/xchat -> homebrew/gui/xchat2

The reason is that if tap.formula_file?(src) will always be false as it checks against the current Tap#formula_dir. It's admittedly a rare corner case, but this should solve it:

if tap.formula_file?(dst)
  @report[:D] << src_full_name
  @report[:A] << dst_full_name
end

Copy link
Contributor Author

@jawshooah jawshooah Jul 10, 2016

Choose a reason for hiding this comment

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

Nice catch! Fixed in f1a7eb6

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for finding an even more elegant solution and particularly for adding a nice test case!

@UniqMartin
Copy link
Contributor

Thanks for taking a look and for this PR! I commented on a corner case, but otherwise it's looking good.

Unfortunately, other parts of Homebrew also assume that Tap#formula_dir never changes during the lifetime of a tap and thus break if formulae are relocated within a tap. See issue #87 for details. Do you maybe see yourself tackling these as well? (Would be awesome, but I certainly don't expect you to.)

@@ -209,8 +209,13 @@ def report
end
@report[:M] << tap.formula_file_to_name(src)
when /^R\d{0,3}/
@report[:D] << tap.formula_file_to_name(src) if tap.formula_file?(src)
@report[:A] << tap.formula_file_to_name(dst) if tap.formula_file?(dst)
next unless tap.formula_file?(dst)
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized this check can be dropped completely, as there's a check preceding the case statement that already makes sure that at least one of the modified paths is a formula file:

next unless paths.any? { |p| tap.formula_file?(p) }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, removed in 7195878.

@UniqMartin UniqMartin added the needs response Needs a response from the issue/PR author label Jul 10, 2016
@ghost ghost removed the needs response Needs a response from the issue/PR author label Jul 10, 2016
@UniqMartin UniqMartin merged commit 4abdeb7 into Homebrew:master Jul 16, 2016
@UniqMartin
Copy link
Contributor

Merged in 4abdeb7. Thank you for this contribution to Homebrew, @jawshooah! 🎉

Sorry for the long delay! I'd be still interested in your answer to the following question:

Unfortunately, other parts of Homebrew also assume that Tap#formula_dir never changes during the lifetime of a tap and thus break if formulae are relocated within a tap. See issue #87 for details. Do you maybe see yourself tackling these as well?

@jawshooah
Copy link
Contributor Author

@UniqMartin No worries! Sorry for the delay in getting back to you. I haven't looked too deeply into FormulaVersions but it seems like a proper fix might require a deep dive into Git plumbing commands. I'll see about giving it a shot later this evening, but I can't make any promises.

souvik1997 pushed a commit to souvik1997/brew that referenced this pull request Jul 25, 2016
@Homebrew Homebrew locked and limited conversation to collaborators May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants