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

utils: add git_repository #10245

Merged
merged 3 commits into from Jan 8, 2021

Conversation

SeekingMeaning
Copy link
Contributor

@SeekingMeaning SeekingMeaning commented Jan 7, 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?
  • Have you successfully run brew man locally and committed any changes?

(Supersedes #10149)

This PR adds utils/git_repository.rb which provides the publicly available methods Utils.git_head and Utils.git_head_short that can be used in formulae such as h2spec. I added these methods separately from utils/git.rb so that it does not have to be excluded from the Style/Documentation rubocop

Before:

commit = Utils.safe_popen_read("git", "rev-parse", "--short", "HEAD").chomp

After:

commit = Utils.git_short_head(buildpath)

Note: git rev-parse --short does not return a constant-length string—see https://stackoverflow.com/q/44286795

@BrewTestBot
Copy link
Member

Review period will end on 2021-01-08 at 05:42:47 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 7, 2021
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Thanks @SeekingMeaning!

Library/Homebrew/extend/git_repository.rb Outdated Show resolved Hide resolved
sig { returns(T.nilable(String)) }
def git_short_head
sig { params(length: T.nilable(Integer)).returns(T.nilable(String)) }
def git_short_head(length: 4)
return unless git? && Utils::Git.available?
Copy link
Member

Choose a reason for hiding this comment

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

I know you didn't write this but: if this could be refactored to not be unless .. && and instead an if I'd be grateful 🙇🏻. For bonus points in another PR: I'd love a rubocop that checks for unless .. && and unless ... ||. rubocop/rubocop#5400 was a first attempt for this in RuboCop itself but I think it'd be fine for this to just be a local cop for Homebrew until/if you're able to upstream it.

Library/Homebrew/extend/git_repository.rb Outdated Show resolved Hide resolved
@@ -20,6 +20,7 @@ Style/Documentation:
- 'utils.rb'
- 'utils/fork.rb'
- 'utils/gems.rb'
- 'utils/git_repository.rb'
Copy link
Member

Choose a reason for hiding this comment

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

Can docs be added (as these are public methods) instead of this being added to todo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do I fix this style error?

Library/Homebrew/utils/git_repository.rb:4:1: C: Missing top-level module documentation comment.
module Utils
^^^^^^

What about utils/popen and utils/fork (which both extend Utils)? Would adding top-level documentation comments cause conflicts?

Copy link
Member

Choose a reason for hiding this comment

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

How do I fix this style error?

Ah, yes, I see. Would need to perhaps define that module in utils.rb and document it? I think it's fine to punt on that, then.

@SeekingMeaning SeekingMeaning marked this pull request as draft January 7, 2021 16:05
@BrewTestBot
Copy link
Member

Review period ended.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 8, 2021
@SeekingMeaning SeekingMeaning merged commit 7a08668 into Homebrew:master Jan 8, 2021
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Feb 8, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Feb 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants