git 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of git might be problematic. Click here for more details.

data/README CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  Library for using Git in Ruby.
4
4
 
5
+ = Homepage
6
+
7
+ The Ruby/Git homepage is currently at :
8
+
9
+ http://jointheconversation.org/rubygit
10
+
11
+ Git public hosting of the project source code is at:
12
+
13
+ http://repo.or.cz/w/rubygit.git
5
14
 
6
15
  = Roadmap
7
16
 
@@ -46,6 +55,23 @@ Here are the operations that need read permission only.
46
55
  g.gblob(treeish)
47
56
  g.gcommit(treeish)
48
57
 
58
+
59
+ commit = g.gcommit('1cc8667014381')
60
+ commit.gtree
61
+ commit.parent.sha
62
+ commit.parents.size
63
+ commit.author.name
64
+ commit.author.email
65
+ commit.author.date.strftime("%m-%d-%y")
66
+ commit.committer.name
67
+ commit.date.strftime("%m-%d-%y")
68
+ commit.message
69
+
70
+ tree = g.gtree("HEAD^{tree}")
71
+ tree.blobs
72
+ tree.subtrees
73
+ tree.children # blobs and subtrees
74
+
49
75
  g.revparse('v2.5:Makefile')
50
76
 
51
77
  g.branches # returns Git::Branch objects
@@ -149,4 +175,4 @@ And here are the operations that will need to write to your git repository.
149
175
  g.repack
150
176
 
151
177
  g.push
152
- g.push(g.remote('name'))
178
+ g.push(g.remote('name'))
@@ -167,6 +167,19 @@ Class <a href="Git/WorkingDirectory.html" class="link">Git::WorkingDirectory</a>
167
167
 
168
168
  </div>
169
169
 
170
+ <div id="constants-list">
171
+ <h3 class="section-bar">Constants</h3>
172
+
173
+ <div class="name-list">
174
+ <table summary="Constants">
175
+ <tr class="top-aligned-row context-row">
176
+ <td class="context-item-name">VERSION</td>
177
+ <td>=</td>
178
+ <td class="context-item-value">'1.0.1'</td>
179
+ </tr>
180
+ </table>
181
+ </div>
182
+ </div>
170
183
 
171
184
 
172
185
 
@@ -191,7 +204,7 @@ Class <a href="Git/WorkingDirectory.html" class="link">Git::WorkingDirectory</a>
191
204
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
192
205
  <div class="method-source-code" id="M000001-source">
193
206
  <pre>
194
- <span class="ruby-comment cmt"># File lib/git.rb, line 34</span>
207
+ <span class="ruby-comment cmt"># File lib/git.rb, line 36</span>
195
208
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">bare</span>(<span class="ruby-identifier">git_dir</span>)
196
209
  <span class="ruby-constant">Base</span>.<span class="ruby-identifier">bare</span>(<span class="ruby-identifier">git_dir</span>)
197
210
  <span class="ruby-keyword kw">end</span>
@@ -214,7 +227,7 @@ Class <a href="Git/WorkingDirectory.html" class="link">Git::WorkingDirectory</a>
214
227
  onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
215
228
  <div class="method-source-code" id="M000004-source">
216
229
  <pre>
217
- <span class="ruby-comment cmt"># File lib/git.rb, line 46</span>
230
+ <span class="ruby-comment cmt"># File lib/git.rb, line 48</span>
218
231
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">clone</span>(<span class="ruby-identifier">repository</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
219
232
  <span class="ruby-constant">Base</span>.<span class="ruby-identifier">clone</span>(<span class="ruby-identifier">repository</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
220
233
  <span class="ruby-keyword kw">end</span>
@@ -237,7 +250,7 @@ Class <a href="Git/WorkingDirectory.html" class="link">Git::WorkingDirectory</a>
237
250
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
238
251
  <div class="method-source-code" id="M000003-source">
239
252
  <pre>
240
- <span class="ruby-comment cmt"># File lib/git.rb, line 42</span>
253
+ <span class="ruby-comment cmt"># File lib/git.rb, line 44</span>
241
254
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">working_dir</span> = <span class="ruby-value str">'.'</span>, <span class="ruby-identifier">options</span> = {})
242
255
  <span class="ruby-constant">Base</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">working_dir</span>, <span class="ruby-identifier">options</span>)
243
256
  <span class="ruby-keyword kw">end</span>
@@ -260,7 +273,7 @@ Class <a href="Git/WorkingDirectory.html" class="link">Git::WorkingDirectory</a>
260
273
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
261
274
  <div class="method-source-code" id="M000002-source">
262
275
  <pre>
263
- <span class="ruby-comment cmt"># File lib/git.rb, line 38</span>
276
+ <span class="ruby-comment cmt"># File lib/git.rb, line 40</span>
264
277
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">working_dir</span>, <span class="ruby-identifier">options</span> = {})
265
278
  <span class="ruby-constant">Base</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">working_dir</span>, <span class="ruby-identifier">options</span>)
266
279
  <span class="ruby-keyword kw">end</span>
@@ -1 +1 @@
1
- Mon Nov 12 10:52:42 PST 2007
1
+ Mon Nov 12 11:08:01 PST 2007
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Mon Nov 12 10:51:20 PST 2007</td>
59
+ <td>Mon Nov 12 11:07:58 PST 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -73,6 +73,21 @@
73
73
  <p>
74
74
  Library for using <a href="../classes/Git.html">Git</a> in Ruby.
75
75
  </p>
76
+ <h1>Homepage</h1>
77
+ <p>
78
+ The Ruby/<a href="../classes/Git.html">Git</a> homepage is currently at :
79
+ </p>
80
+ <p>
81
+ <a
82
+ href="http://jointheconversation.org/rubygit">jointheconversation.org/rubygit</a>
83
+ </p>
84
+ <p>
85
+ <a href="../classes/Git.html">Git</a> public hosting of the project source
86
+ code is at:
87
+ </p>
88
+ <p>
89
+ <a href="http://repo.or.cz/w/rubygit.git">repo.or.cz/w/rubygit.git</a>
90
+ </p>
76
91
  <h1>Roadmap</h1>
77
92
  <p>
78
93
  Right now I&#8217;m forking calls to the &#8216;git&#8217; binary, but
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Nov 10 16:21:26 PST 2007</td>
59
+ <td>Mon Nov 12 10:59:30 PST 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
data/lib/git.rb CHANGED
@@ -21,15 +21,11 @@ require 'git/remote'
21
21
 
22
22
  require 'git/diff'
23
23
  require 'git/status'
24
- =begin
25
24
  require 'git/author'
26
- require 'git/file'
27
-
28
- require 'git/sha'
29
- require 'git/ref'
30
- =end
31
25
 
32
26
  module Git
27
+
28
+ VERSION = '1.0.2'
33
29
 
34
30
  def self.bare(git_dir)
35
31
  Base.bare(git_dir)
@@ -0,0 +1,14 @@
1
+ module Git
2
+ class Author
3
+ attr_accessor :name, :email, :date
4
+
5
+ def initialize(author_string)
6
+ if m = /(.*?) <(.*?)> (\d+) (.*)/.match(author_string)
7
+ @name = m[1]
8
+ @email = m[2]
9
+ @date = Time.at(m[3].to_i)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -79,10 +79,46 @@ module Git
79
79
  command('cat-file', ['-s', sha]).to_i
80
80
  end
81
81
 
82
+ # returns useful array of raw commit object data
83
+ def commit_data(sha)
84
+ in_message = false
85
+
86
+ hsh = {'message' => '', 'parent' => []}
87
+ command_lines('cat-file', ['commit', sha.to_s]).each do |line|
88
+ if in_message
89
+ hsh['message'] += line + "\n"
90
+ end
91
+
92
+ if (line != '') && !in_message
93
+ data = line.split
94
+ key = data.shift
95
+ value = data.join(' ')
96
+ if key == 'parent'
97
+ hsh[key] << value
98
+ else
99
+ hsh[key] = value
100
+ end
101
+ else
102
+ in_message = true
103
+ end
104
+ end
105
+ hsh
106
+ end
107
+
82
108
  def object_contents(sha)
83
109
  command('cat-file', ['-p', sha])
84
110
  end
85
111
 
112
+ def ls_tree(sha)
113
+ data = {'blob' => {}, 'tree' => {}}
114
+ command_lines('ls-tree', sha.to_s).each do |line|
115
+ (info, filenm) = line.split("\t")
116
+ (mode, type, sha) = info.split
117
+ data[type][filenm] = {:mode => mode, :sha => sha}
118
+ end
119
+ data
120
+ end
121
+
86
122
  def branches_all
87
123
  arr = []
88
124
  command_lines('branch', '-a').each do |b|
@@ -12,7 +12,7 @@ module Git
12
12
 
13
13
  def initialize(base, sha)
14
14
  @base = base
15
- @sha = sha
15
+ @sha = sha.to_s
16
16
  @size = @base.lib.object_size(@sha)
17
17
  setup
18
18
  end
@@ -51,21 +51,134 @@ module Git
51
51
 
52
52
 
53
53
  class Blob < AbstractObject
54
+
55
+ def initialize(base, sha, mode = nil)
56
+ super(base, sha)
57
+ @mode = mode
58
+ end
59
+
54
60
  def setup
55
61
  @type = 'blob'
56
62
  end
57
63
  end
58
64
 
59
65
  class Tree < AbstractObject
66
+
67
+ @trees = nil
68
+ @blobs = nil
69
+
70
+ def initialize(base, sha, mode = nil)
71
+ super(base, sha)
72
+ @mode = mode
73
+ end
74
+
60
75
  def setup
61
76
  @type = 'tree'
62
77
  end
78
+
79
+ def children
80
+ blobs.merge(subtrees)
81
+ end
82
+
83
+ def blobs
84
+ check_tree
85
+ @blobs
86
+ end
87
+ alias_method :files, :blobs
88
+
89
+ def trees
90
+ check_tree
91
+ @trees
92
+ end
93
+ alias_method :subtrees, :trees
94
+ alias_method :subdirectories, :trees
95
+
96
+ private
97
+
98
+ # actually run the git command
99
+ def check_tree
100
+ if !@trees
101
+ @trees = {}
102
+ @blobs = {}
103
+ data = @base.lib.ls_tree(@sha)
104
+ data['tree'].each { |k, d| @trees[k] = Tree.new(@base, d[:sha], d[:mode]) }
105
+ data['blob'].each { |k, d| @blobs[k] = Blob.new(@base, d[:sha], d[:mode]) }
106
+ end
107
+ end
108
+
63
109
  end
64
110
 
65
111
  class Commit < AbstractObject
112
+
113
+ @tree = nil
114
+ @parents = nil
115
+ @author = nil
116
+ @committer = nil
117
+ @message = nil
118
+
66
119
  def setup
67
120
  @type = 'commit'
68
121
  end
122
+
123
+ def message
124
+ check_commit
125
+ @message
126
+ end
127
+
128
+ def gtree
129
+ check_commit
130
+ Tree.new(@base, @tree)
131
+ end
132
+
133
+ def parent
134
+ parents.first
135
+ end
136
+
137
+ # array of all parent commits
138
+ def parents
139
+ check_commit
140
+ @parents
141
+ end
142
+
143
+ # git author
144
+ def author
145
+ check_commit
146
+ @author
147
+ end
148
+
149
+ def author_date
150
+ author.date
151
+ end
152
+
153
+ # git author
154
+ def committer
155
+ check_commit
156
+ @committer
157
+ end
158
+
159
+ def committer_date
160
+ committer.date
161
+ end
162
+ alias_method :date, :committer_date
163
+
164
+ def diff_parent
165
+ diff(parent)
166
+ end
167
+
168
+ private
169
+
170
+ # see if this object has been initialized and do so if not
171
+ def check_commit
172
+ if !@tree
173
+ data = @base.lib.commit_data(@sha)
174
+ @committer = Git::Author.new(data['committer'])
175
+ @author = Git::Author.new(data['author'])
176
+ @tree = Tree.new(@base, data['tree'])
177
+ @parents = data['parent'].map{ |sha| Commit.new(@base, sha) }
178
+ @message = data['message'].chomp
179
+ end
180
+ end
181
+
69
182
  end
70
183
 
71
184
  class Tag < AbstractObject
@@ -22,17 +22,18 @@ class Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  def teardown
25
- if @wdir
26
- FileUtils.rm_r(@wdir)
25
+ if @tmp_path
26
+ #puts "teardown #{@tmp_path}"
27
+ FileUtils.rm_r(@tmp_path)
27
28
  end
28
29
  end
29
30
 
30
31
  def create_temp_repo(clone_path)
31
- filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s
32
- tmp_path = File.join("/tmp/", filename)
33
- FileUtils.mkdir_p(tmp_path)
34
- FileUtils.cp_r(clone_path, tmp_path)
35
- tmp_path = File.join(tmp_path, 'working')
32
+ filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
33
+ @tmp_path = File.join("/tmp/", filename)
34
+ FileUtils.mkdir_p(@tmp_path)
35
+ FileUtils.cp_r(clone_path, @tmp_path)
36
+ tmp_path = File.join(@tmp_path, 'working')
36
37
  Dir.chdir(tmp_path) do
37
38
  FileUtils.mv('dot_git', '.git')
38
39
  end
@@ -40,7 +41,7 @@ class Test::Unit::TestCase
40
41
  end
41
42
 
42
43
  def in_temp_dir(remove_after = true)
43
- filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s
44
+ filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
44
45
  tmp_path = File.join("/tmp/", filename)
45
46
  FileUtils.mkdir(tmp_path)
46
47
  Dir.chdir tmp_path do
@@ -13,6 +13,14 @@ class TestLib < Test::Unit::TestCase
13
13
  set_file_paths
14
14
  @lib = Git.open(@wdir).lib
15
15
  end
16
+
17
+ def test_commit_data
18
+ data = @lib.commit_data('1cc8667014381')
19
+ assert_equal('scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194561188 -0800', data['author'])
20
+ assert_equal('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7', data['tree'])
21
+ assert_equal("test\n", data['message'])
22
+ assert_equal(["546bec6f8872efa41d5d97a369f669165ecda0de"], data['parent'])
23
+ end
16
24
 
17
25
  # takes parameters, returns array of appropriate commit objects
18
26
  # :count
@@ -16,6 +16,18 @@ class TestObject < Test::Unit::TestCase
16
16
  o = @git.object('1cc8667014381')
17
17
  assert(o.is_a?(Git::Object::Commit))
18
18
 
19
+ assert_equal('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7', o.gtree.to_s)
20
+ assert_equal('546bec6f8872efa41d5d97a369f669165ecda0de', o.parent.sha)
21
+ assert_equal(1, o.parents.size)
22
+ assert_equal('scott Chacon', o.author.name)
23
+ assert_equal('schacon@agadorsparticus.corp.reactrix.com', o.author.email)
24
+ assert_equal('11-08-07', o.author.date.strftime("%m-%d-%y"))
25
+ assert_equal('11-08-07', o.author_date.strftime("%m-%d-%y"))
26
+ assert_equal('scott Chacon', o.committer.name)
27
+ assert_equal('11-08-07', o.committer_date.strftime("%m-%d-%y"))
28
+ assert_equal('11-08-07', o.date.strftime("%m-%d-%y"))
29
+ assert_equal('test', o.message)
30
+
19
31
  o = @git.object('HEAD')
20
32
  assert(o.is_a?(Git::Object::Commit))
21
33
  assert_equal('commit', o.type)
@@ -47,6 +59,13 @@ class TestObject < Test::Unit::TestCase
47
59
  o = @git.object('1cc8667014381^{tree}')
48
60
  assert(o.is_a?(Git::Object::Tree))
49
61
 
62
+ o = @git.object('v2.7^{tree}')
63
+
64
+ assert_equal(2, o.children.size)
65
+ assert_equal(1, o.blobs.size)
66
+ assert_equal(1, o.subtrees.size)
67
+ assert_equal(1, o.trees['ex_dir'].blobs.size)
68
+
50
69
  o = @git.object('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7')
51
70
  assert(o.is_a?(Git::Object::Tree))
52
71
  assert_equal('tree', o.type)
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: git
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
6
+ version: 1.0.2
7
7
  date: 2007-11-12 00:00:00 -08:00
8
8
  summary: A package for using Git in Ruby code.
9
9
  require_paths:
@@ -31,6 +31,7 @@ authors:
31
31
  files:
32
32
  - lib/git
33
33
  - lib/git.rb
34
+ - lib/git/author.rb
34
35
  - lib/git/base.rb
35
36
  - lib/git/branch.rb
36
37
  - lib/git/branches.rb