You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

611 line
19KB

  1. diff --git a/.gitignore b/.gitignore
  2. index 4ebc8aea50e0a67e000ba29a30809d0a7b9b2666..2dd02534615434d88c51307beb0f0092f21fd103 100644
  3. --- a/.gitignore
  4. +++ b/.gitignore
  5. @@ -1 +1,2 @@
  6. coverage
  7. +pkg
  8. diff --git a/Manifest.txt b/Manifest.txt
  9. index 641972d82c6d1b51122274ae8f6a0ecdfb56ee22..38bf80c54a526e76d74820a0f48606fe1ca7b1be 100644
  10. --- a/Manifest.txt
  11. +++ b/Manifest.txt
  12. @@ -4,4 +4,31 @@ README.txt
  13. Rakefile
  14. bin/grit
  15. lib/grit.rb
  16. -test/test_grit.rb
  17. \ No newline at end of file
  18. +lib/grit/actor.rb
  19. +lib/grit/blob.rb
  20. +lib/grit/commit.rb
  21. +lib/grit/errors.rb
  22. +lib/grit/git.rb
  23. +lib/grit/head.rb
  24. +lib/grit/lazy.rb
  25. +lib/grit/repo.rb
  26. +lib/grit/tree.rb
  27. +test/fixtures/blame
  28. +test/fixtures/cat_file_blob
  29. +test/fixtures/cat_file_blob_size
  30. +test/fixtures/for_each_ref
  31. +test/fixtures/ls_tree_a
  32. +test/fixtures/ls_tree_b
  33. +test/fixtures/rev_list
  34. +test/fixtures/rev_list_single
  35. +test/helper.rb
  36. +test/profile.rb
  37. +test/suite.rb
  38. +test/test_actor.rb
  39. +test/test_blob.rb
  40. +test/test_commit.rb
  41. +test/test_git.rb
  42. +test/test_head.rb
  43. +test/test_reality.rb
  44. +test/test_repo.rb
  45. +test/test_tree.rb
  46. diff --git a/README.txt b/README.txt
  47. index 8b1e02c0fb554eed2ce2ef737a68bb369d7527df..fca94f84afd7d749c62626011f972a509f6a5ac6 100644
  48. --- a/README.txt
  49. +++ b/README.txt
  50. @@ -1,32 +1,185 @@
  51. grit
  52. - by FIX (your name)
  53. - FIX (url)
  54. + by Tom Preston-Werner
  55. + grit.rubyforge.org
  56. == DESCRIPTION:
  57. +
  58. +Grit is a Ruby library for extracting information from a git repository in and
  59. +object oriented manner.
  60. +
  61. +== REQUIREMENTS:
  62. +
  63. +* git (http://git.or.cz) tested with 1.5.3.4
  64. +
  65. +== INSTALL:
  66. +
  67. +sudo gem install grit
  68. +
  69. +== USAGE:
  70. +
  71. +Grit gives you object model access to your git repository. Once you have
  72. +created a repository object, you can traverse it to find parent commit(s),
  73. +trees, blobs, etc.
  74. +
  75. += Initialize a Repo object
  76. +
  77. +The first step is to create a GitPython.Repo object to represent your repo. I
  78. +include the Grit module so reduce typing.
  79. +
  80. + include Grit
  81. + repo = Repo.new("/Users/tom/dev/grit")
  82. -FIX (describe your package)
  83. +In the above example, the directory /Users/tom/dev/grit is my working
  84. +repo and contains the .git directory. You can also initialize Grit with a
  85. +bare repo.
  86. -== FEATURES/PROBLEMS:
  87. + repo = Repo.new("/var/git/grit.git")
  88. -* FIX (list of features or problems)
  89. += Getting a list of commits
  90. -== SYNOPSIS:
  91. +From the Repo object, you can get a list of commits as an array of Commit
  92. +objects.
  93. - FIX (code sample of usage)
  94. + repo.commits
  95. + # => [#<GitPython.Commit "e80bbd2ce67651aa18e57fb0b43618ad4baf7750">,
  96. + #<GitPython.Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">,
  97. + #<GitPython.Commit "038af8c329ef7c1bae4568b98bd5c58510465493">,
  98. + #<GitPython.Commit "40d3057d09a7a4d61059bca9dca5ae698de58cbe">,
  99. + #<GitPython.Commit "4ea50f4754937bf19461af58ce3b3d24c77311d9">]
  100. +
  101. +Called without arguments, Repo#commits returns a list of up to ten commits
  102. +reachable by the master branch (starting at the latest commit). You can ask
  103. +for commits beginning at a different branch, commit, tag, etc.
  104. -== REQUIREMENTS:
  105. + repo.commits('mybranch')
  106. + repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe')
  107. + repo.commits('v0.1')
  108. +
  109. +You can specify the maximum number of commits to return.
  110. -* FIX (list of requirements)
  111. + repo.commits('master', 100)
  112. +
  113. +If you need paging, you can specify a number of commits to skip.
  114. -== INSTALL:
  115. + repo.commits('master', 10, 20)
  116. +
  117. +The above will return commits 21-30 from the commit list.
  118. +
  119. += The Commit object
  120. +
  121. +Commit objects contain information about that commit.
  122. +
  123. + head = repo.commits.first
  124. +
  125. + head.id
  126. + # => "e80bbd2ce67651aa18e57fb0b43618ad4baf7750"
  127. +
  128. + head.parents
  129. + # => [#<GitPython.Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">]
  130. +
  131. + head.tree
  132. + # => #<GitPython.Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
  133. +
  134. + head.author
  135. + # => #<GitPython.Actor "Tom Preston-Werner <tom@mojombo.com>">
  136. +
  137. + head.authored_date
  138. + # => Wed Oct 24 22:02:31 -0700 2007
  139. +
  140. + head.committer
  141. + # => #<GitPython.Actor "Tom Preston-Werner <tom@mojombo.com>">
  142. +
  143. + head.committed_date
  144. + # => Wed Oct 24 22:02:31 -0700 2007
  145. +
  146. + head.message
  147. + # => "add Actor inspect"
  148. +
  149. +You can traverse a commit's ancestry by chaining calls to #parents.
  150. +
  151. + repo.commits.first.parents[0].parents[0].parents[0]
  152. +
  153. +The above corresponds to master^^^ or master~3 in git parlance.
  154. +
  155. += The Tree object
  156. +
  157. +A tree records pointers to the contents of a directory. Let's say you want
  158. +the root tree of the latest commit on the master branch.
  159. +
  160. + tree = repo.commits.first.tree
  161. + # => #<GitPython.Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
  162. +
  163. + tree.id
  164. + # => "3536eb9abac69c3e4db583ad38f3d30f8db4771f"
  165. +
  166. +Once you have a tree, you can get the contents.
  167. +
  168. + contents = tree.contents
  169. + # => [#<GitPython.Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">,
  170. + #<GitPython.Blob "81d2c27608b352814cbe979a6acd678d30219678">,
  171. + #<GitPython.Tree "c3d07b0083f01a6e1ac969a0f32b8d06f20c62e5">,
  172. + #<GitPython.Tree "4d00fe177a8407dbbc64a24dbfc564762c0922d8">]
  173. +
  174. +This tree contains two Blob objects and two Tree objects. The trees are
  175. +subdirectories and the blobs are files. Trees below the root have additional
  176. +attributes.
  177. +
  178. + contents.last.name
  179. + # => "lib"
  180. +
  181. + contents.last.mode
  182. + # => "040000"
  183. +
  184. +There is a convenience method that allows you to get a named sub-object
  185. +from a tree.
  186. +
  187. + tree/"lib"
  188. + # => #<GitPython.Tree "e74893a3d8a25cbb1367cf241cc741bfd503c4b2">
  189. +
  190. +You can also get a tree directly from the repo if you know its name.
  191. +
  192. + repo.tree
  193. + # => #<GitPython.Tree "master">
  194. +
  195. + repo.tree("91169e1f5fa4de2eaea3f176461f5dc784796769")
  196. + # => #<GitPython.Tree "91169e1f5fa4de2eaea3f176461f5dc784796769">
  197. +
  198. += The Blob object
  199. +
  200. +A blob represents a file. Trees often contain blobs.
  201. +
  202. + blob = tree.contents.first
  203. + # => #<GitPython.Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
  204. +
  205. +A blob has certain attributes.
  206. +
  207. + blob.id
  208. + # => "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666"
  209. +
  210. + blob.name
  211. + # => "README.txt"
  212. +
  213. + blob.mode
  214. + # => "100644"
  215. +
  216. + blob.size
  217. + # => 7726
  218. +
  219. +You can get the data of a blob as a string.
  220. +
  221. + blob.data
  222. + # => "Grit is a library to ..."
  223. +
  224. +You can also get a blob directly from the repo if you know its name.
  225. -* FIX (sudo gem install, anything else)
  226. + repo.blob("4ebc8aea50e0a67e000ba29a30809d0a7b9b2666")
  227. + # => #<GitPython.Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
  228. == LICENSE:
  229. (The MIT License)
  230. -Copyright (c) 2007 FIX
  231. +Copyright (c) 2007 Tom Preston-Werner
  232. Permission is hereby granted, free of charge, to any person obtaining
  233. a copy of this software and associated documentation files (the
  234. diff --git a/Rakefile b/Rakefile
  235. index 5bfb62163af455ca54422fd0b2e723ba1021ad12..72fde8c9ca87a1c992ce992bab13c3c4f13cddb9 100644
  236. --- a/Rakefile
  237. +++ b/Rakefile
  238. @@ -4,11 +4,11 @@ require './lib/grit.rb'
  239. Hoe.new('grit', GitPython.VERSION) do |p|
  240. p.rubyforge_name = 'grit'
  241. - # p.author = 'FIX'
  242. - # p.email = 'FIX'
  243. - # p.summary = 'FIX'
  244. - # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
  245. - # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
  246. + p.author = 'Tom Preston-Werner'
  247. + p.email = 'tom@rubyisawesome.com'
  248. + p.summary = 'Object model interface to a git repo'
  249. + p.description = p.paragraphs_of('README.txt', 2..2).join("\n\n")
  250. + p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[2..-1].map { |u| u.strip }
  251. p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
  252. end
  253. diff --git a/lib/grit.rb b/lib/grit.rb
  254. index ae0792ae39d4891ebc1af996102a4f9df703394d..ae55fd7961ac49233f6ca515622a61e90d516044 100644
  255. --- a/lib/grit.rb
  256. +++ b/lib/grit.rb
  257. @@ -1,4 +1,4 @@
  258. -$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
  259. +$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
  260. # core
  261. @@ -12,6 +12,8 @@ require 'grit/head'
  262. require 'grit/commit'
  263. require 'grit/tree'
  264. require 'grit/blob'
  265. +require 'grit/actor'
  266. +require 'grit/diff'
  267. require 'grit/repo'
  268. module Grit
  269. @@ -21,5 +23,5 @@ module Grit
  270. self.debug = false
  271. - VERSION = '1.0.0'
  272. + VERSION = '0.1.0'
  273. end
  274. \ No newline at end of file
  275. diff --git a/lib/grit/actor.rb b/lib/grit/actor.rb
  276. new file mode 100644
  277. index 0000000000000000000000000000000000000000..f733bce6b57c0e5e353206e692b0e3105c2527f4
  278. --- /dev/null
  279. +++ b/lib/grit/actor.rb
  280. @@ -0,0 +1,35 @@
  281. +module Grit
  282. +
  283. + class Actor
  284. + attr_reader :name
  285. + attr_reader :email
  286. +
  287. + def initialize(name, email)
  288. + @name = name
  289. + @email = email
  290. + end
  291. +
  292. + # Create an Actor from a string.
  293. + # +str+ is the string, which is expected to be in regular git format
  294. + #
  295. + # Format
  296. + # John Doe <jdoe@example.com>
  297. + #
  298. + # Returns Actor
  299. + def self.from_string(str)
  300. + case str
  301. + when /<.+>/
  302. + m, name, email = *str.match(/(.*) <(.+?)>/)
  303. + return self.new(name, email)
  304. + else
  305. + return self.new(str, nil)
  306. + end
  307. + end
  308. +
  309. + # Pretty object inspection
  310. + def inspect
  311. + %Q{#<GitPython.Actor "#{@name} <#{@email}>">}
  312. + end
  313. + end # Actor
  314. +
  315. +end # Grit
  316. \ No newline at end of file
  317. diff --git a/lib/grit/blob.rb b/lib/grit/blob.rb
  318. index c863646d4278bfee2a7bcb64caace6b31f89ef03..87d43fab37844afdc2f8814dba3abdaa791f1370 100644
  319. --- a/lib/grit/blob.rb
  320. +++ b/lib/grit/blob.rb
  321. @@ -81,9 +81,9 @@ module Grit
  322. c = commits[info[:id]]
  323. unless c
  324. c = Commit.create(repo, :id => info[:id],
  325. - :author => info[:author],
  326. + :author => Actor.from_string(info[:author] + ' ' + info[:author_email]),
  327. :authored_date => info[:author_date],
  328. - :committer => info[:committer],
  329. + :committer => Actor.from_string(info[:committer] + ' ' + info[:committer_email]),
  330. :committed_date => info[:committer_date],
  331. :message => info[:summary])
  332. commits[info[:id]] = c
  333. @@ -102,11 +102,6 @@ module Grit
  334. def inspect
  335. %Q{#<GitPython.Blob "#{@id}">}
  336. end
  337. -
  338. - # private
  339. -
  340. - def self.read_
  341. - end
  342. end # Blob
  343. end # Grit
  344. \ No newline at end of file
  345. diff --git a/lib/grit/commit.rb b/lib/grit/commit.rb
  346. index c2a9e2f81657b19925fe9bab4bc5d7ac130e5880..cd9c3e3184c97e83a8982fab9499cad3aec339f6 100644
  347. --- a/lib/grit/commit.rb
  348. +++ b/lib/grit/commit.rb
  349. @@ -136,6 +136,11 @@ module Grit
  350. commits
  351. end
  352. + def self.diff(repo, id)
  353. + text = repo.git.diff({:full_index => true}, id)
  354. + Diff.list_from_string(repo, text)
  355. + end
  356. +
  357. # Convert this Commit to a String which is just the SHA1 id
  358. def to_s
  359. @id
  360. @@ -153,7 +158,7 @@ module Grit
  361. # Returns [String (actor name and email), Time (acted at time)]
  362. def self.actor(line)
  363. m, actor, epoch = *line.match(/^.+? (.*) (\d+) .*$/)
  364. - [actor, Time.at(epoch.to_i)]
  365. + [Actor.from_string(actor), Time.at(epoch.to_i)]
  366. end
  367. end # Commit
  368. diff --git a/lib/grit/git.rb b/lib/grit/git.rb
  369. index 1d5251d40fb65ac89184ec662a3e1b04d0c24861..98eeddda5ed2b0e215e21128112393bdc9bc9039 100644
  370. --- a/lib/grit/git.rb
  371. +++ b/lib/grit/git.rb
  372. @@ -13,17 +13,6 @@ module Grit
  373. self.git_dir = git_dir
  374. end
  375. - # Converstion hash from Ruby style options to git command line
  376. - # style options
  377. - TRANSFORM = {:max_count => "--max-count=",
  378. - :skip => "--skip=",
  379. - :pretty => "--pretty=",
  380. - :sort => "--sort=",
  381. - :format => "--format=",
  382. - :since => "--since=",
  383. - :p => "-p",
  384. - :s => "-s"}
  385. -
  386. # Run the given git command with the specified arguments and return
  387. # the result as a String
  388. # +cmd+ is the command
  389. @@ -52,12 +41,19 @@ module Grit
  390. def transform_options(options)
  391. args = []
  392. options.keys.each do |opt|
  393. - if TRANSFORM[opt]
  394. + if opt.to_s.size == 1
  395. + if options[opt] == true
  396. + args << "-#{opt}"
  397. + else
  398. + val = options.delete(opt)
  399. + args << "-#{opt.to_s} #{val}"
  400. + end
  401. + else
  402. if options[opt] == true
  403. - args << TRANSFORM[opt]
  404. + args << "--#{opt.to_s.gsub(/_/, '-')}"
  405. else
  406. val = options.delete(opt)
  407. - args << TRANSFORM[opt] + val.to_s
  408. + args << "--#{opt.to_s.gsub(/_/, '-')}=#{val}"
  409. end
  410. end
  411. end
  412. diff --git a/lib/grit/repo.rb b/lib/grit/repo.rb
  413. index 624991d07e240ae66ff2a0dc55e2f2b5e262c75b..63bf03b839374c96a3d42a07d56681a797f52a71 100644
  414. --- a/lib/grit/repo.rb
  415. +++ b/lib/grit/repo.rb
  416. @@ -93,6 +93,17 @@ module Grit
  417. def blob(id)
  418. Blob.create(self, :id => id)
  419. end
  420. +
  421. + # The commit log for a treeish
  422. + #
  423. + # Returns GitPython.Commit[]
  424. + def log(commit = 'master', path = nil, options = {})
  425. + default_options = {:pretty => "raw"}
  426. + actual_options = default_options.merge(options)
  427. + arg = path ? "#{commit} -- #{path}" : commit
  428. + commits = self.git.log(actual_options, arg)
  429. + Commit.list_from_string(self, commits)
  430. + end
  431. # The diff from commit +a+ to commit +b+, optionally restricted to the given file(s)
  432. # +a+ is the base commit
  433. @@ -121,4 +132,4 @@ module Grit
  434. end
  435. end # Repo
  436. -end # Grit
  437. \ No newline at end of file
  438. +end # Grit
  439. diff --git a/test/test_actor.rb b/test/test_actor.rb
  440. new file mode 100644
  441. index 0000000000000000000000000000000000000000..08391f12336831d048122c8d13bc8404f27e6b91
  442. --- /dev/null
  443. +++ b/test/test_actor.rb
  444. @@ -0,0 +1,28 @@
  445. +require File.dirname(__FILE__) + '/helper'
  446. +
  447. +class TestActor < Test::Unit::TestCase
  448. + def setup
  449. +
  450. + end
  451. +
  452. + # from_string
  453. +
  454. + def test_from_string_should_separate_name_and_email
  455. + a = Actor.from_string("Tom Werner <tom@example.com>")
  456. + assert_equal "Tom Werner", a.name
  457. + assert_equal "tom@example.com", a.email
  458. + end
  459. +
  460. + def test_from_string_should_handle_just_name
  461. + a = Actor.from_string("Tom Werner")
  462. + assert_equal "Tom Werner", a.name
  463. + assert_equal nil, a.email
  464. + end
  465. +
  466. + # inspect
  467. +
  468. + def test_inspect
  469. + a = Actor.from_string("Tom Werner <tom@example.com>")
  470. + assert_equal %Q{#<GitPython.Actor "Tom Werner <tom@example.com>">}, a.inspect
  471. + end
  472. +end
  473. \ No newline at end of file
  474. diff --git a/test/test_blob.rb b/test/test_blob.rb
  475. index 6fa087d785661843034d03c7e0b917a8a80d5d8c..9ef84cc14266141b070771706b8aeebc3dfbef82 100644
  476. --- a/test/test_blob.rb
  477. +++ b/test/test_blob.rb
  478. @@ -40,9 +40,11 @@ class TestBlob < Test::Unit::TestCase
  479. c = b.first.first
  480. c.expects(:__bake__).times(0)
  481. assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id
  482. - assert_equal 'Tom Preston-Werner', c.author
  483. + assert_equal 'Tom Preston-Werner', c.author.name
  484. + assert_equal 'tom@mojombo.com', c.author.email
  485. assert_equal Time.at(1191997100), c.authored_date
  486. - assert_equal 'Tom Preston-Werner', c.committer
  487. + assert_equal 'Tom Preston-Werner', c.committer.name
  488. + assert_equal 'tom@mojombo.com', c.committer.email
  489. assert_equal Time.at(1191997100), c.committed_date
  490. assert_equal 'initial grit setup', c.message
  491. # c.expects(:__bake__).times(1)
  492. diff --git a/test/test_commit.rb b/test/test_commit.rb
  493. index 3bd6af75deda05725900eb7fd06e8107df14c655..0936c90e5b29ede2b5214d6dc26d256a8c6646f4 100644
  494. --- a/test/test_commit.rb
  495. +++ b/test/test_commit.rb
  496. @@ -10,9 +10,28 @@ class TestCommit < Test::Unit::TestCase
  497. def test_bake
  498. Git.any_instance.expects(:rev_list).returns(fixture('rev_list_single'))
  499. @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
  500. - @c.author # cause bake-age
  501. + @c.author # bake
  502. - assert_equal "Tom Preston-Werner <tom@mojombo.com>", @c.author
  503. + assert_equal "Tom Preston-Werner", @c.author.name
  504. + assert_equal "tom@mojombo.com", @c.author.email
  505. + end
  506. +
  507. + # diff
  508. +
  509. + def test_diff
  510. + Git.any_instance.expects(:diff).returns(fixture('diff_p'))
  511. + diffs = Commit.diff(@r, 'master')
  512. +
  513. + assert_equal 15, diffs.size
  514. +
  515. + assert_equal '.gitignore', diffs.first.a_path
  516. + assert_equal '.gitignore', diffs.first.b_path
  517. + assert_equal '4ebc8ae', diffs.first.a_commit
  518. + assert_equal '2dd0253', diffs.first.b_commit
  519. + assert_equal '100644', diffs.first.mode
  520. + assert_equal false, diffs.first.new_file
  521. + assert_equal false, diffs.first.deleted_file
  522. + assert_equal "--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs.first.diff
  523. end
  524. # to_s
  525. diff --git a/test/test_git.rb b/test/test_git.rb
  526. index e615a035d096b6cbc984e2f4213c06d0ac785321..72a18ec424f078f6daee75dbc62265c02ba7a892 100644
  527. --- a/test/test_git.rb
  528. +++ b/test/test_git.rb
  529. @@ -10,6 +10,12 @@ class TestGit < Test::Unit::TestCase
  530. end
  531. def test_transform_options
  532. + assert_equal ["-s"], @git.transform_options({:s => true})
  533. + assert_equal ["-s 5"], @git.transform_options({:s => 5})
  534. +
  535. + assert_equal ["--max-count"], @git.transform_options({:max_count => true})
  536. assert_equal ["--max-count=5"], @git.transform_options({:max_count => 5})
  537. +
  538. + assert_equal ["-t", "-s"], @git.transform_options({:s => true, :t => true})
  539. end
  540. end
  541. \ No newline at end of file
  542. diff --git a/test/test_repo.rb b/test/test_repo.rb
  543. index d53476a51e3286be270c7b515ec1d65e5c1716e0..114a4464fa248550be10cc4abe0735d6025b5fca 100644
  544. --- a/test/test_repo.rb
  545. +++ b/test/test_repo.rb
  546. @@ -59,9 +59,11 @@ class TestRepo < Test::Unit::TestCase
  547. assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id
  548. assert_equal ["634396b2f541a9f2d58b00be1a07f0c358b999b3"], c.parents.map { |p| p.id }
  549. assert_equal "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id
  550. - assert_equal "Tom Preston-Werner <tom@mojombo.com>", c.author
  551. + assert_equal "Tom Preston-Werner", c.author.name
  552. + assert_equal "tom@mojombo.com", c.author.email
  553. assert_equal Time.at(1191999972), c.authored_date
  554. - assert_equal "Tom Preston-Werner <tom@mojombo.com>", c.committer
  555. + assert_equal "Tom Preston-Werner", c.committer.name
  556. + assert_equal "tom@mojombo.com", c.committer.email
  557. assert_equal Time.at(1191999972), c.committed_date
  558. assert_equal "implement Grit#heads", c.message
  559. @@ -125,4 +127,18 @@ class TestRepo < Test::Unit::TestCase
  560. def test_inspect
  561. assert_equal %Q{#<GitPython.Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
  562. end
  563. -end
  564. \ No newline at end of file
  565. +
  566. + # log
  567. +
  568. + def test_log
  569. + Git.any_instance.expects(:log).times(2).with({:pretty => 'raw'}, 'master').returns(fixture('rev_list'))
  570. +
  571. + assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', @r.log.first.id
  572. + assert_equal 'ab25fd8483882c3bda8a458ad2965d2248654335', @r.log.last.id
  573. + end
  574. +
  575. + def test_log_with_path_and_options
  576. + Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master -- file.rb').returns(fixture('rev_list'))
  577. + @r.log('master', 'file.rb', :max_count => 1)
  578. + end
  579. +end