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

Fix wrong version mapping in bump-unversioned-casks. #9456

Merged
merged 2 commits into from Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions Library/Homebrew/cli/named_args.rb
Expand Up @@ -129,13 +129,21 @@ def to_formulae_paths
# Keep existing paths and try to convert others to tap, formula or cask paths.
# If a cask and formula with the same name exist, includes both their paths
# unless `only` is specified.
def to_paths(only: nil)
sig { params(only: T.nilable(Symbol), recurse_tap: T::Boolean).returns(T::Array[Pathname]) }
def to_paths(only: nil, recurse_tap: false)
@to_paths ||= {}
@to_paths[only] ||= downcased_unique_named.flat_map do |name|
if File.exist?(name)
Pathname(name)
elsif name.count("/") == 1 && !name.start_with?("./", "/")
Tap.fetch(name).path
tap = Tap.fetch(name)

if recurse_tap
next tap.formula_files if only == :formula
next tap.cask_files if only == :cask
end

tap.path
else
next Formulary.path(name) if only == :formula
next Cask::CaskLoader.path(name) if only == :cask
Expand Down
11 changes: 5 additions & 6 deletions Library/Homebrew/dev-cmd/bump-unversioned-casks.rb
Expand Up @@ -17,7 +17,7 @@ module Homebrew
def self.bump_unversioned_casks_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`bump-unversioned-casks` [<options>] [<tap>]
`bump-unversioned-casks` [<options>] [<cask>|<tap>]

Check all casks with unversioned URLs in a given <tap> for updates.
EOS
Expand All @@ -28,7 +28,7 @@ def self.bump_unversioned_casks_args
flag "--state-file=",
description: "File for caching state."

named 1
min_named 1
end
end

Expand All @@ -43,11 +43,10 @@ def self.bump_unversioned_casks
end
state_file.dirname.mkpath

tap = Tap.fetch(args.named.first)

state = state_file.exist? ? JSON.parse(state_file.read) : {}

cask_files = tap.cask_files
cask_files = args.named.to_paths(only: :cask, recurse_tap: true)

unversioned_cask_files = cask_files.select do |cask_file|
url = cask_file.each_line do |line|
url = line[/\s*url\s+"([^"]+)"\s*/, 1]
Expand All @@ -59,7 +58,7 @@ def self.bump_unversioned_casks

unversioned_casks = unversioned_cask_files.map { |path| Cask::CaskLoader.load(path) }

ohai "Unversioned Casks: #{unversioned_casks.count}"
ohai "Unversioned Casks: #{unversioned_casks.count} (#{state.size} cached)"

checked, unchecked = unversioned_casks.partition { |c| state.key?(c.full_name) }

Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/unversioned_cask_checker_spec.rb
Expand Up @@ -16,6 +16,7 @@
["1.0", "1"] => "1.0",
["1.0", "0"] => "1.0",
["1.2.3.4000", "4000"] => "1.2.3.4000",
["5", "5.0.45"] => "5.0.45",
}

expected_mappings.each do |(short_version, version), expected_version|
Expand Down
17 changes: 7 additions & 10 deletions Library/Homebrew/unversioned_cask_checker.rb
Expand Up @@ -72,18 +72,15 @@ def self.version_from_package_info(package_info_path)
def self.decide_between_versions(short_version, version)
return short_version if short_version == version

short_version_match = short_version&.match?(/\A\d+(\.\d+)+\Z/)
version_match = version&.match?(/\A\d+(\.\d+)+\Z/)
if short_version && version
return version if version.match?(/\A\d+(\.\d+)+\Z/) && version.start_with?("#{short_version}.")
return short_version if short_version.match?(/\A\d+(\.\d+)+\Z/) && short_version.start_with?("#{version}.")

if short_version_match && version_match
return version if version.length > short_version.length && version.start_with?("#{short_version}.")
return short_version if short_version.length > version.length && short_version.start_with?("#{version}.")
end

if short_version&.match?(/\A\d+(\.\d+)*\Z/) && version&.match?(/\A\d+\Z/)
return short_version if short_version.start_with?("#{version}.") || short_version.end_with?(".#{version}")
if short_version.match?(/\A\d+(\.\d+)*\Z/) && version.match?(/\A\d+\Z/)
return short_version if short_version.start_with?("#{version}.") || short_version.end_with?(".#{version}")

return "#{short_version},#{version}"
return "#{short_version},#{version}"
end
end

short_version || version
Expand Down
2 changes: 1 addition & 1 deletion docs/Manpage.md
Expand Up @@ -899,7 +899,7 @@ present, "revision 1" will be added.
* `--message`:
Append *`message`* to the default commit message.

### `bump-unversioned-casks` [*`options`*] [*`tap`*]
### `bump-unversioned-casks` [*`options`*] [*`cask`*|*`tap`*]

Check all casks with unversioned URLs in a given *`tap`* for updates.

Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Expand Up @@ -1245,7 +1245,7 @@ Print what would be done rather than doing it\.
\fB\-\-message\fR
Append \fImessage\fR to the default commit message\.
.
.SS "\fBbump\-unversioned\-casks\fR [\fIoptions\fR] [\fItap\fR]"
.SS "\fBbump\-unversioned\-casks\fR [\fIoptions\fR] [\fIcask\fR|\fItap\fR]"
Check all casks with unversioned URLs in a given \fItap\fR for updates\.
.
.TP
Expand Down