Class: Git::Trac::Runner::Apply

Inherits:
Base
  • Object
show all
Defined in:
lib/git/trac/runner/apply.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#abort, #add_local_option, command, #command, #each_attachment, #each_ticket_or_attachment, #fetch_or_abort, #fetch_unless_local, #initialize, #missing_argument, #one_attachment, #options, #parse_attachment, #repository, #system, #too_many_arguments

Constructor Details

This class inherits a constructor from Git::Trac::Runner::Base

Class Method Details

.summaryObject



7
8
9
# File 'lib/git/trac/runner/apply.rb', line 7

def self.summary
  "Apply a patch directly to the work tree"
end

Instance Method Details

#add_options(opts) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/git/trac/runner/apply.rb', line 36

def add_options(opts)
  opts.on("--depth NUM","search NUM directories deep for a root") do |n|
    options[:depth] = n
  end
  opts.on("--root DIR","apply patches relative to DIR") do |dir|
    options[:root] = dir
  end
end


11
12
13
# File 'lib/git/trac/runner/apply.rb', line 11

def banner_arguments
  "[<attachment>]"
end

#descriptionObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/git/trac/runner/apply.rb', line 15

def description
  <<-EOF
Apply a patch directly to the work tree.  This command is a building block used
by other, more powerful commands and most users will never need to invoke it
directly.

The --depth option specifies how many directories deep to recursively attempt
to apply the patch in.  For a depth of 2, the patch will be attempted in the
repositority root, foo, foo/bar, but not foo/bar/baz.  It will also try
stripping off up to 2 directories off of the paths inside the patch, the same
as -p0, -p1, and -p2 with patch(1).  The option is ignored if the patch appears
to have been generated with git.  The default value is 0, but this can be
changed with the trac.depth configuration option.

If the patch fails to apply even after a depth search, and the patch contains
carriage returns, a second pass is made with those carriage returns stripped.

If no argument is given, the patch is read from stdin.
  EOF
end

#runObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/git/trac/runner/apply.rb', line 45

def run
  if @argv.empty?
    patch = Patch.new(repository,$stdin.read)
  else
    patch = one_attachment.patch
  end
  abort "no changes" if patch.body.empty?
  unless patch.apply(options)
    abort "patch failed to apply"
  end
end