git-trac 0.0.20071107 → 0.0.20071211

Sign up to get free protection for your applications and to get access to all the features.
@@ -89,11 +89,20 @@ module Git
89
89
  ticket.repository
90
90
  end
91
91
 
92
+ # Rewrite filenames in a patch to be relative to +root+. For each .. at
93
+ # the end of +root+, a path is stripped off the original filename. The
94
+ # rewritten patch is returned as a string.
92
95
  def patch_with_root(root = nil)
93
- if root && !root.empty? && p_value.zero?
96
+ if root && !root.empty? && p_level.zero?
94
97
  patch = ""
95
98
  body.each_line do |line|
96
- line.sub!(/^([+-]{3} |Index: )([^\/].*)$/) { $1 + File.join(root, $2) }
99
+ line.sub!(/^([+-]{3} |Index: )([^\/].*)$/) do
100
+ head = $1
101
+ original = File.join(root, $2)
102
+ while original.sub!(%r{(.*/|^)\.\./[^/]*/},'\\1')
103
+ end
104
+ head + original
105
+ end
97
106
  patch << line
98
107
  end
99
108
  patch
@@ -145,6 +145,9 @@ directory.
145
145
  opts.on("--filter PATTERN","only download filenames matching PATTERN") do |pattern|
146
146
  options[:filter] = pattern
147
147
  end
148
+ opts.on("--root DIR","prefix patch paths with DIR") do |dir|
149
+ options[:root] = dir
150
+ end
148
151
  end
149
152
 
150
153
  def run
@@ -173,9 +176,6 @@ Show a crude ticket summary.
173
176
 
174
177
  def add_options(opts)
175
178
  require_ticket_number
176
- opts.on("--root DIR","apply patches relative to DIR") do |dir|
177
- options[:root] = dir
178
- end
179
179
  end
180
180
 
181
181
  def run
@@ -222,10 +222,18 @@ potentially remove conflicted branches first.
222
222
  opts.on("--root DIR","apply patches relative to DIR") do |dir|
223
223
  options[:root] = dir
224
224
  end
225
+ opts.on("--[no-]update","automatically run git-svn fetch") do |bool|
226
+ options[:update] = bool
227
+ end
225
228
  end
226
229
 
227
230
  def run
228
231
  number = get_ticket_number
232
+ if options[:update]
233
+ @repository.in_work_tree do
234
+ system("git-svn","fetch")
235
+ end
236
+ end
229
237
  @repository.ticket(number).fetch(options) do |attachment, branch|
230
238
  if branch
231
239
  puts "#{attachment.filename}: #{branch}"
@@ -294,17 +302,44 @@ it against a production trac server.
294
302
 
295
303
  def add_options(opts)
296
304
  require_ticket_number
297
- opts.on("--branch BRANCH", "git diff BRANCH (default trunk)") do |b|
305
+ opts.on("--branch BRANCH", "git diff BRANCH (default trunk...HEAD)") do |b|
298
306
  options[:branch] = b
299
307
  end
300
308
  opts.on("--description TEXT", "use TEXT as description") do |text|
301
309
  options[:description] = text
302
310
  end
311
+ opts.on("--[no-]force", "do not prompt before uploading") do |force|
312
+ options[:force] = force
313
+ end
314
+ opts.on("--[no-]update","automatically run git-svn fetch") do |bool|
315
+ options[:update] = bool
316
+ end
303
317
  end
304
318
 
305
319
  def run
306
320
  number = get_ticket_number
307
- if uri = @repository.ticket(number).upload_patch(options)
321
+ if options[:update]
322
+ @repository.in_work_tree do
323
+ system("git-svn","fetch")
324
+ end
325
+ end
326
+ ticket = @repository.ticket(number)
327
+ if $stdin.tty? && !options[:force]
328
+ block = lambda do
329
+ @repository.in_work_tree do
330
+ system("git-diff", options[:branch] || "trunk...HEAD")
331
+ end
332
+ description = "##{number} (#{ticket.csv["summary"]}"
333
+ cols = ENV["COLUMNS"].to_i
334
+ cols = 80 if cols.zero?
335
+ description.sub!(/^(.{#{cols-22}}).{4,}/,"\\1...")
336
+ print "#{description}) Proceed? [yN] "
337
+ $stdin.gets[0,1] == "y"
338
+ end
339
+ else
340
+ block = lambda { true }
341
+ end
342
+ if uri = ticket.upload_patch(options,&block)
308
343
  puts uri
309
344
  else
310
345
  exit 1
@@ -104,10 +104,13 @@ module Git
104
104
  def upload_patch(options = {})
105
105
  filename = options[:filename] || "#{File.basename(repository.current_checkout)}.patch"
106
106
  # diff = repository.exec("git-diff","#{options[:branch] || "trunk"}...HEAD")
107
- diff = repository.exec("git-diff", options[:branch] || "trunk")
107
+ diff = repository.exec("git-diff", options[:branch] || "trunk...HEAD")
108
108
  return false if diff.empty?
109
109
  # Don't upload the exact same patch that was pulled down
110
110
  return false if repository.generated_commits[repository.rev_parse("HEAD")] == number
111
+ if block_given? # confirmation block
112
+ return false if yield(diff) == false
113
+ end
111
114
  upload_attachment(options[:description], filename, diff)
112
115
  end
113
116
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: git-trac
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.20071107
7
- date: 2007-11-07 00:00:00 -06:00
6
+ version: 0.0.20071211
7
+ date: 2007-12-11 00:00:00 -06:00
8
8
  summary: Interact with trac from a git repository pulled from svn
9
9
  require_paths:
10
10
  - lib