Class: Homebrew::PatchPuller

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/dev-cmd/pull.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, description = nil) ⇒ PatchPuller

Returns a new instance of PatchPuller



313
314
315
316
317
318
319
# File 'Library/Homebrew/dev-cmd/pull.rb', line 313

def initialize(url, description = nil)
  @base_url = url
  # GitHub provides commits/pull-requests raw patches using this URL.
  @patch_url = url + ".patch"
  @patchpath = HOMEBREW_CACHE + File.basename(patch_url)
  @description = description
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url



309
310
311
# File 'Library/Homebrew/dev-cmd/pull.rb', line 309

def base_url
  @base_url
end

#patch_urlObject (readonly)

Returns the value of attribute patch_url



310
311
312
# File 'Library/Homebrew/dev-cmd/pull.rb', line 310

def patch_url
  @patch_url
end

#patchpathObject (readonly)

Returns the value of attribute patchpath



311
312
313
# File 'Library/Homebrew/dev-cmd/pull.rb', line 311

def patchpath
  @patchpath
end

Instance Method Details

#apply_patchObject



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'Library/Homebrew/dev-cmd/pull.rb', line 333

def apply_patch
  # Applies a patch previously downloaded with fetch_patch()
  # Deletes the patch file as a side effect, regardless of success

  ohai "Applying patch"
  patch_args = []
  # Normally we don't want whitespace errors, but squashing them can break
  # patches so an option is provided to skip this step.
  if ARGV.include?("--ignore-whitespace") || ARGV.include?("--clean")
    patch_args << "--whitespace=nowarn"
  else
    patch_args << "--whitespace=fix"
  end

  # Fall back to three-way merge if patch does not apply cleanly
  patch_args << "-3"
  patch_args << patchpath

  begin
    safe_system "git", "am", *patch_args
  rescue ErrorDuringExecution
    if ARGV.include? "--resolve"
      odie "Patch failed to apply: try to resolve it."
    else
      system "git", "am", "--abort"
      odie "Patch failed to apply: aborted."
    end
  ensure
    patchpath.unlink
  end
end

#fetch_patchObject



326
327
328
329
330
331
# File 'Library/Homebrew/dev-cmd/pull.rb', line 326

def fetch_patch
  extra_msg = @description ? "(#{@description})" : nil
  ohai "Fetching patch #{extra_msg}"
  puts "Patch: #{patch_url}"
  curl_download patch_url, to: patchpath
end

#pull_patchObject



321
322
323
324
# File 'Library/Homebrew/dev-cmd/pull.rb', line 321

def pull_patch
  fetch_patch
  apply_patch
end