git-trac 0.0.20071211 → 0.0.20080127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/git/trac/attachment.rb +6 -2
- data/lib/git/trac/runner.rb +56 -31
- data/lib/git/trac/ticket.rb +8 -5
- metadata +49 -42
data/lib/git/trac/attachment.rb
CHANGED
@@ -12,19 +12,23 @@ module Git
|
|
12
12
|
|
13
13
|
def self.from_hpricot(ticket, html)
|
14
14
|
collection = []
|
15
|
+
last = nil
|
15
16
|
return collection unless html
|
16
17
|
html.children.each do |element|
|
17
18
|
if !element.elem?
|
18
19
|
elsif element.name == "dd"
|
19
20
|
str = ""
|
20
21
|
element.traverse_text {|t| str << t.to_s}
|
21
|
-
|
22
|
+
last.description = str if last
|
22
23
|
elsif element.name = "dt"
|
23
24
|
texts = []
|
24
25
|
element.traverse_text {|x| texts << x.to_s}
|
25
26
|
if texts.first =~ /\A([\w-]*)(\.\d+)?\.(diff|patch)\Z/
|
26
27
|
time = Time.parse("#{texts[3]} +0000").utc
|
27
28
|
collection << new(ticket, texts[0], texts[2], time)
|
29
|
+
last = collection.last
|
30
|
+
else
|
31
|
+
last = nil
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
@@ -66,7 +70,7 @@ module Git
|
|
66
70
|
end
|
67
71
|
|
68
72
|
def tag_name
|
69
|
-
"trac/#{ticket.number}/#{filename
|
73
|
+
"trac/#{ticket.number}/#{filename}"
|
70
74
|
end
|
71
75
|
|
72
76
|
def tag_path
|
data/lib/git/trac/runner.rb
CHANGED
@@ -58,7 +58,7 @@ Available commands:
|
|
58
58
|
end
|
59
59
|
|
60
60
|
klass_name = command.capitalize.gsub(/-(.)/) { $1.upcase }
|
61
|
-
if self.class.const_defined?(klass_name)
|
61
|
+
if klass_name =~ /^[A-Z]\w*$/ && self.class.const_defined?(klass_name)
|
62
62
|
klass = self.class.const_get(klass_name)
|
63
63
|
if klass < Base
|
64
64
|
return klass.new(@argv, @repository)
|
@@ -75,7 +75,7 @@ Available commands:
|
|
75
75
|
|
76
76
|
def initialize(argv, repo)
|
77
77
|
@argv, @repository = argv, repo
|
78
|
-
@options =
|
78
|
+
@options = repo.config("trac")
|
79
79
|
@opts = OptionParser.new
|
80
80
|
@opts.banner = "Usage: git-trac #{command} #{banner_arguments}\n#{"\n" if description}#{description}"
|
81
81
|
@opts.separator("")
|
@@ -103,13 +103,24 @@ Available commands:
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
def each_ticket_argument
|
107
|
+
if @argv.empty?
|
108
|
+
yield get_ticket_number, nil
|
109
|
+
elsif @argv.any? {|a| a !~ /\b\d+\b/}
|
110
|
+
abort "ticket number required"
|
111
|
+
end
|
112
|
+
@argv.each do |arg|
|
113
|
+
match_data = arg.match(/\b(\d+)\b(?:\/([^?\/]+))?/)
|
114
|
+
yield Integer(match_data[1]), match_data[2]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
106
118
|
def require_ticket_number
|
107
119
|
@opts.separator("Ticket number is required unless it can be derived from the current branch.\n")
|
108
120
|
end
|
109
121
|
|
110
122
|
def abort(message)
|
111
123
|
$stderr.puts "Error: #{message}"
|
112
|
-
# $stderr.puts @opts
|
113
124
|
exit(1)
|
114
125
|
end
|
115
126
|
|
@@ -136,13 +147,13 @@ directory.
|
|
136
147
|
end
|
137
148
|
|
138
149
|
def banner_arguments
|
139
|
-
"[options] [ticket]"
|
150
|
+
"[options] [ticket[/filename]] ..."
|
140
151
|
end
|
141
152
|
|
142
153
|
def add_options(opts)
|
143
154
|
require_ticket_number
|
144
155
|
opts.separator("Options:")
|
145
|
-
opts.on("--filter PATTERN","only
|
156
|
+
opts.on("--filter PATTERN","only get matching filenames (deprecated)") do |pattern|
|
146
157
|
options[:filter] = pattern
|
147
158
|
end
|
148
159
|
opts.on("--root DIR","prefix patch paths with DIR") do |dir|
|
@@ -151,11 +162,17 @@ directory.
|
|
151
162
|
end
|
152
163
|
|
153
164
|
def run
|
154
|
-
number
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
165
|
+
each_ticket_argument do |number, filename|
|
166
|
+
filter = if filename
|
167
|
+
"\\A#{Regexp.escape(filename)}"
|
168
|
+
else
|
169
|
+
options[:filter]
|
170
|
+
end
|
171
|
+
@repository.ticket(number).attachments.each do |attach|
|
172
|
+
next if filter && attach.filename !~ /#{filter}/
|
173
|
+
File.open(attach.filename, "w") do |f|
|
174
|
+
f.puts attach.patch_with_root(options[:root])
|
175
|
+
end
|
159
176
|
end
|
160
177
|
end
|
161
178
|
end
|
@@ -193,7 +210,7 @@ Show a crude ticket summary.
|
|
193
210
|
class Fetch < Base #:nodoc:
|
194
211
|
|
195
212
|
def banner_arguments
|
196
|
-
"[ticket]"
|
213
|
+
"[options] [ticket[/filename]] ..."
|
197
214
|
end
|
198
215
|
|
199
216
|
def description
|
@@ -216,29 +233,37 @@ potentially remove conflicted branches first.
|
|
216
233
|
opts.on("--branch BRANCH","apply against branch BRANCH") do |b|
|
217
234
|
options[:branch] = b
|
218
235
|
end
|
219
|
-
opts.on("--filter PATTERN","only fetch filenames
|
236
|
+
opts.on("--filter PATTERN","only fetch matching filenames (deprecated)") do |pattern|
|
220
237
|
options[:filter] = pattern
|
221
238
|
end
|
222
239
|
opts.on("--root DIR","apply patches relative to DIR") do |dir|
|
223
240
|
options[:root] = dir
|
224
241
|
end
|
225
|
-
opts.on("--[no-]
|
226
|
-
options[:
|
242
|
+
opts.on("--[no-]local","don't run git-svn fetch") do |bool|
|
243
|
+
options[:local] = bool
|
244
|
+
end
|
245
|
+
opts.on("--[no-]update","run git-svn fetch (deprecated)") do |bool|
|
246
|
+
options[:local] = !bool
|
227
247
|
end
|
228
248
|
end
|
229
249
|
|
230
250
|
def run
|
231
|
-
|
232
|
-
if options[:update]
|
251
|
+
unless options[:local]
|
233
252
|
@repository.in_work_tree do
|
234
253
|
system("git-svn","fetch")
|
235
254
|
end
|
236
255
|
end
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
256
|
+
each_ticket_argument do |number, filename|
|
257
|
+
loop_opts = options.dup
|
258
|
+
if filename
|
259
|
+
loop_opts[:filter] = "\\A#{Regexp.escape(filename)}"
|
260
|
+
end
|
261
|
+
@repository.ticket(number).fetch(loop_opts) do |attachment, branch|
|
262
|
+
if branch
|
263
|
+
puts "#{attachment.filename}: #{branch}"
|
264
|
+
else
|
265
|
+
$stderr.puts "#{attachment.filename} FAILED"
|
266
|
+
end
|
242
267
|
end
|
243
268
|
end
|
244
269
|
end
|
@@ -248,7 +273,7 @@ potentially remove conflicted branches first.
|
|
248
273
|
class Cleanup < Base #:nodoc:
|
249
274
|
|
250
275
|
def banner_arguments
|
251
|
-
"[options] [ticket
|
276
|
+
"[options] [ticket[/filename]] ..."
|
252
277
|
end
|
253
278
|
|
254
279
|
def description
|
@@ -271,12 +296,9 @@ been closed, but you can also specify ticket numbers explicitly or use --all.
|
|
271
296
|
t.cleanup
|
272
297
|
end
|
273
298
|
elsif @argv.any?
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
end
|
278
|
-
rescue TypeError
|
279
|
-
abort "invalid ticket number"
|
299
|
+
each_ticket_argument do |number, filename|
|
300
|
+
filter = "\\A#{Regexp.escape(filename.to_s)}"
|
301
|
+
@repository.ticket(number).cleanup(:filter => filter)
|
280
302
|
end
|
281
303
|
else
|
282
304
|
@repository.working_tickets.each do |t|
|
@@ -311,14 +333,17 @@ it against a production trac server.
|
|
311
333
|
opts.on("--[no-]force", "do not prompt before uploading") do |force|
|
312
334
|
options[:force] = force
|
313
335
|
end
|
314
|
-
opts.on("--[no-]
|
315
|
-
options[:
|
336
|
+
opts.on("--[no-]local","don't run git-svn fetch") do |bool|
|
337
|
+
options[:local] = bool
|
338
|
+
end
|
339
|
+
opts.on("--[no-]update","run git-svn fetch (deprecated)") do |bool|
|
340
|
+
options[:local] = !bool
|
316
341
|
end
|
317
342
|
end
|
318
343
|
|
319
344
|
def run
|
320
345
|
number = get_ticket_number
|
321
|
-
|
346
|
+
unless options[:local]
|
322
347
|
@repository.in_work_tree do
|
323
348
|
system("git-svn","fetch")
|
324
349
|
end
|
data/lib/git/trac/ticket.rb
CHANGED
@@ -119,11 +119,13 @@ module Git
|
|
119
119
|
%w(new reopened).include?(c["status"])
|
120
120
|
end
|
121
121
|
|
122
|
-
def cleanup
|
122
|
+
def cleanup(options = {})
|
123
123
|
revs = []
|
124
124
|
repository.each_ref("refs/remotes/trac/#{number}") do |object, ref|
|
125
|
-
|
126
|
-
|
125
|
+
if File.basename(ref) =~ /#{options[:filter]}/
|
126
|
+
revs << object
|
127
|
+
repository.exec("git-update-ref","-d",ref,object)
|
128
|
+
end
|
127
129
|
end
|
128
130
|
unless revs.empty?
|
129
131
|
repository.each_ref("refs/heads") do |object, ref|
|
@@ -136,7 +138,7 @@ module Git
|
|
136
138
|
end
|
137
139
|
|
138
140
|
def fetch(options = {})
|
139
|
-
cleanup
|
141
|
+
cleanup(options)
|
140
142
|
seen = {}
|
141
143
|
repository.with_index("tracindex#{$$}") do
|
142
144
|
FileUtils.mkdir_p(trac_dir)
|
@@ -163,7 +165,8 @@ module Git
|
|
163
165
|
parents = " -p #{parent}"
|
164
166
|
end
|
165
167
|
commit = repository.popen3("git-commit-tree #{tree}#{parents}") do |i,o,e|
|
166
|
-
i.puts attachment.
|
168
|
+
i.puts "#{number}/#{attachment.filename}"
|
169
|
+
i.puts "\n#{attachment.description}" if attachment.description
|
167
170
|
i.close
|
168
171
|
o.read.chomp
|
169
172
|
end
|
metadata
CHANGED
@@ -1,33 +1,34 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: git-trac
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-12-11 00:00:00 -06:00
|
8
|
-
summary: Interact with trac from a git repository pulled from svn
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: ruby@tpope.info
|
12
|
-
homepage: http://git-trac.rubyforge.org
|
13
|
-
rubyforge_project: git-trac
|
14
|
-
description: git-trac takes the repetition out of working with trac and git-svn. Among other features is the ability to easily attach a patch to a ticket and to pull all patches from a ticket and turn them into git branches. Created for (but not limited to) work on the Ruby on Rails core.
|
15
|
-
autorequire:
|
16
|
-
default_executable: git-trac
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.0.20080127
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Tim Pope
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-27 00:00:00 -06:00
|
13
|
+
default_executable: git-trac
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mechanize
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.6.8
|
23
|
+
version:
|
24
|
+
description: git-trac takes the repetition out of working with trac and git-svn. Among other features is the ability to easily attach a patch to a ticket and to pull all patches from a ticket and turn them into git branches. Created for (but not limited to) work on the Ruby on Rails core.
|
25
|
+
email: ruby@tpope.info
|
26
|
+
executables:
|
27
|
+
- git-trac
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
31
32
|
files:
|
32
33
|
- Rakefile
|
33
34
|
- README
|
@@ -39,25 +40,31 @@ files:
|
|
39
40
|
- lib/git/trac/runner.rb
|
40
41
|
- lib/git/trac/ticket.rb
|
41
42
|
- test/execution_test.rb
|
42
|
-
|
43
|
-
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://git-trac.rubyforge.org
|
45
|
+
post_install_message:
|
44
46
|
rdoc_options: []
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
52
62
|
requirements: []
|
53
63
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 0.6.8
|
63
|
-
version:
|
64
|
+
rubyforge_project: git-trac
|
65
|
+
rubygems_version: 1.0.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: Interact with trac from a git repository pulled from svn
|
69
|
+
test_files: []
|
70
|
+
|