Class: Git::Trac::Runner::Push
- Inherits:
-
Base
- Object
- Base
- Git::Trac::Runner::Push
show all
- Defined in:
- lib/git/trac/runner/push.rb
Overview
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
Class Method Details
.summary ⇒ Object
7
8
9
|
# File 'lib/git/trac/runner/push.rb', line 7
def self.summary
"Upload the current diff against upstream to a ticket"
end
|
Instance Method Details
#add_options(opts) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/git/trac/runner/push.rb', line 26
def add_options(opts)
opts.on("--against BRANCH", "git diff BRANCH...HEAD") do |b|
options[:upstream] = b
end
opts.on("--description TEXT", "use TEXT as description") do |text|
options[:description] = text
end
opts.on("--[no-]force", "do not prompt before uploading") do |force|
options[:force] = force
end
add_local_option(opts)
end
|
#banner_arguments ⇒ Object
11
12
13
|
# File 'lib/git/trac/runner/push.rb', line 11
def banner_arguments
"[options] <ticket>[/<filename>]"
end
|
#description ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/git/trac/runner/push.rb', line 15
def description
<<-EOF
Do a `git diff` and upload the result as an attachment to a ticket. The
potential patch will be shown in a pager and you will be given the opportunity
to cancel. If no filename is given, the name of the current branch plus
".patch" is used.
This command was formerly known as upload-patch.
EOF
end
|
#run ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/git/trac/runner/push.rb', line 39
def run
if @argv.size > 1
too_many_arguments
elsif @argv.empty?
number = repository.guess_current_ticket_number or
missing_argument "ticket"
else
number, options[:filename] = parse_attachment(@argv.shift)
end
fetch_unless_local
ticket = repository.ticket(number)
options[:upstream] ||= repository.guess_upstream || "refs/remotes/trunk"
options[:upstream] += "...HEAD" unless options[:upstream].include?(".")
if $stdin.tty? && !options[:force]
block = lambda do
repository.in_work_tree do
system("git","diff", options[:upstream])
end
description = "##{number} (#{ticket.csv["summary"]}"
cols = ENV["COLUMNS"].to_i
cols = 80 if cols.zero?
description.sub!(/^(.{#{cols-22}}).{4,}/,"\\1...")
print "#{description}) Proceed? [yN] "
$stdin.gets[0,1] == "y"
end
else
block = lambda { true }
end
if uri = ticket.upload_patch(options,&block)
puts uri
else
exit 1
end
end
|