square-circle-triangle-grit 1.1.2 → 1.1.3
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/LICENSE +22 -0
- data/VERSION.yml +1 -1
- data/examples/ex_add_commit.rb +13 -0
- data/examples/ex_index.rb +14 -0
- data/lib/grit/repo.rb +12 -14
- data/test/bench/benchmarks.rb +126 -0
- data/test/helper.rb +18 -0
- data/test/profile.rb +21 -0
- data/test/suite.rb +6 -0
- data/test/test_actor.rb +35 -0
- data/test/test_blame.rb +32 -0
- data/test/test_blame_tree.rb +33 -0
- data/test/test_blob.rb +83 -0
- data/test/test_commit.rb +207 -0
- data/test/test_commit_stats.rb +33 -0
- data/test/test_commit_write.rb +20 -0
- data/test/test_config.rb +58 -0
- data/test/test_diff.rb +18 -0
- data/test/test_file_index.rb +56 -0
- data/test/test_git.rb +84 -0
- data/test/test_grit.rb +32 -0
- data/test/test_head.rb +47 -0
- data/test/test_index_status.rb +40 -0
- data/test/test_merge.rb +17 -0
- data/test/test_raw.rb +16 -0
- data/test/test_real.rb +19 -0
- data/test/test_reality.rb +17 -0
- data/test/test_remote.rb +14 -0
- data/test/test_repo.rb +347 -0
- data/test/test_rubygit.rb +188 -0
- data/test/test_rubygit_alt.rb +40 -0
- data/test/test_rubygit_index.rb +76 -0
- data/test/test_rubygit_iv2.rb +28 -0
- data/test/test_submodule.rb +69 -0
- data/test/test_tag.rb +67 -0
- data/test/test_tree.rb +101 -0
- metadata +44 -14
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2007-2009 Tom Preston-Werner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION.yml
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require '../lib/grit'
|
2
|
+
|
3
|
+
count = 1
|
4
|
+
Dir.chdir("/Users/schacon/projects/atest") do
|
5
|
+
r = Grit::Repo.new('.')
|
6
|
+
while(count < 10) do
|
7
|
+
fname = Time.now.to_i.to_s + count.to_s
|
8
|
+
File.open(fname, 'w') { |f| f.write('hellor ' + fname) }
|
9
|
+
r.add(fname)
|
10
|
+
count += 1
|
11
|
+
end
|
12
|
+
r.commit_index('my commit')
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require '../lib/grit'
|
2
|
+
|
3
|
+
count = 1
|
4
|
+
Dir.chdir("/Users/schacon/projects/atest") do
|
5
|
+
r = Grit::Repo.new('.')
|
6
|
+
i = r.index
|
7
|
+
while(count < 10) do
|
8
|
+
fname = Time.now.to_i.to_s + count.to_s
|
9
|
+
i.add(fname, 'hello ' + fname)
|
10
|
+
count += 1
|
11
|
+
end
|
12
|
+
puts i.commit('my commit')
|
13
|
+
puts i.inspect
|
14
|
+
end
|
data/lib/grit/repo.rb
CHANGED
@@ -1,19 +1,11 @@
|
|
1
1
|
module Grit
|
2
2
|
|
3
|
-
class RemoteError < StandardError
|
4
|
-
end
|
5
|
-
|
6
|
-
class
|
7
|
-
end
|
8
|
-
|
9
|
-
class BranchNonexistentError < StandardError
|
10
|
-
end
|
11
|
-
|
12
|
-
class RemoteBranchExistsError < StandardError
|
13
|
-
end
|
14
|
-
|
15
|
-
class RemoteUninitializedError < StandardError
|
16
|
-
end
|
3
|
+
class RemoteError < StandardError; end
|
4
|
+
class RemoteNonexistentError < RemoteError; end
|
5
|
+
class BranchNonexistentError < RemoteError; end
|
6
|
+
class RemoteBranchExistsError < RemoteError; end
|
7
|
+
class RemoteUninitializedError < RemoteError; end
|
8
|
+
class ConflictError < RemoteError; end
|
17
9
|
|
18
10
|
class Repo
|
19
11
|
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
|
@@ -541,12 +533,18 @@ module Grit
|
|
541
533
|
raise RemoteNonexistentError, last_error
|
542
534
|
elsif last_error =~ /ssh: Could not resolve hostname .*: nodename nor servname provided, or not known/
|
543
535
|
raise RemoteNonexistentError, last_error
|
536
|
+
elsif last_error =~ /does not appear to be a git repository/
|
537
|
+
raise RemoteNonexistentError, last_error
|
544
538
|
elsif last_error =~ /fatal: Couldn't find remote ref .*/
|
545
539
|
raise BranchNonexistentError, last_error
|
546
540
|
elsif last_error =~ /error: src refspec .* does not match any./
|
547
541
|
raise BranchNonexistentError, last_error
|
548
542
|
elsif last_error =~ /unknown revision or path not in the working tree/
|
549
543
|
raise RemoteUninitializedError, last_error
|
544
|
+
elsif last_error =~ /error: Entry '.*' would be overwritten by merge. Cannot merge./
|
545
|
+
raise ConflictError, last_error
|
546
|
+
elsif last_error =~ /Entry '.*' not uptodate. Cannot merge./
|
547
|
+
raise ConflictError, last_error
|
550
548
|
elsif last_error =~ /(error|fatal)/
|
551
549
|
raise RemoteError, last_error
|
552
550
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ruby-prof'
|
5
|
+
require 'memcache'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
gem 'grit', '=0.7.0'
|
9
|
+
#require '../../lib/grit'
|
10
|
+
|
11
|
+
def main
|
12
|
+
@wbare = File.expand_path(File.join('../../', 'test', 'dot_git'))
|
13
|
+
|
14
|
+
in_temp_dir do
|
15
|
+
#result = RubyProf.profile do
|
16
|
+
|
17
|
+
git = Grit::Repo.new('.')
|
18
|
+
puts Grit::VERSION
|
19
|
+
#Grit::GitRuby.cache_client = MemCache.new 'localhost:11211', :namespace => 'grit'
|
20
|
+
#Grit.debug = true
|
21
|
+
|
22
|
+
#pp Grit::GitRuby.cache_client.stats
|
23
|
+
|
24
|
+
commit1 = '5e3ee1198672257164ce3fe31dea3e40848e68d5'
|
25
|
+
commit2 = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
|
26
|
+
|
27
|
+
Benchmark.bm(8) do |x|
|
28
|
+
|
29
|
+
run_code(x, 'packobj') do
|
30
|
+
@commit = git.commit('5e3ee1198672257164ce3fe31dea3e40848e68d5')
|
31
|
+
@tree = git.tree('cd7422af5a2e0fff3e94d6fb1a8fff03b2841881')
|
32
|
+
@blob = git.blob('4232d073306f01cf0b895864e5a5cfad7dd76fce')
|
33
|
+
@commit.parents[0].parents[0].parents[0]
|
34
|
+
end
|
35
|
+
|
36
|
+
run_code(x, 'commits 1') do
|
37
|
+
git.commits.size
|
38
|
+
end
|
39
|
+
|
40
|
+
run_code(x, 'commits 2') do
|
41
|
+
log = git.commits('master', 15)
|
42
|
+
log.size
|
43
|
+
log.size
|
44
|
+
log.first
|
45
|
+
git.commits('testing').map { |c| c.message }
|
46
|
+
end
|
47
|
+
|
48
|
+
run_code(x, 'big revlist') do
|
49
|
+
c = git.commits('master', 200)
|
50
|
+
end
|
51
|
+
|
52
|
+
run_code(x, 'log') do
|
53
|
+
log = git.log('master')
|
54
|
+
log.size
|
55
|
+
log.size
|
56
|
+
log.first
|
57
|
+
end
|
58
|
+
|
59
|
+
run_code(x, 'diff') do
|
60
|
+
c = git.diff(commit1, commit2)
|
61
|
+
end
|
62
|
+
|
63
|
+
run_code(x, 'commit-diff') do
|
64
|
+
c = git.commit_diff(commit1)
|
65
|
+
end
|
66
|
+
|
67
|
+
run_code(x, 'heads') do
|
68
|
+
c = git.heads.collect { |b| b.commit.id }
|
69
|
+
end
|
70
|
+
|
71
|
+
# run_code(x, 'config', 100) do
|
72
|
+
# c = git.config['user.name']
|
73
|
+
# c = git.config['user.email']
|
74
|
+
# end
|
75
|
+
|
76
|
+
#run_code(x, 'commit count') do
|
77
|
+
# c = git.commit_count('testing')
|
78
|
+
#end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
#end
|
83
|
+
|
84
|
+
#printer = RubyProf::FlatPrinter.new(result)
|
85
|
+
#printer.print(STDOUT, 0)
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def run_code(x, name, times = 30)
|
94
|
+
x.report(name.ljust(12)) do
|
95
|
+
for i in 1..times do
|
96
|
+
yield i
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
#end
|
101
|
+
|
102
|
+
# Print a graph profile to text
|
103
|
+
end
|
104
|
+
|
105
|
+
def new_file(name, contents)
|
106
|
+
File.open(name, 'w') do |f|
|
107
|
+
f.puts contents
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def in_temp_dir(remove_after = true)
|
113
|
+
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
114
|
+
tmp_path = File.join("/tmp/", filename)
|
115
|
+
FileUtils.mkdir(tmp_path)
|
116
|
+
Dir.chdir tmp_path do
|
117
|
+
FileUtils.cp_r(@wbare, File.join(tmp_path, '.git'))
|
118
|
+
yield tmp_path
|
119
|
+
end
|
120
|
+
puts tmp_path
|
121
|
+
#FileUtils.rm_r(tmp_path) if remove_after
|
122
|
+
end
|
123
|
+
|
124
|
+
main()
|
125
|
+
|
126
|
+
##pp Grit::GitRuby.cache_client.stats
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib grit])
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
gem "mocha", ">=0"
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
GRIT_REPO = File.join(File.dirname(__FILE__), *%w[..])
|
9
|
+
|
10
|
+
include Grit
|
11
|
+
|
12
|
+
def fixture(name)
|
13
|
+
File.read(File.join(File.dirname(__FILE__), 'fixtures', name))
|
14
|
+
end
|
15
|
+
|
16
|
+
def absolute_project_path
|
17
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
18
|
+
end
|
data/test/profile.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib grit])
|
2
|
+
include Grit
|
3
|
+
|
4
|
+
def recurse(tree, indent = "")
|
5
|
+
tree.contents.each do |c|
|
6
|
+
case c
|
7
|
+
when Tree
|
8
|
+
# puts "#{indent}#{c.name} (#{c.id})"
|
9
|
+
recurse(c, indent + " ")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
10.times do
|
15
|
+
r = Repo.new("/Users/schacon/projects/ambition")
|
16
|
+
t = r.tree
|
17
|
+
|
18
|
+
recurse(t)
|
19
|
+
end
|
20
|
+
|
21
|
+
#500.times { puts `git --git-dir /Users/schacon/projects/ambition/.git ls-tree master` }
|
data/test/suite.rb
ADDED
data/test/test_actor.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestActor < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
# from_string
|
9
|
+
|
10
|
+
def test_from_string_should_separate_name_and_email
|
11
|
+
a = Actor.from_string("Tom Werner <tom@example.com>")
|
12
|
+
assert_equal "Tom Werner", a.name
|
13
|
+
assert_equal "tom@example.com", a.email
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_from_string_should_handle_just_name
|
17
|
+
a = Actor.from_string("Tom Werner")
|
18
|
+
assert_equal "Tom Werner", a.name
|
19
|
+
assert_equal nil, a.email
|
20
|
+
end
|
21
|
+
|
22
|
+
# inspect
|
23
|
+
|
24
|
+
def test_inspect
|
25
|
+
a = Actor.from_string("Tom Werner <tom@example.com>")
|
26
|
+
assert_equal %Q{#<Grit::Actor "Tom Werner <tom@example.com>">}, a.inspect
|
27
|
+
end
|
28
|
+
|
29
|
+
# to_s
|
30
|
+
|
31
|
+
def test_to_s_should_alias_name
|
32
|
+
a = Actor.from_string("Tom Werner <tom@example.com>")
|
33
|
+
assert_equal a.name, a.to_s
|
34
|
+
end
|
35
|
+
end
|
data/test/test_blame.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
class TestBlame < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_simple_blame
|
11
|
+
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
12
|
+
blame = @r.blame('History.txt', commit)
|
13
|
+
assert_equal 5, blame.lines.size
|
14
|
+
line = blame.lines[2]
|
15
|
+
assert_equal '* 1 major enhancement', line.line
|
16
|
+
assert_equal 3, line.lineno
|
17
|
+
assert_equal 3, line.oldlineno
|
18
|
+
assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', line.commit.id
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_depth_blame
|
22
|
+
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
23
|
+
blame = @r.blame('lib/grit.rb', commit)
|
24
|
+
assert_equal 37, blame.lines.size
|
25
|
+
line = blame.lines[24]
|
26
|
+
assert_equal "require 'grit/diff'", line.line
|
27
|
+
assert_equal 25, line.lineno
|
28
|
+
assert_equal 16, line.oldlineno
|
29
|
+
assert_equal '46291865ba0f6e0c9818b11be799fe2db6964d56', line.commit.id
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
class TestBlameTree < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@git = Git.new(File.join(File.dirname(__FILE__), *%w[dot_git]))
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_blame_tree
|
11
|
+
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
12
|
+
tree = @git.blame_tree(commit)
|
13
|
+
last_commit_sha = tree['History.txt']
|
14
|
+
assert_equal last_commit_sha, '7bcc0ee821cdd133d8a53e8e7173a334fef448aa'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_blame_tree_path
|
18
|
+
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
19
|
+
tree = @git.blame_tree(commit, 'lib')
|
20
|
+
last_commit_sha = tree['lib/grit.rb']
|
21
|
+
assert_equal last_commit_sha, '5a0943123f6872e75a9b1dd0b6519dd42a186fda'
|
22
|
+
last_commit_sha = tree['lib/grit']
|
23
|
+
assert_equal last_commit_sha, '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_blame_tree_multi_path
|
27
|
+
commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
|
28
|
+
tree = @git.blame_tree(commit, 'lib/grit')
|
29
|
+
last_commit_sha = tree['lib/grit/diff.rb']
|
30
|
+
assert_equal last_commit_sha, '22825175e37f22c9418d756ca69b574d75602994'
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/test/test_blob.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestBlob < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@r = Repo.new(GRIT_REPO)
|
6
|
+
@b = Blob.allocate
|
7
|
+
end
|
8
|
+
|
9
|
+
# blob
|
10
|
+
def test_nosuch_blob
|
11
|
+
t = @r.blob('blahblah')
|
12
|
+
assert t.is_a?(Blob)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_data_should_return_blob_contents
|
16
|
+
Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
|
17
|
+
blob = Blob.create(@r, :id => 'abc')
|
18
|
+
assert_equal "Hello world", blob.data
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_data_should_cache
|
22
|
+
Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob')).times(1)
|
23
|
+
blob = Blob.create(@r, :id => 'abc')
|
24
|
+
blob.data
|
25
|
+
blob.data
|
26
|
+
end
|
27
|
+
|
28
|
+
# size
|
29
|
+
|
30
|
+
def test_size_should_return_file_size
|
31
|
+
Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob_size'))
|
32
|
+
blob = Blob.create(@r, :id => 'abc')
|
33
|
+
assert_equal 11, blob.size
|
34
|
+
end
|
35
|
+
|
36
|
+
# data
|
37
|
+
|
38
|
+
# mime_type
|
39
|
+
|
40
|
+
def test_mime_type_should_return_mime_type_for_known_types
|
41
|
+
blob = Blob.create(@r, :id => 'abc', :name => 'foo.png')
|
42
|
+
assert_equal "image/png", blob.mime_type
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_mime_type_should_return_text_plain_for_unknown_types
|
46
|
+
blob = Blob.create(@r, :id => 'abc')
|
47
|
+
assert_equal "text/plain", blob.mime_type
|
48
|
+
end
|
49
|
+
|
50
|
+
# blame
|
51
|
+
|
52
|
+
def test_blame
|
53
|
+
Git.any_instance.expects(:blame).returns(fixture('blame'))
|
54
|
+
b = Blob.blame(@r, 'master', 'lib/grit.rb')
|
55
|
+
assert_equal 13, b.size
|
56
|
+
assert_equal 25, b.inject(0) { |acc, x| acc + x.last.size }
|
57
|
+
assert_equal b[0].first.object_id, b[9].first.object_id
|
58
|
+
c = b.first.first
|
59
|
+
c.expects(:__bake__).times(0)
|
60
|
+
assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id
|
61
|
+
assert_equal 'Tom Preston-Werner', c.author.name
|
62
|
+
assert_equal 'tom@mojombo.com', c.author.email
|
63
|
+
assert_equal Time.at(1191997100), c.authored_date
|
64
|
+
assert_equal 'Tom Preston-Werner', c.committer.name
|
65
|
+
assert_equal 'tom@mojombo.com', c.committer.email
|
66
|
+
assert_equal Time.at(1191997100), c.committed_date
|
67
|
+
assert_equal 'initial grit setup', c.message
|
68
|
+
# c.expects(:__bake__).times(1)
|
69
|
+
# assert_equal Tree, c.tree.class
|
70
|
+
end
|
71
|
+
|
72
|
+
# inspect
|
73
|
+
|
74
|
+
def test_inspect
|
75
|
+
@b = Blob.create(@r, :id => 'abc')
|
76
|
+
assert_equal %Q{#<Grit::Blob "abc">}, @b.inspect
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_basename
|
80
|
+
@b = Blob.create(@r, :name => 'foo/bar.rb')
|
81
|
+
assert_equal "bar.rb", @b.basename
|
82
|
+
end
|
83
|
+
end
|