From ef1e07b88bf406a7b9b50cec78c8a7617e87ef62 Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Tue, 2 Mar 2021 19:10:58 +1100 Subject: [PATCH] rubocops/patches: GitLab patches should use .diff Only `.diff` URLs return output comparable to the diffs from `git diff --full-index`. While the extra metadata from `.patch` is nice, the instability of the patch contents is undesirable. Co-Authored-By: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> --- Library/Homebrew/rubocops/patches.rb | 6 ++++-- Library/Homebrew/test/rubocops/patches_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/rubocops/patches.rb b/Library/Homebrew/rubocops/patches.rb index 272e7c8311..79ffc873c6 100644 --- a/Library/Homebrew/rubocops/patches.rb +++ b/Library/Homebrew/rubocops/patches.rb @@ -56,8 +56,10 @@ module RuboCop problem "GitHub patches should end with .patch, not .diff: #{patch_url}" end - if regex_match_group(patch_url_node, %r{.*gitlab.*/commit/[a-fA-F0-9]*\.diff}) - problem "GitLab patches should end with .patch, not .diff: #{patch_url}" + # Only .diff passes `--full-index` to `git diff` and there is no documented way + # to get .patch to behave the same for GitLab. + if regex_match_group(patch_url_node, %r{.*gitlab.*/commit/[a-fA-F0-9]*\.patch}) + problem "GitLab patches should end with .diff, not .patch: #{patch_url}" end gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)} diff --git a/Library/Homebrew/test/rubocops/patches_spec.rb b/Library/Homebrew/test/rubocops/patches_spec.rb index 6a7db5908f..1631d076df 100644 --- a/Library/Homebrew/test/rubocops/patches_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_spec.rb @@ -181,7 +181,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do "https://github.com/uber/h3/pull/362.patch?full_index=1", "https://gitlab.gnome.org/GNOME/gitg/-/merge_requests/142.diff", "https://github.com/michaeldv/pit/commit/f64978d.diff?full_index=1", - "https://gitlab.gnome.org/GNOME/msitools/commit/248450a.diff", + "https://gitlab.gnome.org/GNOME/msitools/commit/248450a.patch", ] patch_urls.each do |patch_url| source = <<~RUBY @@ -225,7 +225,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do EOS elsif patch_url.match?(%r{.*gitlab.*/commit/}) expect_offense_hash message: <<~EOS.chomp, severity: :convention, line: 5, column: 8, source: source - GitLab patches should end with .patch, not .diff: #{patch_url} + GitLab patches should end with .diff, not .patch: #{patch_url} EOS # rubocop:disable Layout/LineLength elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})