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, args, description = nil) ⇒ PatchPuller

Returns a new instance of PatchPuller.


205
206
207
208
209
210
211
212
# File 'Library/Homebrew/dev-cmd/pull.rb', line 205

def initialize(url, args, 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
  @args = args
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url


203
204
205
# File 'Library/Homebrew/dev-cmd/pull.rb', line 203

def base_url
  @base_url
end

#patch_urlObject (readonly)

Returns the value of attribute patch_url


203
204
205
# File 'Library/Homebrew/dev-cmd/pull.rb', line 203

def patch_url
  @patch_url
end

#patchpathObject (readonly)

Returns the value of attribute patchpath


203
204
205
# File 'Library/Homebrew/dev-cmd/pull.rb', line 203

def patchpath
  @patchpath
end

Instance Method Details

#apply_patchObject


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'Library/Homebrew/dev-cmd/pull.rb', line 221

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.
  patch_args << if @args.ignore_whitespace? || @args.clean?
    "--whitespace=nowarn"
  else
    "--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 @args.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


214
215
216
217
218
219
# File 'Library/Homebrew/dev-cmd/pull.rb', line 214

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