git-trac 0.0.20071106 → 0.0.20071107

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -70,7 +70,7 @@ spec = Gem::Specification.new do |s|
70
70
 
71
71
  s.files = [ "Rakefile", "README", "setup.rb" ]
72
72
  s.files = s.files + Dir.glob( "lib/**/*.rb" )
73
- s.files = s.files + Dir.glob( "test/**/*" ).reject { |item| item.include?( "\.svn" ) }
73
+ s.files = s.files + Dir.glob( "test/**/*" ).reject { |item| item[-1] == ?~ || item.include?( "\.svn" ) }
74
74
  end
75
75
 
76
76
  Rake::GemPackageTask.new(spec) do |p|
@@ -13,7 +13,7 @@ module Git
13
13
  def self.from_hpricot(ticket, html)
14
14
  collection = []
15
15
  return collection unless html
16
- (html.children).each do |element|
16
+ html.children.each do |element|
17
17
  if !element.elem?
18
18
  elsif element.name == "dd"
19
19
  str = ""
@@ -22,7 +22,7 @@ module Git
22
22
  elsif element.name = "dt"
23
23
  texts = []
24
24
  element.traverse_text {|x| texts << x.to_s}
25
- if texts.first =~ /\A(\w*)(\.\d+)?\.(diff|patch)\Z/
25
+ if texts.first =~ /\A([\w-]*)(\.\d+)?\.(diff|patch)\Z/
26
26
  time = Time.parse("#{texts[3]} +0000").utc
27
27
  collection << new(ticket, texts[0], texts[2], time)
28
28
  end
@@ -89,9 +89,22 @@ module Git
89
89
  ticket.repository
90
90
  end
91
91
 
92
- def apply!
92
+ def patch_with_root(root = nil)
93
+ if root && !root.empty? && p_value.zero?
94
+ patch = ""
95
+ body.each_line do |line|
96
+ line.sub!(/^([+-]{3} |Index: )([^\/].*)$/) { $1 + File.join(root, $2) }
97
+ patch << line
98
+ end
99
+ patch
100
+ else
101
+ body
102
+ end
103
+ end
104
+
105
+ def apply(options = {})
93
106
  repository.popen3("git-apply", "-p#{p_level}", :cached => true, :whitespace => "nowarn") do |inn,out,err|
94
- inn.puts body
107
+ inn.puts patch_with_root(options[:root])
95
108
  inn.close
96
109
  err.read.empty?
97
110
  end
@@ -11,18 +11,21 @@ module Git
11
11
  options, dir = dir, nil if dir.kind_of?(Hash)
12
12
  dir ||= ENV["GIT_DIR"]
13
13
  dir ||= Dir.getwd
14
- @git_dir = Dir.chdir(dir) do
15
- Open3.popen3("git","rev-parse","--git-dir") do |i,o,e|
14
+ Dir.chdir(dir) do
15
+ @git_dir = Open3.popen3("git","rev-parse","--git-dir") do |i,o,e|
16
16
  e.read.empty? ? o.read.chomp("\n") : nil
17
17
  end
18
+ raise Git::Trac::Error, "Not a git repository" unless @git_dir
19
+ @git_dir = File.join(".",@git_dir) if @git_dir[0] == ?~
20
+ @git_dir = File.expand_path(@git_dir)
18
21
  end
19
- raise Git::Trac::Error, "Not a git repository" unless @git_dir
20
- @git_dir = File.join(".",@git_dir) if @git_dir[0] == ?~
21
- @git_dir = File.expand_path(@git_dir)
22
- @options = (config("trac")||{}).merge(options)
23
- unless url
24
- # raise Git::Trac::Error, "missing trac url: consider `git config trac.url http://tracurl`"
25
- end
22
+ @options = options
23
+ reload
24
+ end
25
+
26
+ def reload #:nodoc:
27
+ @config = nil
28
+ @options = (config("trac")||{}).merge(@options)
26
29
  end
27
30
 
28
31
  def inspect
@@ -150,6 +153,9 @@ module Git
150
153
 
151
154
  def agent
152
155
  unless defined?(@agent)
156
+ unless url
157
+ raise Git::Trac::Error, "missing trac url: consider `git config trac.url http://tracurl`"
158
+ end
153
159
  require 'mechanize'
154
160
  @agent = WWW::Mechanize.new {|a| a.log = nil}
155
161
  url = "#{url()}/login"
@@ -206,7 +212,7 @@ module Git
206
212
  return number.to_i
207
213
  else
208
214
  hash = generated_commits
209
- exec("git-rev-list", "HEAD", :maxcount => 25) do |line|
215
+ exec("git-rev-list", "HEAD", :max_count => 25) do |line|
210
216
  number = hash[line.chomp] and return number
211
217
  end
212
218
  nil
@@ -142,7 +142,7 @@ directory.
142
142
  def add_options(opts)
143
143
  require_ticket_number
144
144
  opts.separator("Options:")
145
- opts.on("--filter PATTERN","only download patches matching PATTERN") do |pattern|
145
+ opts.on("--filter PATTERN","only download filenames matching PATTERN") do |pattern|
146
146
  options[:filter] = pattern
147
147
  end
148
148
  end
@@ -152,7 +152,7 @@ directory.
152
152
  @repository.ticket(number).attachments.each do |attach|
153
153
  next if options[:filter] && attach.filename !~ /#{options[:filter]}/
154
154
  File.open(attach.filename, "w") do |f|
155
- f.puts attach.body
155
+ f.puts attach.patch_with_root(options[:root])
156
156
  end
157
157
  end
158
158
  end
@@ -173,6 +173,9 @@ Show a crude ticket summary.
173
173
 
174
174
  def add_options(opts)
175
175
  require_ticket_number
176
+ opts.on("--root DIR","apply patches relative to DIR") do |dir|
177
+ options[:root] = dir
178
+ end
176
179
  end
177
180
 
178
181
  def run
@@ -210,11 +213,20 @@ potentially remove conflicted branches first.
210
213
 
211
214
  def add_options(opts)
212
215
  require_ticket_number
216
+ opts.on("--branch BRANCH","apply against branch BRANCH") do |b|
217
+ options[:branch] = b
218
+ end
219
+ opts.on("--filter PATTERN","only fetch filenames matching PATTERN") do |pattern|
220
+ options[:filter] = pattern
221
+ end
222
+ opts.on("--root DIR","apply patches relative to DIR") do |dir|
223
+ options[:root] = dir
224
+ end
213
225
  end
214
226
 
215
227
  def run
216
228
  number = get_ticket_number
217
- @repository.ticket(number).fetch do |attachment, branch|
229
+ @repository.ticket(number).fetch(options) do |attachment, branch|
218
230
  if branch
219
231
  puts "#{attachment.filename}: #{branch}"
220
232
  else
@@ -285,6 +297,9 @@ it against a production trac server.
285
297
  opts.on("--branch BRANCH", "git diff BRANCH (default trunk)") do |b|
286
298
  options[:branch] = b
287
299
  end
300
+ opts.on("--description TEXT", "use TEXT as description") do |text|
301
+ options[:description] = text
302
+ end
288
303
  end
289
304
 
290
305
  def run
@@ -97,9 +97,7 @@ module Git
97
97
  attachment = form.file_uploads.name("attachment").first
98
98
  attachment.file_name = filename
99
99
  attachment.file_data = body
100
- p form.fields
101
100
  submission = form.submit
102
- puts submission.instance_variable_get(:@body)
103
101
  submission.instance_variable_get(:@uri)
104
102
  end
105
103
 
@@ -139,10 +137,12 @@ module Git
139
137
  seen = {}
140
138
  repository.with_index("tracindex#{$$}") do
141
139
  FileUtils.mkdir_p(trac_dir)
142
- attachments.map do |attachment|
140
+ attachments.select do |attachment|
141
+ attachment.filename =~ /#{options[:filter]}/
142
+ end.map do |attachment|
143
143
  parent = repository.exec("git-rev-list","--max-count=1","--before=#{attachment.timestamp}",options[:branch] || 'trunk').chomp
144
144
  repository.exec("git-read-tree",parent)
145
- unless attachment.apply!
145
+ unless attachment.apply(options)
146
146
  yield attachment, false if block_given?
147
147
  next
148
148
  end
@@ -37,4 +37,13 @@ class ExecutionTest < Test::Unit::TestCase
37
37
  assert_nothing_raised { @repo.exec("git-diff","HEAD") }
38
38
  assert_raise(Git::Trac::ExecutionError) { @repo.exec("git-diff","TAIL") }
39
39
  end
40
+
41
+ def test_should_determine_url
42
+ @repo.exec("git-config","svn-remote.svn.url","http://dev.rubyonrails.org/svn/rails")
43
+ @repo.reload
44
+ assert_equal "http://dev.rubyonrails.org", @repo.url
45
+ @repo.exec("git-config","trac.url","http://foo/trac.cgi")
46
+ @repo.reload
47
+ assert_equal "http://foo/trac.cgi", @repo.url
48
+ end
40
49
  end
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.20071106
7
- date: 2007-11-06 00:00:00 -06:00
6
+ version: 0.0.20071107
7
+ date: 2007-11-07 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
@@ -39,7 +39,6 @@ files:
39
39
  - lib/git/trac/runner.rb
40
40
  - lib/git/trac/ticket.rb
41
41
  - test/execution_test.rb
42
- - test/execution_test.rb~
43
42
  test_files: []
44
43
 
45
44
  rdoc_options: []
@@ -1,40 +0,0 @@
1
- require 'fileutils'
2
- require 'tempfile'
3
- require 'test/unit'
4
-
5
- $: << File.join(File.dirname(File.dirname(__FILE__)),'lib')
6
- require 'git/trac'
7
-
8
- class ExecutionTest < Test::Unit::TestCase
9
-
10
- def create_empty_repository(directory = nil)
11
- if directory.nil?
12
- file = Tempfile.new("git-trac-test")
13
- directory = file.path
14
- file.unlink
15
- end
16
- at_exit { FileUtils.rm_rf(directory) }
17
- FileUtils.mkdir_p(directory)
18
- Dir.chdir(directory) do
19
- `git-init`
20
- end
21
- FileUtils.touch(File.join(directory,".gitignore"))
22
- repo = Git::Trac::Repository.new(directory)
23
- repo.exec("git-add",".gitignore")
24
- repo.exec("git-commit","-m","Initial revision")
25
- repo
26
- end
27
-
28
- def setup
29
- @repo = create_empty_repository
30
- end
31
-
32
- def test_rev_parse
33
- assert_match(/^[0-9a-f]{40}$/, @repo.rev_parse("HEAD"))
34
- end
35
-
36
- def test_stderr_should_raise
37
- assert_nothing_raised {@repo.exec("git-diff","HEAD")}
38
- assert_raise(Git::Trac::ExecutionError) {@repo.exec("git-diff","TAIL")}
39
- end
40
- end