rugged 0.18.0.gh.de28323 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. data/README.md +9 -4
  2. data/Rakefile +1 -1
  3. data/ext/rugged/extconf.rb +10 -0
  4. data/ext/rugged/rugged.c +153 -86
  5. data/ext/rugged/rugged.h +44 -33
  6. data/ext/rugged/rugged_blob.c +288 -60
  7. data/ext/rugged/rugged_branch.c +82 -57
  8. data/ext/rugged/rugged_commit.c +83 -86
  9. data/ext/rugged/rugged_config.c +68 -68
  10. data/ext/rugged/rugged_diff.c +509 -0
  11. data/ext/rugged/rugged_diff_delta.c +94 -0
  12. data/ext/rugged/rugged_diff_hunk.c +100 -0
  13. data/ext/rugged/rugged_diff_line.c +79 -0
  14. data/ext/rugged/rugged_diff_patch.c +169 -0
  15. data/ext/rugged/rugged_index.c +539 -8
  16. data/ext/rugged/rugged_note.c +74 -80
  17. data/ext/rugged/rugged_object.c +63 -8
  18. data/ext/rugged/rugged_reference.c +231 -145
  19. data/ext/rugged/rugged_remote.c +509 -53
  20. data/ext/rugged/rugged_repo.c +572 -236
  21. data/ext/rugged/rugged_revwalk.c +59 -36
  22. data/ext/rugged/rugged_settings.c +7 -9
  23. data/ext/rugged/rugged_signature.c +7 -11
  24. data/ext/rugged/rugged_tag.c +93 -39
  25. data/ext/rugged/rugged_tree.c +321 -58
  26. data/lib/rugged.rb +1 -0
  27. data/lib/rugged/commit.rb +16 -1
  28. data/lib/rugged/console.rb +9 -0
  29. data/lib/rugged/diff.rb +19 -0
  30. data/lib/rugged/diff/delta.rb +54 -0
  31. data/lib/rugged/diff/hunk.rb +23 -0
  32. data/lib/rugged/diff/line.rb +29 -0
  33. data/lib/rugged/diff/patch.rb +28 -0
  34. data/lib/rugged/repository.rb +36 -39
  35. data/lib/rugged/version.rb +1 -1
  36. data/test/blob_test.rb +308 -1
  37. data/test/branch_test.rb +7 -0
  38. data/test/commit_test.rb +7 -10
  39. data/test/coverage/cover.rb +9 -1
  40. data/test/diff_test.rb +777 -0
  41. data/test/fixtures/archive.tar.gz +0 -0
  42. data/test/fixtures/attr/attr0 +1 -0
  43. data/test/fixtures/attr/attr1 +29 -0
  44. data/test/fixtures/attr/attr2 +21 -0
  45. data/test/fixtures/attr/attr3 +4 -0
  46. data/test/fixtures/attr/binfile +1 -0
  47. data/test/fixtures/attr/dir/file +0 -0
  48. data/test/fixtures/attr/file +1 -0
  49. data/test/fixtures/attr/gitattributes +29 -0
  50. data/test/fixtures/attr/gitignore +2 -0
  51. data/test/fixtures/attr/ign +1 -0
  52. data/test/fixtures/attr/macro_bad +1 -0
  53. data/test/fixtures/attr/macro_test +1 -0
  54. data/test/fixtures/attr/root_test1 +1 -0
  55. data/test/fixtures/attr/root_test2 +6 -0
  56. data/test/fixtures/attr/root_test3 +19 -0
  57. data/test/fixtures/attr/root_test4.txt +14 -0
  58. data/test/fixtures/attr/sub/abc +37 -0
  59. data/test/fixtures/attr/sub/dir/file +0 -0
  60. data/test/fixtures/attr/sub/file +1 -0
  61. data/test/fixtures/attr/sub/ign/file +1 -0
  62. data/test/fixtures/attr/sub/ign/sub/file +1 -0
  63. data/test/fixtures/attr/sub/sub/dir +0 -0
  64. data/test/fixtures/attr/sub/sub/file +1 -0
  65. data/test/fixtures/attr/sub/sub/subsub.txt +1 -0
  66. data/test/fixtures/attr/sub/subdir_test1 +2 -0
  67. data/test/fixtures/attr/sub/subdir_test2.txt +1 -0
  68. data/test/fixtures/diff/another.txt +38 -0
  69. data/test/fixtures/diff/readme.txt +36 -0
  70. data/test/fixtures/mergedrepo/conflicts-one.txt +5 -0
  71. data/test/fixtures/mergedrepo/conflicts-two.txt +5 -0
  72. data/test/fixtures/mergedrepo/one.txt +10 -0
  73. data/test/fixtures/mergedrepo/two.txt +12 -0
  74. data/test/fixtures/status/current_file +1 -0
  75. data/test/fixtures/status/ignored_file +1 -0
  76. data/test/fixtures/status/modified_file +2 -0
  77. data/test/fixtures/status/new_file +1 -0
  78. data/test/fixtures/status/staged_changes +2 -0
  79. data/test/fixtures/status/staged_changes_modified_file +3 -0
  80. data/test/fixtures/status/staged_delete_modified_file +1 -0
  81. data/test/fixtures/status/staged_new_file +1 -0
  82. data/test/fixtures/status/staged_new_file_modified_file +2 -0
  83. data/test/fixtures/status/subdir.txt +2 -0
  84. data/test/fixtures/status/subdir/current_file +1 -0
  85. data/test/fixtures/status/subdir/modified_file +2 -0
  86. data/test/fixtures/status/subdir/new_file +1 -0
  87. data/test/fixtures/status//350/277/231 +1 -0
  88. data/test/fixtures/testrepo.git/config +5 -0
  89. data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
  90. data/test/fixtures/text_file.md +464 -0
  91. data/test/fixtures/unsymlinked.git/HEAD +1 -0
  92. data/test/fixtures/unsymlinked.git/config +6 -0
  93. data/test/fixtures/unsymlinked.git/description +1 -0
  94. data/test/fixtures/unsymlinked.git/info/exclude +2 -0
  95. data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
  96. data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
  97. data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
  98. data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
  99. data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
  100. data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
  101. data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
  102. data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
  103. data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
  104. data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +2 -0
  105. data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
  106. data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
  107. data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
  108. data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
  109. data/test/fixtures/unsymlinked.git/refs/heads/exe-file +1 -0
  110. data/test/fixtures/unsymlinked.git/refs/heads/master +1 -0
  111. data/test/fixtures/unsymlinked.git/refs/heads/reg-file +1 -0
  112. data/test/index_test.rb +120 -0
  113. data/test/reference_test.rb +38 -3
  114. data/test/remote_test.rb +224 -3
  115. data/test/repo_reset_test.rb +2 -0
  116. data/test/repo_test.rb +147 -10
  117. data/test/test_helper.rb +5 -2
  118. data/vendor/libgit2/include/git2/attr.h +3 -3
  119. data/vendor/libgit2/include/git2/blob.h +11 -17
  120. data/vendor/libgit2/include/git2/branch.h +3 -2
  121. data/vendor/libgit2/include/git2/checkout.h +7 -0
  122. data/vendor/libgit2/include/git2/clone.h +3 -0
  123. data/vendor/libgit2/include/git2/commit.h +61 -66
  124. data/vendor/libgit2/include/git2/common.h +73 -42
  125. data/vendor/libgit2/include/git2/config.h +57 -71
  126. data/vendor/libgit2/include/git2/cred_helpers.h +2 -2
  127. data/vendor/libgit2/include/git2/diff.h +179 -30
  128. data/vendor/libgit2/include/git2/errors.h +3 -3
  129. data/vendor/libgit2/include/git2/index.h +225 -146
  130. data/vendor/libgit2/include/git2/indexer.h +2 -22
  131. data/vendor/libgit2/include/git2/inttypes.h +9 -9
  132. data/vendor/libgit2/include/git2/merge.h +123 -5
  133. data/vendor/libgit2/include/git2/odb.h +59 -38
  134. data/vendor/libgit2/include/git2/odb_backend.h +45 -104
  135. data/vendor/libgit2/include/git2/oid.h +30 -19
  136. data/vendor/libgit2/include/git2/pack.h +21 -3
  137. data/vendor/libgit2/include/git2/refdb.h +0 -35
  138. data/vendor/libgit2/include/git2/refs.h +93 -31
  139. data/vendor/libgit2/include/git2/refspec.h +17 -0
  140. data/vendor/libgit2/include/git2/remote.h +60 -20
  141. data/vendor/libgit2/include/git2/repository.h +48 -70
  142. data/vendor/libgit2/include/git2/reset.h +3 -3
  143. data/vendor/libgit2/include/git2/revparse.h +22 -0
  144. data/vendor/libgit2/include/git2/stash.h +1 -1
  145. data/vendor/libgit2/include/git2/status.h +131 -56
  146. data/vendor/libgit2/include/git2/strarray.h +2 -2
  147. data/vendor/libgit2/include/git2/submodule.h +16 -16
  148. data/vendor/libgit2/include/git2/sys/commit.h +46 -0
  149. data/vendor/libgit2/include/git2/sys/config.h +71 -0
  150. data/vendor/libgit2/include/git2/sys/index.h +179 -0
  151. data/vendor/libgit2/include/git2/sys/odb_backend.h +86 -0
  152. data/vendor/libgit2/include/git2/sys/refdb_backend.h +158 -0
  153. data/vendor/libgit2/include/git2/sys/refs.h +38 -0
  154. data/vendor/libgit2/include/git2/sys/repository.h +106 -0
  155. data/vendor/libgit2/include/git2/tag.h +44 -18
  156. data/vendor/libgit2/include/git2/trace.h +1 -2
  157. data/vendor/libgit2/include/git2/transport.h +74 -0
  158. data/vendor/libgit2/include/git2/tree.h +12 -22
  159. data/vendor/libgit2/include/git2/types.h +33 -0
  160. data/vendor/libgit2/include/git2/version.h +2 -2
  161. data/vendor/libgit2/src/array.h +66 -0
  162. data/vendor/libgit2/src/attr.c +26 -13
  163. data/vendor/libgit2/src/attr_file.c +3 -2
  164. data/vendor/libgit2/src/attr_file.h +3 -3
  165. data/vendor/libgit2/src/attrcache.h +4 -4
  166. data/vendor/libgit2/src/blob.c +13 -9
  167. data/vendor/libgit2/src/blob.h +2 -2
  168. data/vendor/libgit2/src/branch.c +67 -49
  169. data/vendor/libgit2/src/cache.c +224 -54
  170. data/vendor/libgit2/src/cache.h +33 -20
  171. data/vendor/libgit2/src/checkout.c +145 -85
  172. data/vendor/libgit2/src/clone.c +62 -50
  173. data/vendor/libgit2/src/commit.c +74 -40
  174. data/vendor/libgit2/src/commit.h +2 -3
  175. data/vendor/libgit2/src/commit_list.c +14 -8
  176. data/vendor/libgit2/src/config.c +119 -36
  177. data/vendor/libgit2/src/config.h +3 -0
  178. data/vendor/libgit2/src/config_cache.c +24 -7
  179. data/vendor/libgit2/src/config_file.c +9 -6
  180. data/vendor/libgit2/src/crlf.c +4 -2
  181. data/vendor/libgit2/src/date.c +3 -3
  182. data/vendor/libgit2/src/delta.c +1 -1
  183. data/vendor/libgit2/src/diff.c +681 -303
  184. data/vendor/libgit2/src/diff.h +34 -2
  185. data/vendor/libgit2/src/diff_driver.c +405 -0
  186. data/vendor/libgit2/src/diff_driver.h +49 -0
  187. data/vendor/libgit2/src/diff_file.c +447 -0
  188. data/vendor/libgit2/src/diff_file.h +58 -0
  189. data/vendor/libgit2/src/diff_patch.c +995 -0
  190. data/vendor/libgit2/src/diff_patch.h +46 -0
  191. data/vendor/libgit2/src/diff_print.c +430 -0
  192. data/vendor/libgit2/src/diff_tform.c +464 -203
  193. data/vendor/libgit2/src/diff_xdiff.c +166 -0
  194. data/vendor/libgit2/src/diff_xdiff.h +28 -0
  195. data/vendor/libgit2/src/fetch.c +11 -4
  196. data/vendor/libgit2/src/fileops.c +85 -61
  197. data/vendor/libgit2/src/fileops.h +4 -0
  198. data/vendor/libgit2/src/global.c +10 -2
  199. data/vendor/libgit2/src/global.h +0 -8
  200. data/vendor/libgit2/src/hash/hash_generic.h +3 -3
  201. data/vendor/libgit2/src/hash/hash_win32.h +4 -4
  202. data/vendor/libgit2/src/hashsig.c +0 -1
  203. data/vendor/libgit2/src/ignore.c +68 -28
  204. data/vendor/libgit2/src/ignore.h +10 -1
  205. data/vendor/libgit2/src/index.c +666 -84
  206. data/vendor/libgit2/src/index.h +6 -0
  207. data/vendor/libgit2/src/indexer.c +10 -28
  208. data/vendor/libgit2/src/iterator.c +427 -283
  209. data/vendor/libgit2/src/iterator.h +58 -4
  210. data/vendor/libgit2/src/merge.c +1892 -32
  211. data/vendor/libgit2/src/merge.h +132 -5
  212. data/vendor/libgit2/src/merge_file.c +174 -0
  213. data/vendor/libgit2/src/merge_file.h +71 -0
  214. data/vendor/libgit2/src/mwindow.c +1 -1
  215. data/vendor/libgit2/src/notes.c +45 -48
  216. data/vendor/libgit2/src/object.c +89 -127
  217. data/vendor/libgit2/src/object.h +0 -1
  218. data/vendor/libgit2/src/object_api.c +129 -0
  219. data/vendor/libgit2/src/odb.c +156 -59
  220. data/vendor/libgit2/src/odb.h +5 -2
  221. data/vendor/libgit2/src/odb_loose.c +31 -17
  222. data/vendor/libgit2/src/odb_pack.c +39 -43
  223. data/vendor/libgit2/src/oid.c +62 -27
  224. data/vendor/libgit2/src/oid.h +33 -0
  225. data/vendor/libgit2/src/oidmap.h +4 -6
  226. data/vendor/libgit2/src/pack-objects.c +54 -22
  227. data/vendor/libgit2/src/pack.c +98 -56
  228. data/vendor/libgit2/src/pack.h +3 -1
  229. data/vendor/libgit2/src/pathspec.c +26 -1
  230. data/vendor/libgit2/src/pathspec.h +14 -0
  231. data/vendor/libgit2/src/pool.c +5 -0
  232. data/vendor/libgit2/src/posix.c +2 -2
  233. data/vendor/libgit2/src/posix.h +3 -0
  234. data/vendor/libgit2/src/push.c +13 -10
  235. data/vendor/libgit2/src/refdb.c +82 -62
  236. data/vendor/libgit2/src/refdb.h +16 -16
  237. data/vendor/libgit2/src/refdb_fs.c +386 -133
  238. data/vendor/libgit2/src/reflog.c +3 -1
  239. data/vendor/libgit2/src/refs.c +247 -221
  240. data/vendor/libgit2/src/refs.h +2 -1
  241. data/vendor/libgit2/src/refspec.c +18 -1
  242. data/vendor/libgit2/src/refspec.h +3 -1
  243. data/vendor/libgit2/src/remote.c +434 -253
  244. data/vendor/libgit2/src/remote.h +5 -3
  245. data/vendor/libgit2/src/repository.c +197 -111
  246. data/vendor/libgit2/src/repository.h +26 -5
  247. data/vendor/libgit2/src/reset.c +1 -1
  248. data/vendor/libgit2/src/revparse.c +84 -79
  249. data/vendor/libgit2/src/revwalk.c +1 -1
  250. data/vendor/libgit2/src/signature.c +22 -10
  251. data/vendor/libgit2/src/stash.c +5 -2
  252. data/vendor/libgit2/src/status.c +311 -107
  253. data/vendor/libgit2/src/status.h +23 -0
  254. data/vendor/libgit2/src/submodule.c +21 -13
  255. data/vendor/libgit2/src/tag.c +42 -31
  256. data/vendor/libgit2/src/tag.h +2 -3
  257. data/vendor/libgit2/src/thread-utils.h +105 -3
  258. data/vendor/libgit2/src/trace.c +1 -2
  259. data/vendor/libgit2/src/trace.h +3 -3
  260. data/vendor/libgit2/src/transport.c +18 -6
  261. data/vendor/libgit2/src/transports/cred.c +103 -1
  262. data/vendor/libgit2/src/transports/local.c +19 -9
  263. data/vendor/libgit2/src/transports/smart_protocol.c +32 -12
  264. data/vendor/libgit2/src/transports/ssh.c +519 -0
  265. data/vendor/libgit2/src/transports/winhttp.c +3 -1
  266. data/vendor/libgit2/src/tree.c +26 -28
  267. data/vendor/libgit2/src/tree.h +3 -3
  268. data/vendor/libgit2/src/unix/posix.h +2 -0
  269. data/vendor/libgit2/src/util.c +43 -6
  270. data/vendor/libgit2/src/util.h +40 -12
  271. data/vendor/libgit2/src/vector.c +3 -5
  272. data/vendor/libgit2/src/vector.h +9 -0
  273. data/vendor/libgit2/src/win32/dir.c +1 -1
  274. data/vendor/libgit2/src/win32/error.c +2 -0
  275. data/vendor/libgit2/src/win32/findfile.c +3 -6
  276. data/vendor/libgit2/src/win32/posix_w32.c +85 -59
  277. data/vendor/libgit2/src/win32/pthread.c +16 -8
  278. data/vendor/libgit2/src/win32/pthread.h +7 -4
  279. metadata +407 -306
  280. data/test/coverage/HEAD.json +0 -1
  281. data/vendor/libgit2/include/git2/refdb_backend.h +0 -109
  282. data/vendor/libgit2/src/diff_output.c +0 -1819
  283. data/vendor/libgit2/src/diff_output.h +0 -93
@@ -1,3 +1,5 @@
1
+ require "test_helper"
2
+
1
3
  class RepositoryResetTest < Rugged::TestCase
2
4
  include Rugged::TempRepositoryAccess
3
5
 
data/test/repo_test.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  require 'test_helper'
2
2
  require 'base64'
3
3
 
4
- class RepositoryTest < Rugged::TestCase
5
- include Rugged::RepositoryAccess
4
+ class RepositoryTest < Rugged::SandboxedTestCase
5
+ def setup
6
+ super
7
+
8
+ @repo = sandbox_init "testrepo.git"
9
+ end
6
10
 
7
11
  def test_last_commit
8
12
  assert @repo.respond_to? :last_commit
@@ -78,8 +82,8 @@ class RepositoryTest < Rugged::TestCase
78
82
  end
79
83
 
80
84
  def test_match_all_refs
81
- refs = @repo.refs 'refs/heads'
82
- assert_equal 2, refs.length
85
+ refs = @repo.refs 'refs/heads/*'
86
+ assert_equal 2, refs.count
83
87
  end
84
88
 
85
89
  def test_return_all_ref_names
@@ -100,40 +104,58 @@ class RepositoryTest < Rugged::TestCase
100
104
 
101
105
  def test_return_all_remotes
102
106
  remotes = @repo.remotes
103
- assert_equal 1, remotes.count
107
+ assert_equal 2, remotes.count
104
108
  end
105
109
 
106
110
  def test_lookup_head
107
111
  head = @repo.head
112
+ assert_equal "refs/heads/master", head.name
108
113
  assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", head.target
109
114
  assert_equal :direct, head.type
110
115
  end
111
116
 
117
+ def test_set_head_ref
118
+ @repo.head = "refs/heads/packed"
119
+ assert_equal "refs/heads/packed", @repo.head.name
120
+ end
121
+
122
+ def test_set_head_invalid
123
+ assert_raises Rugged::ReferenceError do
124
+ @repo.head = "36060c58702ed4c2a40832c51758d5344201d89a"
125
+ end
126
+ end
127
+
112
128
  def test_access_a_file
113
129
  sha = '36060c58702ed4c2a40832c51758d5344201d89a'
114
130
  blob = @repo.blob_at(sha, 'new.txt')
115
131
  assert_equal "new file\n", blob.content
116
132
  end
117
133
 
134
+ def test_access_a_missing_file
135
+ sha = '36060c58702ed4c2a40832c51758d5344201d89a'
136
+ blob = @repo.blob_at(sha, 'file-not-found.txt')
137
+ assert_nil blob
138
+ end
139
+
118
140
  def test_garbage_collection
119
- Rugged::Repository.new(@path)
141
+ Rugged::Repository.new(@repo.path)
120
142
  ObjectSpace.garbage_collect
121
143
  end
122
144
 
123
145
  def test_enumerate_all_objects
124
- assert_equal 36, @repo.each_id.to_a.length
146
+ assert_equal 37, @repo.each_id.to_a.length
125
147
  end
126
148
 
127
149
  def test_loading_alternates
128
150
  alt_path = File.dirname(__FILE__) + '/fixtures/alternate/objects'
129
- repo = Rugged::Repository.new(@path, :alternates => [alt_path])
130
- assert_equal 39, repo.each_id.to_a.length
151
+ repo = Rugged::Repository.new(@repo.path, :alternates => [alt_path])
152
+ assert_equal 40, repo.each_id.to_a.length
131
153
  assert repo.read('146ae76773c91e3b1d00cf7a338ec55ae58297e2')
132
154
  end
133
155
 
134
156
  def test_alternates_with_invalid_path_type
135
157
  assert_raises TypeError do
136
- Rugged::Repository.new(@path, :alternates => [:invalid_input])
158
+ Rugged::Repository.new(@repo.path, :alternates => [:invalid_input])
137
159
  end
138
160
  end
139
161
 
@@ -157,6 +179,33 @@ class RepositoryTest < Rugged::TestCase
157
179
  base = '5b5b025afb0b4c913b4c338a42934a3863bf3644'
158
180
  assert_equal base, @repo.merge_base(commit1, commit2)
159
181
  end
182
+
183
+ def test_find_merge_base_between_many
184
+ commit1 = 'a4a7dce85cf63874e984719f4fdd239f5145052f'
185
+ commit2 = "refs/heads/packed"
186
+ commit3 = @repo.lookup('36060c58702ed4c2a40832c51758d5344201d89a')
187
+
188
+ base = '5b5b025afb0b4c913b4c338a42934a3863bf3644'
189
+ assert_equal base, @repo.merge_base(commit1, commit2, commit3)
190
+ end
191
+
192
+ def test_ahead_behind_with_oids
193
+ ahead, behind = @repo.ahead_behind(
194
+ 'a4a7dce85cf63874e984719f4fdd239f5145052f',
195
+ '36060c58702ed4c2a40832c51758d5344201d89a'
196
+ )
197
+ assert_equal 1, ahead
198
+ assert_equal 4, behind
199
+ end
200
+
201
+ def test_ahead_behind_with_commits
202
+ ahead, behind = @repo.ahead_behind(
203
+ @repo.lookup('a4a7dce85cf63874e984719f4fdd239f5145052f'),
204
+ @repo.lookup('36060c58702ed4c2a40832c51758d5344201d89a')
205
+ )
206
+ assert_equal 1, ahead
207
+ assert_equal 4, behind
208
+ end
160
209
  end
161
210
 
162
211
  class RepositoryWriteTest < Rugged::TestCase
@@ -213,6 +262,94 @@ class RepositoryInitTest < Rugged::TestCase
213
262
  end
214
263
  end
215
264
 
265
+ class RepositoryCloneTest < Rugged::TestCase
266
+ def setup
267
+ @tmppath = Dir.mktmpdir
268
+ @source_path = File.join(Rugged::TestCase::TEST_DIR, 'fixtures', 'testrepo.git')
269
+ end
270
+
271
+ def teardown
272
+ FileUtils.remove_entry_secure(@tmppath)
273
+ end
274
+
275
+ def test_clone
276
+ repo = Rugged::Repository.clone_at(@source_path, @tmppath)
277
+ assert_equal "hey", File.read(File.join(@tmppath, "README")).chomp
278
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.head.target
279
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/heads/master").target
280
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/remotes/origin/master").target
281
+ assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.ref("refs/remotes/origin/packed").target
282
+ end
283
+
284
+ def test_clone_bare
285
+ repo = Rugged::Repository.clone_at(@source_path, @tmppath, :bare => true)
286
+ assert repo.bare?
287
+ end
288
+
289
+ def test_clone_with_progress
290
+ total_objects = indexed_objects = received_objects = received_bytes = nil
291
+ callsback = 0
292
+ Rugged::Repository.clone_at(@source_path, @tmppath,
293
+ :progress => lambda { |*args| callsback += 1 ; total_objects, indexed_objects, received_objects, received_bytes = args })
294
+ assert_equal 22, callsback
295
+ assert_equal 19, total_objects
296
+ assert_equal 19, indexed_objects
297
+ assert_equal 19, received_objects
298
+ assert_equal 1563, received_bytes
299
+ end
300
+
301
+ def test_clone_quits_on_error
302
+ begin
303
+ Rugged::Repository.clone_at(@source_path, @tmppath, :progress => lambda { |*_| raise 'boom' })
304
+ rescue => e
305
+ assert_equal 'boom', e.message
306
+ end
307
+ assert_no_dotgit_dir(@tmppath)
308
+ end
309
+
310
+ def test_clone_with_bad_progress_callback
311
+ assert_raises ArgumentError do
312
+ Rugged::Repository.clone_at(@source_path, @tmppath, :progress => Object.new)
313
+ end
314
+ assert_no_dotgit_dir(@tmppath)
315
+ end
316
+
317
+ def assert_no_dotgit_dir(path)
318
+ assert_equal [], Dir[File.join(path, ".git/**")], "new repository's .git dir should not exist"
319
+ end
320
+ end
321
+
322
+ class RepositoryNamespaceTest < Rugged::SandboxedTestCase
323
+ def setup
324
+ super
325
+
326
+ @repo = sandbox_init("testrepo.git")
327
+ end
328
+
329
+ def test_no_namespace
330
+ assert_nil @repo.namespace
331
+ end
332
+
333
+ def test_changing_namespace
334
+ @repo.namespace = "foo"
335
+ assert_equal "foo", @repo.namespace
336
+
337
+ @repo.namespace = "bar"
338
+ assert_equal "bar", @repo.namespace
339
+
340
+ @repo.namespace = "foo/bar"
341
+ assert_equal "foo/bar", @repo.namespace
342
+
343
+ @repo.namespace = nil
344
+ assert_equal nil, @repo.namespace
345
+ end
346
+
347
+ def test_refs_in_namespaces
348
+ @repo.namespace = "foo"
349
+ assert_equal [], @repo.refs.to_a
350
+ end
351
+ end
352
+
216
353
  class RepositoryPushTest < Rugged::SandboxedTestCase
217
354
  def setup
218
355
  super
data/test/test_helper.rb CHANGED
@@ -8,6 +8,9 @@ require 'pp'
8
8
 
9
9
  module Rugged
10
10
  class TestCase < MiniTest::Unit::TestCase
11
+ # Ruby 1.8 / 1.9 Shim
12
+ Enumerator = defined?(::Enumerator) ? ::Enumerator : ::Enumerable::Enumerator
13
+
11
14
  TEST_DIR = File.dirname(File.expand_path(__FILE__))
12
15
 
13
16
  protected
@@ -65,12 +68,12 @@ module Rugged
65
68
  end
66
69
 
67
70
  module TempRepositoryAccess
68
- def setup
71
+ def setup
69
72
  @path = temp_repo("testrepo.git")
70
73
  @repo = Rugged::Repository.new(@path)
71
74
  end
72
75
 
73
- def teardown
76
+ def teardown
74
77
  destroy_temp_repo(@path)
75
78
  end
76
79
 
@@ -141,7 +141,7 @@ GIT_EXTERN(git_attr_t) git_attr_value(const char *attr);
141
141
  */
142
142
  GIT_EXTERN(int) git_attr_get(
143
143
  const char **value_out,
144
- git_repository *repo,
144
+ git_repository *repo,
145
145
  uint32_t flags,
146
146
  const char *path,
147
147
  const char *name);
@@ -162,7 +162,7 @@ GIT_EXTERN(int) git_attr_get(
162
162
  * Then you could loop through the 3 values to get the settings for
163
163
  * the three attributes you asked about.
164
164
  *
165
- * @param values An array of num_attr entries that will have string
165
+ * @param values_out An array of num_attr entries that will have string
166
166
  * pointers written into it for the values of the attributes.
167
167
  * You should not modify or free the values that are written
168
168
  * into this array (although of course, you should free the
@@ -228,7 +228,7 @@ GIT_EXTERN(void) git_attr_cache_flush(
228
228
  * function allows you to add others. For example, to add the default
229
229
  * macro, you would call:
230
230
  *
231
- * git_attr_add_macro(repo, "binary", "-diff -crlf");
231
+ * git_attr_add_macro(repo, "binary", "-diff -crlf");
232
232
  */
233
233
  GIT_EXTERN(int) git_attr_add_macro(
234
234
  git_repository *repo,
@@ -29,10 +29,7 @@ GIT_BEGIN_DECL
29
29
  * @param id identity of the blob to locate.
30
30
  * @return 0 or an error code
31
31
  */
32
- GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id)
33
- {
34
- return git_object_lookup((git_object **)blob, repo, id, GIT_OBJ_BLOB);
35
- }
32
+ GIT_EXTERN(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id);
36
33
 
37
34
  /**
38
35
  * Lookup a blob object from a repository,
@@ -46,10 +43,7 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
46
43
  * @param len the length of the short identifier
47
44
  * @return 0 or an error code
48
45
  */
49
- GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len)
50
- {
51
- return git_object_lookup_prefix((git_object **)blob, repo, id, len, GIT_OBJ_BLOB);
52
- }
46
+ GIT_EXTERN(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len);
53
47
 
54
48
  /**
55
49
  * Close an open blob
@@ -62,11 +56,7 @@ GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, co
62
56
  *
63
57
  * @param blob the blob to close
64
58
  */
65
-
66
- GIT_INLINE(void) git_blob_free(git_blob *blob)
67
- {
68
- git_object_free((git_object *) blob);
69
- }
59
+ GIT_EXTERN(void) git_blob_free(git_blob *blob);
70
60
 
71
61
  /**
72
62
  * Get the id of a blob.
@@ -74,11 +64,15 @@ GIT_INLINE(void) git_blob_free(git_blob *blob)
74
64
  * @param blob a previously loaded blob.
75
65
  * @return SHA1 hash for this blob.
76
66
  */
77
- GIT_INLINE(const git_oid *) git_blob_id(const git_blob *blob)
78
- {
79
- return git_object_id((const git_object *)blob);
80
- }
67
+ GIT_EXTERN(const git_oid *) git_blob_id(const git_blob *blob);
81
68
 
69
+ /**
70
+ * Get the repository that contains the blob.
71
+ *
72
+ * @param blob A previously loaded blob.
73
+ * @return Repository that contains this blob.
74
+ */
75
+ GIT_EXTERN(git_repository *) git_blob_owner(const git_blob *blob);
82
76
 
83
77
  /**
84
78
  * Get a read-only buffer with the raw content of a blob.
@@ -58,7 +58,8 @@ GIT_EXTERN(int) git_branch_create(
58
58
  * Delete an existing branch reference.
59
59
  *
60
60
  * If the branch is successfully deleted, the passed reference
61
- * object will be freed and invalidated.
61
+ * object will be invalidated. The reference must be freed manually
62
+ * by the user.
62
63
  *
63
64
  * @param branch A valid reference representing a branch
64
65
  * @return 0 on success, or an error code.
@@ -237,7 +238,7 @@ GIT_EXTERN(int) git_branch_is_head(
237
238
  *
238
239
  * @return Number of characters in the reference name
239
240
  * including the trailing NUL byte; GIT_ENOTFOUND
240
- * when no remote matching remote was gound,
241
+ * when no remote matching remote was found,
241
242
  * GIT_EAMBIGUOUS when the branch maps to several remotes,
242
243
  * otherwise an error code.
243
244
  */
@@ -134,6 +134,9 @@ typedef enum {
134
134
  /** Treat pathspec as simple list of exact match file paths */
135
135
  GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH = (1u << 13),
136
136
 
137
+ /** Ignore directories in use, they will be left empty */
138
+ GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES = (1u << 18),
139
+
137
140
  /**
138
141
  * THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
139
142
  */
@@ -180,6 +183,8 @@ typedef enum {
180
183
  GIT_CHECKOUT_NOTIFY_UPDATED = (1u << 2),
181
184
  GIT_CHECKOUT_NOTIFY_UNTRACKED = (1u << 3),
182
185
  GIT_CHECKOUT_NOTIFY_IGNORED = (1u << 4),
186
+
187
+ GIT_CHECKOUT_NOTIFY_ALL = 0x0FFFFu
183
188
  } git_checkout_notify_t;
184
189
 
185
190
  /** Checkout notification callback function */
@@ -231,6 +236,8 @@ typedef struct git_checkout_opts {
231
236
  git_strarray paths;
232
237
 
233
238
  git_tree *baseline; /** expected content of workdir, defaults to HEAD */
239
+
240
+ const char *target_directory; /** alternative checkout path to workdir */
234
241
  } git_checkout_opts;
235
242
 
236
243
  #define GIT_CHECKOUT_OPTS_VERSION 1
@@ -51,6 +51,8 @@ GIT_BEGIN_DECL
51
51
  * - `cred_acquire_cb` is a callback to be used if credentials are required
52
52
  * during the initial fetch.
53
53
  * - `cred_acquire_payload` is the payload for the above callback.
54
+ * - `transport_flags` is flags used to create transport if no transport is
55
+ * provided.
54
56
  * - `transport` is a custom transport to be used for the initial fetch. NULL
55
57
  * means use the transport autodetected from the URL.
56
58
  * - `remote_callbacks` may be used to specify custom progress callbacks for
@@ -75,6 +77,7 @@ typedef struct git_clone_options {
75
77
  const char *push_spec;
76
78
  git_cred_acquire_cb cred_acquire_cb;
77
79
  void *cred_acquire_payload;
80
+ git_transport_flags_t transport_flags;
78
81
  git_transport *transport;
79
82
  git_remote_callbacks *remote_callbacks;
80
83
  git_remote_autotag_option_t remote_autotag;
@@ -30,10 +30,7 @@ GIT_BEGIN_DECL
30
30
  * an annotated tag it will be peeled back to the commit.
31
31
  * @return 0 or an error code
32
32
  */
33
- GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id)
34
- {
35
- return git_object_lookup((git_object **)commit, repo, id, GIT_OBJ_COMMIT);
36
- }
33
+ GIT_EXTERN(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id);
37
34
 
38
35
  /**
39
36
  * Lookup a commit object from a repository,
@@ -48,10 +45,7 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con
48
45
  * @param len the length of the short identifier
49
46
  * @return 0 or an error code
50
47
  */
51
- GIT_INLINE(int) git_commit_lookup_prefix(git_commit **commit, git_repository *repo, const git_oid *id, size_t len)
52
- {
53
- return git_object_lookup_prefix((git_object **)commit, repo, id, len, GIT_OBJ_COMMIT);
54
- }
48
+ GIT_EXTERN(int) git_commit_lookup_prefix(git_commit **commit, git_repository *repo, const git_oid *id, size_t len);
55
49
 
56
50
  /**
57
51
  * Close an open commit
@@ -65,10 +59,7 @@ GIT_INLINE(int) git_commit_lookup_prefix(git_commit **commit, git_repository *re
65
59
  * @param commit the commit to close
66
60
  */
67
61
 
68
- GIT_INLINE(void) git_commit_free(git_commit *commit)
69
- {
70
- git_object_free((git_object *) commit);
71
- }
62
+ GIT_EXTERN(void) git_commit_free(git_commit *commit);
72
63
 
73
64
  /**
74
65
  * Get the id of a commit.
@@ -76,10 +67,15 @@ GIT_INLINE(void) git_commit_free(git_commit *commit)
76
67
  * @param commit a previously loaded commit.
77
68
  * @return object identity for the commit.
78
69
  */
79
- GIT_INLINE(const git_oid *) git_commit_id(const git_commit *commit)
80
- {
81
- return git_object_id((const git_object *)commit);
82
- }
70
+ GIT_EXTERN(const git_oid *) git_commit_id(const git_commit *commit);
71
+
72
+ /**
73
+ * Get the repository that contains the commit.
74
+ *
75
+ * @param commit A previously loaded commit.
76
+ * @return Repository that contains this commit.
77
+ */
78
+ GIT_EXTERN(git_repository *) git_commit_owner(const git_commit *commit);
83
79
 
84
80
  /**
85
81
  * Get the encoding for the message of a commit,
@@ -168,7 +164,10 @@ GIT_EXTERN(unsigned int) git_commit_parentcount(const git_commit *commit);
168
164
  * @param n the position of the parent (from 0 to `parentcount`)
169
165
  * @return 0 or an error code
170
166
  */
171
- GIT_EXTERN(int) git_commit_parent(git_commit **out, git_commit *commit, unsigned int n);
167
+ GIT_EXTERN(int) git_commit_parent(
168
+ git_commit **out,
169
+ const git_commit *commit,
170
+ unsigned int n);
172
171
 
173
172
  /**
174
173
  * Get the oid of a specified parent for a commit. This is different from
@@ -179,7 +178,9 @@ GIT_EXTERN(int) git_commit_parent(git_commit **out, git_commit *commit, unsigned
179
178
  * @param n the position of the parent (from 0 to `parentcount`)
180
179
  * @return the id of the parent, NULL on error.
181
180
  */
182
- GIT_EXTERN(const git_oid *) git_commit_parent_id(git_commit *commit, unsigned int n);
181
+ GIT_EXTERN(const git_oid *) git_commit_parent_id(
182
+ const git_commit *commit,
183
+ unsigned int n);
183
184
 
184
185
  /**
185
186
  * Get the commit object that is the <n>th generation ancestor
@@ -201,14 +202,12 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
201
202
  unsigned int n);
202
203
 
203
204
  /**
204
- * Create a new commit in the repository using `git_object`
205
- * instances as parameters.
205
+ * Create new commit in the repository from a list of `git_object` pointers
206
206
  *
207
- * The message will not be cleaned up. This can be achieved
208
- * through `git_message_prettify()`.
207
+ * The message will not be cleaned up automatically. You can do that with
208
+ * the `git_message_prettify()` function.
209
209
  *
210
- * @param id Pointer where to store the OID of the
211
- * newly created commit
210
+ * @param id Pointer in which to store the OID of the newly created commit
212
211
  *
213
212
  * @param repo Repository where to store the commit
214
213
  *
@@ -219,73 +218,69 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
219
218
  * make it point to this commit. If the reference doesn't
220
219
  * exist yet, it will be created.
221
220
  *
222
- * @param author Signature representing the author and the authory
223
- * time of this commit
221
+ * @param author Signature with author and author time of commit
224
222
  *
225
- * @param committer Signature representing the committer and the
226
- * commit time of this commit
223
+ * @param committer Signature with committer and * commit time of commit
227
224
  *
228
225
  * @param message_encoding The encoding for the message in the
229
- * commit, represented with a standard encoding name.
230
- * E.g. "UTF-8". If NULL, no encoding header is written and
231
- * UTF-8 is assumed.
226
+ * commit, represented with a standard encoding name.
227
+ * E.g. "UTF-8". If NULL, no encoding header is written and
228
+ * UTF-8 is assumed.
232
229
  *
233
230
  * @param message Full message for this commit
234
231
  *
235
232
  * @param tree An instance of a `git_tree` object that will
236
- * be used as the tree for the commit. This tree object must
237
- * also be owned by the given `repo`.
233
+ * be used as the tree for the commit. This tree object must
234
+ * also be owned by the given `repo`.
238
235
  *
239
236
  * @param parent_count Number of parents for this commit
240
237
  *
241
- * @param parents[] Array of `parent_count` pointers to `git_commit`
242
- * objects that will be used as the parents for this commit. This
243
- * array may be NULL if `parent_count` is 0 (root commit). All the
244
- * given commits must be owned by the `repo`.
238
+ * @param parents Array of `parent_count` pointers to `git_commit`
239
+ * objects that will be used as the parents for this commit. This
240
+ * array may be NULL if `parent_count` is 0 (root commit). All the
241
+ * given commits must be owned by the `repo`.
245
242
  *
246
243
  * @return 0 or an error code
247
244
  * The created commit will be written to the Object Database and
248
245
  * the given reference will be updated to point to it
249
246
  */
250
247
  GIT_EXTERN(int) git_commit_create(
251
- git_oid *id,
252
- git_repository *repo,
253
- const char *update_ref,
254
- const git_signature *author,
255
- const git_signature *committer,
256
- const char *message_encoding,
257
- const char *message,
258
- const git_tree *tree,
259
- int parent_count,
260
- const git_commit *parents[]);
248
+ git_oid *id,
249
+ git_repository *repo,
250
+ const char *update_ref,
251
+ const git_signature *author,
252
+ const git_signature *committer,
253
+ const char *message_encoding,
254
+ const char *message,
255
+ const git_tree *tree,
256
+ int parent_count,
257
+ const git_commit *parents[]);
261
258
 
262
259
  /**
263
- * Create a new commit in the repository using a variable
264
- * argument list.
260
+ * Create new commit in the repository using a variable argument list.
265
261
  *
266
- * The message will be cleaned up from excess whitespace
267
- * it will be made sure that the last line ends with a '\n'.
262
+ * The message will be cleaned up from excess whitespace and it will be made
263
+ * sure that the last line ends with a '\n'.
268
264
  *
269
- * The parents for the commit are specified as a variable
270
- * list of pointers to `const git_commit *`. Note that this
271
- * is a convenience method which may not be safe to export
272
- * for certain languages or compilers
265
+ * The parents for the commit are specified as a variable list of pointers
266
+ * to `const git_commit *`. Note that this is a convenience method which may
267
+ * not be safe to export for certain languages or compilers
273
268
  *
274
- * All other parameters remain the same
269
+ * All other parameters remain the same at `git_commit_create()`.
275
270
  *
276
271
  * @see git_commit_create
277
272
  */
278
273
  GIT_EXTERN(int) git_commit_create_v(
279
- git_oid *id,
280
- git_repository *repo,
281
- const char *update_ref,
282
- const git_signature *author,
283
- const git_signature *committer,
284
- const char *message_encoding,
285
- const char *message,
286
- const git_tree *tree,
287
- int parent_count,
288
- ...);
274
+ git_oid *id,
275
+ git_repository *repo,
276
+ const char *update_ref,
277
+ const git_signature *author,
278
+ const git_signature *committer,
279
+ const char *message_encoding,
280
+ const char *message,
281
+ const git_tree *tree,
282
+ int parent_count,
283
+ ...);
289
284
 
290
285
  /** @} */
291
286
  GIT_END_DECL