mercurial-ruby 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/.document +5 -0
  2. data/Gemfile +10 -0
  3. data/Gemfile.lock +32 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +86 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/lib/mercurial-ruby.rb +66 -0
  9. data/lib/mercurial-ruby/branch.rb +45 -0
  10. data/lib/mercurial-ruby/changed_file.rb +51 -0
  11. data/lib/mercurial-ruby/command.rb +77 -0
  12. data/lib/mercurial-ruby/commit.rb +152 -0
  13. data/lib/mercurial-ruby/config_file.rb +119 -0
  14. data/lib/mercurial-ruby/configuration.rb +14 -0
  15. data/lib/mercurial-ruby/diff.rb +50 -0
  16. data/lib/mercurial-ruby/factories/branch_factory.rb +91 -0
  17. data/lib/mercurial-ruby/factories/changed_file_factory.rb +50 -0
  18. data/lib/mercurial-ruby/factories/commit_factory.rb +154 -0
  19. data/lib/mercurial-ruby/factories/diff_factory.rb +63 -0
  20. data/lib/mercurial-ruby/factories/hook_factory.rb +45 -0
  21. data/lib/mercurial-ruby/factories/node_factory.rb +111 -0
  22. data/lib/mercurial-ruby/factories/tag_factory.rb +48 -0
  23. data/lib/mercurial-ruby/file_index.rb +209 -0
  24. data/lib/mercurial-ruby/helper.rb +23 -0
  25. data/lib/mercurial-ruby/hook.rb +23 -0
  26. data/lib/mercurial-ruby/manifest.rb +58 -0
  27. data/lib/mercurial-ruby/node.rb +100 -0
  28. data/lib/mercurial-ruby/repository.rb +94 -0
  29. data/lib/mercurial-ruby/root_node.rb +27 -0
  30. data/lib/mercurial-ruby/shell.rb +64 -0
  31. data/lib/mercurial-ruby/style.rb +23 -0
  32. data/lib/mercurial-ruby/tag.rb +33 -0
  33. data/lib/stdlib_exts/string.rb +12 -0
  34. data/lib/styles/changeset.style +5 -0
  35. data/lib/styles/file_index.style +3 -0
  36. data/mercurial-ruby.gemspec +227 -0
  37. data/test/fixtures.rb +28 -0
  38. data/test/fixtures/test-repo/.DotFile +1 -0
  39. data/test/fixtures/test-repo/.hg/00changelog.i +0 -0
  40. data/test/fixtures/test-repo/.hg/branch +1 -0
  41. data/test/fixtures/test-repo/.hg/cache/branchheads +6 -0
  42. data/test/fixtures/test-repo/.hg/cache/tags +7 -0
  43. data/test/fixtures/test-repo/.hg/dirstate +0 -0
  44. data/test/fixtures/test-repo/.hg/hgrc +3 -0
  45. data/test/fixtures/test-repo/.hg/last-message.txt +1 -0
  46. data/test/fixtures/test-repo/.hg/requires +4 -0
  47. data/test/fixtures/test-repo/.hg/store/00changelog.i +0 -0
  48. data/test/fixtures/test-repo/.hg/store/00manifest.i +0 -0
  49. data/test/fixtures/test-repo/.hg/store/data/_file _with _whitespace.pdf.i +0 -0
  50. data/test/fixtures/test-repo/.hg/store/data/_l_i_c_e_n_s_e.txt.i +0 -0
  51. data/test/fixtures/test-repo/.hg/store/data/_l_i_c_e_n_s_e2.txt.i +0 -0
  52. data/test/fixtures/test-repo/.hg/store/data/_l_i_c_e_n_s_e3.txt.i +0 -0
  53. data/test/fixtures/test-repo/.hg/store/data/_l_i_c_e_n_s_e4.txt.i +0 -0
  54. data/test/fixtures/test-repo/.hg/store/data/_r_e_a_d_m_e.markdown.i +0 -0
  55. data/test/fixtures/test-repo/.hg/store/data/_r_e_a_d_m_e.markup.i +0 -0
  56. data/test/fixtures/test-repo/.hg/store/data/_rakefile.i +0 -0
  57. data/test/fixtures/test-repo/.hg/store/data/_rakefile2.i +0 -0
  58. data/test/fixtures/test-repo/.hg/store/data/_rakefile3.i +0 -0
  59. data/test/fixtures/test-repo/.hg/store/data/check ~5c this ~5c out ~22 now.i +0 -0
  60. data/test/fixtures/test-repo/.hg/store/data/directory two/minitest__mixin.rb.i +0 -0
  61. data/test/fixtures/test-repo/.hg/store/data/directory two/options.rb.i +0 -0
  62. data/test/fixtures/test-repo/.hg/store/data/directory two/rdoc__mixin.rb.i +0 -0
  63. data/test/fixtures/test-repo/.hg/store/data/directory two/rspec__mixin.rb.i +0 -0
  64. data/test/fixtures/test-repo/.hg/store/data/directory two/shindo__mixin.rb.i +0 -0
  65. data/test/fixtures/test-repo/.hg/store/data/directory two/shoulda__mixin.rb.i +0 -0
  66. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/_gemfile.i +0 -0
  67. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/_l_i_c_e_n_s_e.txt.i +0 -0
  68. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/_r_e_a_d_m_e.rdoc.i +0 -0
  69. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/_rakefile.i +0 -0
  70. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/bacon/flunking.rb.i +0 -0
  71. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/bacon/helper.rb.i +0 -0
  72. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/bundler__setup.erb.i +0 -0
  73. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/features/default.feature.i +0 -0
  74. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/features/support/env.rb.i +0 -0
  75. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/jeweler__tasks.erb.i +0 -0
  76. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/micronaut/flunking.rb.i +0 -0
  77. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/micronaut/helper.rb.i +0 -0
  78. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/minitest/flunking.rb.i +0 -0
  79. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/minitest/helper.rb.i +0 -0
  80. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/other__tasks.erb.i +0 -0
  81. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/riot/flunking.rb.i +0 -0
  82. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/riot/helper.rb.i +0 -0
  83. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/rspec/flunking.rb.i +0 -0
  84. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/rspec/helper.rb.i +0 -0
  85. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/rspec/~2erspec.i +0 -0
  86. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/shindo/flunking.rb.i +0 -0
  87. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/shindo/helper.rb.i +0 -0
  88. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/shoulda/flunking.rb.i +0 -0
  89. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/shoulda/helper.rb.i +0 -0
  90. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/testspec/flunking.rb.i +0 -0
  91. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/testspec/helper.rb.i +0 -0
  92. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/testunit/flunking.rb.i +0 -0
  93. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/testunit/helper.rb.i +0 -0
  94. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/~2edocument.i +0 -0
  95. data/test/fixtures/test-repo/.hg/store/data/directory two/templates/~2egitignore.i +0 -0
  96. data/test/fixtures/test-repo/.hg/store/data/directory two/~2e_d_s___store.i +0 -0
  97. data/test/fixtures/test-repo/.hg/store/data/directory__1/rubygems__dot__org__tasks.rb.i +0 -0
  98. data/test/fixtures/test-repo/.hg/store/data/directory__1/rubygems__tasks.rb.i +0 -0
  99. data/test/fixtures/test-repo/.hg/store/data/directory__1/specification.rb.i +0 -0
  100. data/test/fixtures/test-repo/.hg/store/data/directory__1/tasks.rb.i +0 -0
  101. data/test/fixtures/test-repo/.hg/store/data/directory__1/~2e_d_s___store.i +0 -0
  102. data/test/fixtures/test-repo/.hg/store/data/empty-file.i +0 -0
  103. data/test/fixtures/test-repo/.hg/store/data/goose.png.i +0 -0
  104. data/test/fixtures/test-repo/.hg/store/data/goose/pretty-thing.txt.i +0 -0
  105. data/test/fixtures/test-repo/.hg/store/data/new-directory/another-boring-file.i +0 -0
  106. data/test/fixtures/test-repo/.hg/store/data/new-directory/something.csv.i +0 -0
  107. data/test/fixtures/test-repo/.hg/store/data/new-directory/subdirectory/_e_u_l_a5seat___chin___sim02.03.04.pdf.d +0 -0
  108. data/test/fixtures/test-repo/.hg/store/data/new-directory/subdirectory/_e_u_l_a5seat___chin___sim02.03.04.pdf.i +0 -0
  109. data/test/fixtures/test-repo/.hg/store/data/new-directory/subdirectory/_file _with _whitespace.pdf.i +0 -0
  110. data/test/fixtures/test-repo/.hg/store/data/new-directory/subdirectory/beansprout.png.i +0 -0
  111. data/test/fixtures/test-repo/.hg/store/data/new-file.i +0 -0
  112. data/test/fixtures/test-repo/.hg/store/data/old-directory/minitest__mixin.rb.i +0 -0
  113. data/test/fixtures/test-repo/.hg/store/data/old-directory/options.rb.i +0 -0
  114. data/test/fixtures/test-repo/.hg/store/data/old-directory/rspec__mixin.rb.i +0 -0
  115. data/test/fixtures/test-repo/.hg/store/data/old-directory/shindo__mixin.rb.i +0 -0
  116. data/test/fixtures/test-repo/.hg/store/data/old-directory/testunit__mixin.rb.i +0 -0
  117. data/test/fixtures/test-repo/.hg/store/data/old-directory/yard__mixin.rb.i +0 -0
  118. data/test/fixtures/test-repo/.hg/store/data/riot__mixin.rb.i +0 -0
  119. data/test/fixtures/test-repo/.hg/store/data/riot__mixin__copy.rb.i +0 -0
  120. data/test/fixtures/test-repo/.hg/store/data/style.i +0 -0
  121. data/test/fixtures/test-repo/.hg/store/data/super-cow.i +0 -0
  122. data/test/fixtures/test-repo/.hg/store/data/superman.txt.i +0 -0
  123. data/test/fixtures/test-repo/.hg/store/data/testspec__mixin.rb.i +0 -0
  124. data/test/fixtures/test-repo/.hg/store/data/testspec__mixin__new.rb.i +0 -0
  125. data/test/fixtures/test-repo/.hg/store/data/~2e_dot_file.i +0 -0
  126. data/test/fixtures/test-repo/.hg/store/data/~2ehgignore.i +0 -0
  127. data/test/fixtures/test-repo/.hg/store/data/~2ehgtags.i +0 -0
  128. data/test/fixtures/test-repo/.hg/store/fncache +79 -0
  129. data/test/fixtures/test-repo/.hg/store/undo +0 -0
  130. data/test/fixtures/test-repo/.hg/undo.bookmarks +0 -0
  131. data/test/fixtures/test-repo/.hg/undo.branch +1 -0
  132. data/test/fixtures/test-repo/.hg/undo.desc +2 -0
  133. data/test/fixtures/test-repo/.hg/undo.dirstate +0 -0
  134. data/test/fixtures/test-repo/.hgignore +1 -0
  135. data/test/fixtures/test-repo/.hgtags +1 -0
  136. data/test/fixtures/test-repo/LICENSE3.txt +15 -0
  137. data/test/fixtures/test-repo/LICENSE4.txt +17 -0
  138. data/test/fixtures/test-repo/README.markup +218 -0
  139. data/test/fixtures/test-repo/Rakefile3 +83 -0
  140. data/test/fixtures/test-repo/check // this // out /" now" "b/data/test/fixtures/test-repo/check // this // out / → now +0 -0
  141. data/test/fixtures/test-repo/empty-file +0 -0
  142. data/test/fixtures/test-repo/goose.png +0 -0
  143. data/test/fixtures/test-repo/goose/pretty-thing.txt +0 -0
  144. data/test/fixtures/test-repo/new-directory/another-boring-file +78 -0
  145. data/test/fixtures/test-repo/new-directory/something.csv +1 -0
  146. data/test/fixtures/test-repo/new-directory/subdirectory/EULA5seat_Chin_Sim02.03.04.pdf +0 -0
  147. data/test/fixtures/test-repo/new-directory/subdirectory/File With Whitespace.pdf b/data/test/fixtures/test-repo/new-directory/subdirectory/File With → Whitespace.pdf +0 -0
  148. data/test/fixtures/test-repo/new-directory/subdirectory/beansprout.png +0 -0
  149. data/test/fixtures/test-repo/riot_mixin.rb +45 -0
  150. data/test/fixtures/test-repo/style +4 -0
  151. data/test/fixtures/test-repo/superman.txt +1 -0
  152. data/test/fixtures/test-repo/testspec_mixin_new.rb +44 -0
  153. data/test/helper.rb +41 -0
  154. data/test/test_branch_factory.rb +46 -0
  155. data/test/test_changed_file.rb +46 -0
  156. data/test/test_changed_file_factory.rb +16 -0
  157. data/test/test_command.rb +62 -0
  158. data/test/test_commit.rb +66 -0
  159. data/test/test_commit_factory.rb +101 -0
  160. data/test/test_config_file.rb +105 -0
  161. data/test/test_configuration.rb +26 -0
  162. data/test/test_diff.rb +39 -0
  163. data/test/test_diff_factory.rb +38 -0
  164. data/test/test_file_index.rb +113 -0
  165. data/test/test_hook.rb +39 -0
  166. data/test/test_hook_factory.rb +40 -0
  167. data/test/test_manifest.rb +39 -0
  168. data/test/test_node.rb +34 -0
  169. data/test/test_node_factory.rb +125 -0
  170. data/test/test_repository.rb +58 -0
  171. data/test/test_shell.rb +33 -0
  172. data/test/test_tag_factory.rb +27 -0
  173. metadata +328 -0
@@ -0,0 +1,101 @@
1
+ require 'helper'
2
+
3
+ describe Mercurial::CommitFactory do
4
+
5
+ before do
6
+ @repository = Mercurial::Repository.open(Fixtures.test_repo)
7
+ end
8
+
9
+ it "should find commit by hash" do
10
+ commit = @repository.commits.by_hash_id('bc729b15e2b5')
11
+ commit.author.must_equal 'Ilya Sabanin'
12
+ commit.author_email.must_equal 'ilya.sabanin@gmail.com'
13
+ commit.hash_id.must_equal 'bc729b15e2b556065dd4f32c161f54be5dd92776'
14
+ commit.message.must_equal 'Directory added'
15
+ end
16
+
17
+ it "should not find inexistent commit by hash" do
18
+ lambda { @repository.commits.by_hash_id('dfio9sdf78sdfh') }.must_raise Mercurial::CommandError
19
+ end
20
+
21
+ it "should parse commits with big commit messages" do
22
+ commit = @repository.commits.by_hash_id('825fd6032c3b')
23
+ commit.author.must_equal 'Ilya Sabanin'
24
+ commit.author_email.must_equal 'ilya.sabanin@gmail.com'
25
+ commit.hash_id.must_equal '825fd6032c3bbab3677e1890bf05f134a7331533'
26
+ commit.message.must_equal really_long_commit_message
27
+ end
28
+
29
+ it "should find arrays of commits by their hashes" do
30
+ commits = @repository.commits.by_hash_ids(['6157254a4423', 'bf6386c0a0cc'])
31
+ commits.map(&:hash_id).sort.must_equal %w(6157254a442343181939c7af1a744cf2a16afcce bf6386c0a0ccd1282dbbe51888f52fe82b1806e3).sort
32
+ commits.map(&:author_email).uniq.must_equal %w(ilya.sabanin@gmail.com)
33
+ end
34
+
35
+ it "should find many commits with multiple arguments instead of array" do
36
+ commits = @repository.commits.by_hash_ids('6157254a4423', 'bf6386c0a0cc')
37
+ commits.map(&:hash_id).sort.must_equal %w(6157254a442343181939c7af1a744cf2a16afcce bf6386c0a0ccd1282dbbe51888f52fe82b1806e3).sort
38
+ commits.map(&:author_email).uniq.must_equal %w(ilya.sabanin@gmail.com)
39
+ end
40
+
41
+ it "should find all commits" do
42
+ commits = @repository.commits.all
43
+ (commits.size > 5).must_equal true
44
+ end
45
+
46
+ it "should find commits by branch" do
47
+ commits = @repository.commits.by_branch("new-branch")
48
+ commits.size.must_equal 3
49
+ commits.map(&:hash_id).sort.must_equal ["63e18640e83af60196334f16cc31f4f99c419918", "63f70b2314ede1e12813cae87f6f303ee8d5c09a", "bc729b15e2b556065dd4f32c161f54be5dd92776"].sort
50
+ end
51
+
52
+ it "should not find commits for inexistent branch" do
53
+ lambda { @repository.commits.by_branch("shikaka") }.must_raise Mercurial::CommandError
54
+ end
55
+
56
+ it "should find tip commit" do
57
+ tip = @repository.commits.tip
58
+ tip.must_be_kind_of Mercurial::Commit
59
+ end
60
+
61
+ it "should count commits" do
62
+ count = @repository.commits.count
63
+ count.must_equal 36
64
+ end
65
+
66
+ it "should iterate through commits" do
67
+ @repository.commits.each do |c|
68
+ c.must_be_kind_of Mercurial::Commit
69
+ end
70
+ end
71
+
72
+ it "should find commits for range" do
73
+ commits = @repository.commits.for_range('bc729b15e2b5', 'a07263ded072')
74
+ commits.map(&:hash_id).sort.must_equal ['bc729b15e2b556065dd4f32c161f54be5dd92776', '63f70b2314ede1e12813cae87f6f303ee8d5c09a', '6157254a442343181939c7af1a744cf2a16afcce', 'a07263ded0729d146062e6ec076cf1e6af214218'].sort
75
+ end
76
+
77
+ it "should return nil instead of latest commit if it's blank" do
78
+ FileUtils.rm_rf('/tmp/new-crazy-repo')
79
+ Mercurial::Repository.create('/tmp/new-crazy-repo').commits.latest.must_equal nil
80
+ end
81
+
82
+ private
83
+
84
+ def really_long_commit_message
85
+ %q[check-code: disallow use of hasattr()
86
+
87
+ The hasattr() builtin from Python < 3.2 [1] has slightly surprising
88
+ behavior: it catches all exceptions, even KeyboardInterrupt. This
89
+ causes it to have several surprising side effects, such as hiding
90
+ warnings that occur during attribute load and causing mysterious
91
+ failure modes when ^Cing an application. In later versions of Python
92
+ 2.x [0], exception classes which do not inherit from Exception (such
93
+ as SystemExit and KeyboardInterrupt) are not caught, but other types
94
+ of exceptions may still silently cause returning False instead of
95
+ getting a reasonable exception.
96
+
97
+ [0] http://bugs.python.org/issue2196
98
+ [1] http://docs.python.org/dev/whatsnew/3.2.html]
99
+ end
100
+
101
+ end
@@ -0,0 +1,105 @@
1
+ require 'helper'
2
+
3
+ describe Mercurial::ConfigFile do
4
+
5
+ before do
6
+ @repository = Mercurial::Repository.create('/tmp/configfile-test.hg')
7
+ @config = @repository.config
8
+ stub_hgrc(@config.path)
9
+ end
10
+
11
+ after do
12
+ @repository.destroy!
13
+ end
14
+
15
+ it "should state as existing" do
16
+ @config.exists?.must_equal true
17
+ end
18
+
19
+ it "should have content" do
20
+ @config.contents.size.must_equal 324
21
+ end
22
+
23
+ it "should add setting" do
24
+ @config.add_setting('hooks', 'incoming', 'hg update')
25
+ @config.contents.must_equal hgrc_with_incoming_hook_added
26
+ @config.find_header('hooks').size.must_equal 3
27
+ @config.find_setting('hooks', 'incoming').must_equal "incoming = hg update\n"
28
+ @config.find_setting('hooks', 'commit').must_equal "commit =/Users/ilya/work/beanstalk/script/mercurial/commit.rb\n\n"
29
+ @config.find_setting('hooks', 'sfdf').must_equal nil
30
+ end
31
+
32
+ it "should delete settings" do
33
+ @config.delete_setting!('hooks', 'commit')
34
+ @config.contents.must_equal hgrc_with_commit_hook_deleted
35
+ @config.find_header('hooks').size.must_equal 1
36
+ @config.find_setting('hooks', 'commit').must_equal nil
37
+ @config.find_setting('hooks', 'changegroup').must_equal "changegroup = /Users/ilya/work/beanstalk/script/mercurial/changegroup.rb\n"
38
+ end
39
+
40
+ it "should add settings with new header" do
41
+ @config.add_setting('somethingelse', 'shikaka', 'True')
42
+ @config.contents.must_equal hgrc_with_new_standalone_setting
43
+ end
44
+
45
+ it "should add settings even if config is missing" do
46
+ FileUtils.rm_rf('/tmp/another-repo')
47
+ repository = Mercurial::Repository.create('/tmp/another-repo')
48
+ repository.config.add_setting("something", "super", "True")
49
+ repository.config.contents.must_equal "[something]\nsuper = True\n"
50
+ end
51
+
52
+ private
53
+
54
+ def hgrc_with_incoming_hook_added
55
+ %q[[paths]
56
+ default = http://selenic.com/hg
57
+
58
+ [hooks]
59
+ incoming = hg update
60
+ changegroup = /Users/ilya/work/beanstalk/script/mercurial/changegroup.rb
61
+ commit =/Users/ilya/work/beanstalk/script/mercurial/commit.rb
62
+
63
+ [ui]
64
+ username = Firstname Lastname <firstname.lastname@example.net>
65
+ verbose = True
66
+
67
+ # [revlog]
68
+ # format=0 for revlog; format=1 for revlogng]
69
+ end
70
+
71
+ def hgrc_with_commit_hook_deleted
72
+ %q[[paths]
73
+ default = http://selenic.com/hg
74
+
75
+ [hooks]
76
+ changegroup = /Users/ilya/work/beanstalk/script/mercurial/changegroup.rb
77
+ [ui]
78
+ username = Firstname Lastname <firstname.lastname@example.net>
79
+ verbose = True
80
+
81
+ # [revlog]
82
+ # format=0 for revlog; format=1 for revlogng]
83
+ end
84
+
85
+ def hgrc_with_new_standalone_setting
86
+ %q[[paths]
87
+ default = http://selenic.com/hg
88
+
89
+ [hooks]
90
+ changegroup = /Users/ilya/work/beanstalk/script/mercurial/changegroup.rb
91
+ commit =/Users/ilya/work/beanstalk/script/mercurial/commit.rb
92
+
93
+ [ui]
94
+ username = Firstname Lastname <firstname.lastname@example.net>
95
+ verbose = True
96
+
97
+ # [revlog]
98
+ # format=0 for revlog; format=1 for revlogng
99
+
100
+ [somethingelse]
101
+ shikaka = True
102
+ ]
103
+ end
104
+
105
+ end
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ describe Mercurial::Configuration do
4
+
5
+ before do
6
+ @config = Mercurial.configuration
7
+ end
8
+
9
+ after do
10
+ Mercurial.configure do |config|
11
+ config.hg_binary_path = '/usr/local/bin/hg'
12
+ end
13
+ end
14
+
15
+ it "should have default values" do
16
+ @config.hg_binary_path.must_equal '/usr/local/bin/hg'
17
+ end
18
+
19
+ it "should change values with configure block" do
20
+ Mercurial.configure do |config|
21
+ config.hg_binary_path = '/usr/bin/hg'
22
+ end
23
+ @config.hg_binary_path.must_equal '/usr/bin/hg'
24
+ end
25
+
26
+ end
data/test/test_diff.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+
3
+ describe Mercurial::Diff do
4
+
5
+ before do
6
+ @repository = Mercurial::Repository.open(Fixtures.test_repo)
7
+ @commit = @repository.commits.by_hash_id('34f85a44acf1')
8
+ @diff = @commit.diffs.first
9
+ end
10
+
11
+ it "should have hash_a and hash_b" do
12
+ @diff.hash_a.must_equal '25bb5c51fd61'
13
+ @diff.hash_b.must_equal '34f85a44acf1'
14
+ end
15
+
16
+ it "should have file_a and file_b" do
17
+ @diff.file_a.must_equal 'Rakefile'
18
+ @diff.file_b.must_equal 'Rakefile'
19
+ end
20
+
21
+ it "should have body" do
22
+ @diff.body.strip.must_equal expected_diff.strip
23
+ end
24
+
25
+ private
26
+
27
+ def expected_diff
28
+ %q[--- a/Rakefile Thu Jul 28 00:09:22 2011 +0800
29
+ +++ b/Rakefile Thu Jul 28 02:03:13 2011 +0800
30
+ @@ -1,5 +1,7 @@
31
+ # encoding: utf-8
32
+
33
+ +test
34
+ +
35
+ require 'rubygems'
36
+ require 'bundler']
37
+ end
38
+
39
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ describe Mercurial::DiffFactory do
4
+
5
+ before do
6
+ @repository = Mercurial::Repository.open(Fixtures.test_repo)
7
+ end
8
+
9
+ it "should find diffs for commit" do
10
+ commit = @repository.commits.by_hash_id('54d96f4b1a26')
11
+ diffs = @repository.diffs.for_commit(commit)
12
+ diffs.size.must_equal 6
13
+ diffs.map(&:file_name).sort.must_equal ['LICENSE4.txt', 'README.markup', 'Rakefile', 'Rakefile2', 'Rakefile3', 'superman.txt']
14
+ end
15
+
16
+ it "should work for files with dots in their names" do
17
+ commit = @repository.commits.by_hash_id('b66320fa72aa')
18
+ diffs = commit.diffs
19
+ diffs.size.must_equal 1
20
+ diffs.first.file_name.must_equal '.DotFile'
21
+ end
22
+
23
+ it "should handle binary files properly" do
24
+ commit = @repository.commits.by_hash_id('c2b3e46b986e')
25
+ commit.diffs.size.must_equal 1
26
+ diff = commit.diffs.first
27
+ diff.must_be_kind_of Mercurial::Diff
28
+ diff.file_name.must_equal 'goose.png'
29
+ diff.body.must_equal 'Binary files differ'
30
+ diff.binary?.must_equal true
31
+ end
32
+
33
+ it "should handle empty files properly" do
34
+ commit = @repository.commits.by_hash_id('8173f122b0d0')
35
+ commit.diffs.size.must_equal 0
36
+ end
37
+
38
+ end
@@ -0,0 +1,113 @@
1
+ require 'helper'
2
+
3
+ describe Mercurial::FileIndex do
4
+
5
+ before do
6
+ @repository = Mercurial::Repository.open(Fixtures.test_repo)
7
+ @file_index = @repository.file_index
8
+ @file_index.update
9
+ end
10
+
11
+ after do
12
+ @file_index.destroy!
13
+ end
14
+
15
+ it "should update index" do
16
+ File.exists?(@file_index.send(:path)).must_equal true
17
+ end
18
+
19
+ it "should read index even if missing" do
20
+ repository = Mercurial::Repository.create('/tmp/test-repo-bla-bla.hg')
21
+ file_index = repository.file_index
22
+ file_index.count_all.must_equal 0
23
+ repository.destroy!
24
+ end
25
+
26
+ it "should count all commits" do
27
+ @file_index.count_all.must_equal 36
28
+ end
29
+
30
+ it "should count commits reachable by specific hash id" do
31
+ @file_index.count('612af4851a6c483f499cadf1dd28040d7996aa78').must_equal 12
32
+ end
33
+
34
+ it "should return commits that are reachable by specific hash id" do
35
+ commits = @file_index.commits_from('a07263ded0729d146062e6ec076cf1e6af214218')
36
+ commits.must_equal ["a07263ded0729d146062e6ec076cf1e6af214218", "bf6386c0a0ccd1282dbbe51888f52fe82b1806e3"]
37
+ end
38
+
39
+ it "should return files changed at commit" do
40
+ files = @file_index.files('a8b39838302fc5aad12bb6b043331b9ef50149ed')
41
+ files.size.must_equal 2
42
+ files.sort.must_equal ["new-directory/subdirectory/EULA5seat_Chin_Sim02.03.04.pdf", "new-directory/subdirectory/beansprout.png"].sort
43
+ end
44
+
45
+ it "should work with files with white-spaces in names" do
46
+ files = @file_index.files('8ddac5f6380ec3094e6c6bb161d7d90e2de16cb0')
47
+ files.size.must_equal 1
48
+ files.sort.must_equal ["File With Whitespace.pdf"].sort
49
+ end
50
+
51
+ it "should not return files for commit that doesn't exist" do
52
+ files = @file_index.files('f63dvf38302fc5aad12bb6b043331b9ef50149ed')
53
+ files.must_equal []
54
+ end
55
+
56
+ it "should return commits for a file" do
57
+ commits = @file_index.commits_for('LICENSE3.txt')
58
+ commits.must_equal %w(612af4851a6c483f499cadf1dd28040d7996aa78)
59
+ end
60
+
61
+ it "should not return commits for file that doesn't exist" do
62
+ commits = @file_index.commits_for('doesntexist')
63
+ commits.must_equal []
64
+ end
65
+
66
+ it "should return last commits for files" do
67
+ commits = @file_index.last_commits('207476112e024921b1538a096e5f6812d0698cab', ['README.markup'])
68
+ commits.must_equal({ "README.markup" => "54d96f4b1a260dc5614e89c1ed8c2d2edaa4942f" })
69
+
70
+ commits = @file_index.last_commits('bf6386c0a0ccd1282dbbe51888f52fe82b1806e3', ['README.markup'])
71
+ commits.must_equal({})
72
+
73
+ commits = @file_index.last_commits('f2b8b135f3a6f254d5ca20e293bffdad03336e57', ['empty-file', 'goose.png'])
74
+ commits.must_equal({ "goose.png"=>"c2b3e46b986e99220e3d2fdb6e44aedbc94b3a85", "empty-file" => "8173f122b0d061e8d398862f1eaf601babf156aa" })
75
+
76
+ commits = @file_index.last_commits('207476112e024921b1538a096e5f6812d0698cab', ['doesntexist'])
77
+ commits.must_equal({})
78
+ end
79
+
80
+ it "should return last commits with regex" do
81
+ commits = @file_index.last_commits('1b99d0243f8e5542c1b33a013b63130f9009ac52', /^new-directory\/[^\s\/]+\/?$/)
82
+ commits.size.must_equal 1
83
+ commits.values.first.must_equal '4474d1ddaf653cb7fbf18bb62ff1e39a4e571969'
84
+ end
85
+
86
+ it "should update existing index by adding a range of commits to it" do
87
+ File.open(@file_index.path, 'w') do |index_file|
88
+ index_file << preset_sample_index
89
+ end
90
+ @file_index.count_all.must_equal 2
91
+ @file_index.update('63f70b2314ede1e12813cae87f6f303ee8d5c09a', 'a8b39838302fc5aad12bb6b043331b9ef50149ed')
92
+ @file_index.reload
93
+ @file_index.count_all.must_equal 26
94
+ @file_index.instance_variable_get('@commit_index').keys.sort.must_equal(['bf6386c0a0ccd1282dbbe51888f52fe82b1806e3', 'bc729b15e2b556065dd4f32c161f54be5dd92776', '63f70b2314ede1e12813cae87f6f303ee8d5c09a', '6157254a442343181939c7af1a744cf2a16afcce', 'a07263ded0729d146062e6ec076cf1e6af214218', '3cdad3d3ca0054ebfcd2652cc83442bd0d272bbb', '25bb5c51fd613b8b58d88ef1caf99da559af51f3', '63e18640e83af60196334f16cc31f4f99c419918', '8fc3d59965d71a9b83308c53a76f3af0235b6eb6', '0f41dd2ec1667518741da599db7264943c9ed472', '16fac694db0a52edfd266576acafb475f7f8420f', '34f85a44acf11c3386f771a65445d6c39e5261d6', '4474d1ddaf653cb7fbf18bb62ff1e39a4e571969', 'cd9fa0c59c7f189fa1d70edea564e534ac9478d0', '611407bf9b369e061eaf0bee1a261c9e62ad713d', 'd14b0c16b21d9d3e08101ef264959a7d91a8b5db', '3e1ea66bdd04dbfb8d91e4f2de3baca218cd4cca', 'bbfe40f4a56961bdfc6b497a19cc35e18f2d40a3', '4e9f11e95eade74c55fc785e3159015f8a472f4b', '11998206a49ca9a55b4065508ce6ca10945e3e73', '1b99d0243f8e5542c1b33a013b63130f9009ac52', '612af4851a6c483f499cadf1dd28040d7996aa78', '54d96f4b1a260dc5614e89c1ed8c2d2edaa4942f', '207476112e024921b1538a096e5f6812d0698cab', 'ea1e37a728e989176e9e7b33f0d0e035fd347623', 'a8b39838302fc5aad12bb6b043331b9ef50149ed'].sort)
95
+ end
96
+
97
+ private
98
+
99
+ # contains two oldest commits only
100
+ def preset_sample_index
101
+ %q[bf6386c0a0ccd1282dbbe51888f52fe82b1806e3 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 Initial files.
102
+ LICENSE.txt
103
+ README.markdown
104
+ Rakefile
105
+
106
+ bc729b15e2b556065dd4f32c161f54be5dd92776 bf6386c0a0ccd1282dbbe51888f52fe82b1806e3 0000000000000000000000000000000000000000 Directory added
107
+ directory_1/rubygems_dot_org_tasks.rb
108
+ directory_1/rubygems_tasks.rb
109
+ directory_1/specification.rb
110
+ directory_1/tasks.rb]
111
+ end
112
+
113
+ end
data/test/test_hook.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+
3
+ describe Mercurial::Hook do
4
+
5
+ before do
6
+ @repository = Mercurial::Repository.create('/tmp/test-hg-repo')
7
+ stub_hgrc(@repository.config.path)
8
+ @hook = @repository.hooks.by_name('changegroup')
9
+ end
10
+
11
+ after do
12
+ @repository.destroy!
13
+ end
14
+
15
+ it "should have name" do
16
+ @hook.name.must_equal 'changegroup'
17
+ end
18
+
19
+ it "should have value" do
20
+ @hook.value.must_equal '/Users/ilya/work/beanstalk/script/mercurial/changegroup.rb'
21
+ end
22
+
23
+ it "should have repository" do
24
+ @hook.repository.must_equal @repository
25
+ end
26
+
27
+ it "should add itself to the config" do
28
+ hook = Mercurial::Hook.new(@repository, 'outcoming', 'hg update')
29
+ hook.save
30
+ @repository.hooks.by_name('outcoming').value.must_equal 'hg update'
31
+ end
32
+
33
+ it "should remove itself from the config" do
34
+ @hook.destroy!
35
+ @repository.hooks.by_name('changegroup').must_equal nil
36
+ @repository.hooks.by_name('commit').value.must_equal '/Users/ilya/work/beanstalk/script/mercurial/commit.rb'
37
+ end
38
+
39
+ end