Class: Git::Trac::Runner::Fetch

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

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fetchable

#after_fetch

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



9
10
11
# File 'lib/git/trac/runner/fetch.rb', line 9

def self.summary
  "Create remote heads for ticket attachments"
end

Instance Method Details

#add_options(opts) ⇒ Object



34
35
36
37
38
39
# File 'lib/git/trac/runner/fetch.rb', line 34

def add_options(opts)
  super
  opts.on("--auto-branch","create branches for attachments") do
    options[:auto_branch] = true
  end
end


13
14
15
# File 'lib/git/trac/runner/fetch.rb', line 13

def banner_arguments
  "<attachment>..."
end

#descriptionObject



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

def description
  <<-EOF
For each attachment argument, find the revision that most recently preceeds the
the time of upload, apply the patch to it, create a new commit, and add a
remote head of the form refs/remotes/trac/ticketnumber/filename.ext.

If the --auto-branch option is given, a unique branch is created for each
unique base name (filename without extension) of each attachment.  If multiple
attachments have the same base name, the newest is used.  Existing branches
will not be overridden, but there is an implied `git cleanup` that runs
beforehand which could potentially remove conflicting branches first.
Automatic branch creation used to be the default, but now the behavior is
deprecated and may be removed in a future release.  Consider using `git-trac
checkout` instead.
  EOF
end

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/git/trac/runner/fetch.rb', line 41

def run
  fetch_unless_local
  each_ticket_or_attachment do |ticket|
    seen = {}
    ticket.fetch(options) do |attachment, dir, commit|
      if dir == "." || dir == true
        puts "#{attachment.tag_name}"
      elsif dir
        puts "#{attachment.tag_name} (#{dir})"
      else
        $stderr.puts "#{attachment.tag_name} FAILED"
      end
      seen[attachment.name] = commit if commit
    end
    if options[:auto_branch]
      seen.each do |k,v|
        if !File.exists?(path = "#{repository.git_dir}/refs/heads/#{k}")
          File.open(path, "w") {|f| f.puts v}
        end
      end
    end
  end
end