rugged 0.17.0.b7 → 0.18.0.b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. data/LICENSE +1 -1
  2. data/README.md +88 -32
  3. data/ext/rugged/extconf.rb +4 -2
  4. data/ext/rugged/rugged.c +72 -10
  5. data/ext/rugged/rugged.h +14 -10
  6. data/ext/rugged/rugged_blob.c +8 -10
  7. data/ext/rugged/rugged_branch.c +11 -14
  8. data/ext/rugged/rugged_commit.c +31 -24
  9. data/ext/rugged/rugged_config.c +2 -2
  10. data/ext/rugged/rugged_index.c +133 -198
  11. data/ext/rugged/rugged_note.c +372 -0
  12. data/ext/rugged/rugged_object.c +50 -22
  13. data/ext/rugged/rugged_reference.c +122 -130
  14. data/ext/rugged/rugged_remote.c +72 -29
  15. data/ext/rugged/rugged_repo.c +402 -20
  16. data/ext/rugged/rugged_revwalk.c +7 -3
  17. data/ext/rugged/rugged_settings.c +110 -0
  18. data/ext/rugged/rugged_signature.c +23 -7
  19. data/ext/rugged/rugged_tag.c +32 -16
  20. data/ext/rugged/rugged_tree.c +44 -15
  21. data/lib/rugged.rb +1 -0
  22. data/lib/rugged/index.rb +8 -0
  23. data/lib/rugged/remote.rb +13 -0
  24. data/lib/rugged/repository.rb +3 -3
  25. data/lib/rugged/version.rb +1 -1
  26. data/test/blob_test.rb +13 -15
  27. data/test/branch_test.rb +32 -67
  28. data/test/commit_test.rb +50 -12
  29. data/test/config_test.rb +12 -11
  30. data/test/coverage/HEAD.json +1 -1
  31. data/test/coverage/cover.rb +40 -21
  32. data/test/errors_test.rb +34 -0
  33. data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
  34. data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
  35. data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
  36. data/test/fixtures/testrepo.git/logs/refs/notes/commits +1 -0
  37. data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +1 -0
  38. data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
  39. data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +1 -0
  40. data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
  41. data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
  42. data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +3 -0
  43. data/test/fixtures/testrepo.git/refs/notes/commits +1 -0
  44. data/test/index_test.rb +65 -69
  45. data/test/lib_test.rb +76 -11
  46. data/test/note_test.rb +158 -0
  47. data/test/object_test.rb +8 -11
  48. data/test/reference_test.rb +77 -85
  49. data/test/remote_test.rb +86 -8
  50. data/test/repo_pack_test.rb +9 -7
  51. data/test/repo_reset_test.rb +80 -0
  52. data/test/repo_test.rb +176 -53
  53. data/test/tag_test.rb +44 -7
  54. data/test/test_helper.rb +63 -35
  55. data/test/tree_test.rb +34 -13
  56. data/test/walker_test.rb +14 -14
  57. data/vendor/libgit2/Makefile.embed +1 -1
  58. data/vendor/libgit2/deps/http-parser/http_parser.c +974 -578
  59. data/vendor/libgit2/deps/http-parser/http_parser.h +106 -70
  60. data/vendor/libgit2/deps/regex/regcomp.c +7 -6
  61. data/vendor/libgit2/deps/regex/regex_internal.c +1 -1
  62. data/vendor/libgit2/deps/regex/regex_internal.h +12 -3
  63. data/vendor/libgit2/deps/regex/regexec.c +5 -5
  64. data/vendor/libgit2/include/git2.h +5 -1
  65. data/vendor/libgit2/include/git2/attr.h +4 -2
  66. data/vendor/libgit2/include/git2/blob.h +39 -12
  67. data/vendor/libgit2/include/git2/branch.h +123 -35
  68. data/vendor/libgit2/include/git2/checkout.h +206 -48
  69. data/vendor/libgit2/include/git2/clone.h +72 -27
  70. data/vendor/libgit2/include/git2/commit.h +20 -17
  71. data/vendor/libgit2/include/git2/common.h +67 -1
  72. data/vendor/libgit2/include/git2/config.h +81 -60
  73. data/vendor/libgit2/include/git2/cred_helpers.h +53 -0
  74. data/vendor/libgit2/include/git2/diff.h +459 -150
  75. data/vendor/libgit2/include/git2/errors.h +9 -1
  76. data/vendor/libgit2/include/git2/graph.h +41 -0
  77. data/vendor/libgit2/include/git2/ignore.h +7 -6
  78. data/vendor/libgit2/include/git2/index.h +323 -97
  79. data/vendor/libgit2/include/git2/indexer.h +27 -59
  80. data/vendor/libgit2/include/git2/inttypes.h +4 -0
  81. data/vendor/libgit2/include/git2/merge.h +13 -3
  82. data/vendor/libgit2/include/git2/message.h +14 -8
  83. data/vendor/libgit2/include/git2/net.h +9 -7
  84. data/vendor/libgit2/include/git2/notes.h +88 -29
  85. data/vendor/libgit2/include/git2/object.h +16 -6
  86. data/vendor/libgit2/include/git2/odb.h +80 -17
  87. data/vendor/libgit2/include/git2/odb_backend.h +47 -11
  88. data/vendor/libgit2/include/git2/oid.h +26 -17
  89. data/vendor/libgit2/include/git2/pack.h +62 -8
  90. data/vendor/libgit2/include/git2/push.h +131 -0
  91. data/vendor/libgit2/include/git2/refdb.h +103 -0
  92. data/vendor/libgit2/include/git2/refdb_backend.h +109 -0
  93. data/vendor/libgit2/include/git2/reflog.h +30 -21
  94. data/vendor/libgit2/include/git2/refs.h +215 -193
  95. data/vendor/libgit2/include/git2/refspec.h +22 -2
  96. data/vendor/libgit2/include/git2/remote.h +158 -37
  97. data/vendor/libgit2/include/git2/repository.h +150 -31
  98. data/vendor/libgit2/include/git2/reset.h +43 -9
  99. data/vendor/libgit2/include/git2/revparse.h +48 -4
  100. data/vendor/libgit2/include/git2/revwalk.h +25 -10
  101. data/vendor/libgit2/include/git2/signature.h +20 -12
  102. data/vendor/libgit2/include/git2/stash.h +121 -0
  103. data/vendor/libgit2/include/git2/status.h +122 -53
  104. data/vendor/libgit2/include/git2/strarray.h +17 -11
  105. data/vendor/libgit2/include/git2/submodule.h +42 -7
  106. data/vendor/libgit2/include/git2/tag.h +72 -59
  107. data/vendor/libgit2/include/git2/threads.h +4 -2
  108. data/vendor/libgit2/include/git2/trace.h +68 -0
  109. data/vendor/libgit2/include/git2/transport.h +328 -0
  110. data/vendor/libgit2/include/git2/tree.h +149 -120
  111. data/vendor/libgit2/include/git2/types.h +13 -12
  112. data/vendor/libgit2/include/git2/version.h +3 -3
  113. data/vendor/libgit2/src/amiga/map.c +2 -2
  114. data/vendor/libgit2/src/attr.c +58 -48
  115. data/vendor/libgit2/src/attr.h +4 -18
  116. data/vendor/libgit2/src/attr_file.c +30 -6
  117. data/vendor/libgit2/src/attr_file.h +6 -8
  118. data/vendor/libgit2/src/attrcache.h +24 -0
  119. data/vendor/libgit2/src/blob.c +30 -7
  120. data/vendor/libgit2/src/blob.h +1 -1
  121. data/vendor/libgit2/src/branch.c +361 -68
  122. data/vendor/libgit2/src/branch.h +17 -0
  123. data/vendor/libgit2/src/bswap.h +1 -1
  124. data/vendor/libgit2/src/buf_text.c +291 -0
  125. data/vendor/libgit2/src/buf_text.h +122 -0
  126. data/vendor/libgit2/src/buffer.c +27 -101
  127. data/vendor/libgit2/src/buffer.h +54 -39
  128. data/vendor/libgit2/src/cache.c +15 -6
  129. data/vendor/libgit2/src/cache.h +1 -1
  130. data/vendor/libgit2/src/cc-compat.h +3 -1
  131. data/vendor/libgit2/src/checkout.c +1165 -222
  132. data/vendor/libgit2/src/checkout.h +24 -0
  133. data/vendor/libgit2/src/clone.c +171 -86
  134. data/vendor/libgit2/src/commit.c +44 -45
  135. data/vendor/libgit2/src/commit.h +3 -3
  136. data/vendor/libgit2/src/commit_list.c +194 -0
  137. data/vendor/libgit2/src/commit_list.h +49 -0
  138. data/vendor/libgit2/src/common.h +44 -10
  139. data/vendor/libgit2/src/compress.c +1 -1
  140. data/vendor/libgit2/src/compress.h +1 -1
  141. data/vendor/libgit2/src/config.c +211 -124
  142. data/vendor/libgit2/src/config.h +23 -4
  143. data/vendor/libgit2/src/config_cache.c +2 -2
  144. data/vendor/libgit2/src/config_file.c +129 -53
  145. data/vendor/libgit2/src/config_file.h +10 -8
  146. data/vendor/libgit2/src/crlf.c +66 -67
  147. data/vendor/libgit2/src/date.c +12 -12
  148. data/vendor/libgit2/src/delta-apply.c +14 -1
  149. data/vendor/libgit2/src/delta-apply.h +18 -1
  150. data/vendor/libgit2/src/delta.c +40 -107
  151. data/vendor/libgit2/src/delta.h +19 -17
  152. data/vendor/libgit2/src/diff.c +347 -496
  153. data/vendor/libgit2/src/diff.h +27 -1
  154. data/vendor/libgit2/src/diff_output.c +564 -249
  155. data/vendor/libgit2/src/diff_output.h +15 -8
  156. data/vendor/libgit2/src/diff_tform.c +687 -0
  157. data/vendor/libgit2/src/errors.c +27 -36
  158. data/vendor/libgit2/src/fetch.c +13 -351
  159. data/vendor/libgit2/src/fetch.h +13 -3
  160. data/vendor/libgit2/src/fetchhead.c +295 -0
  161. data/vendor/libgit2/src/fetchhead.h +34 -0
  162. data/vendor/libgit2/src/filebuf.c +42 -15
  163. data/vendor/libgit2/src/filebuf.h +4 -2
  164. data/vendor/libgit2/src/fileops.c +466 -113
  165. data/vendor/libgit2/src/fileops.h +154 -28
  166. data/vendor/libgit2/src/filter.c +3 -75
  167. data/vendor/libgit2/src/filter.h +1 -29
  168. data/vendor/libgit2/src/fnmatch.c +1 -1
  169. data/vendor/libgit2/src/fnmatch.h +1 -1
  170. data/vendor/libgit2/src/global.c +54 -10
  171. data/vendor/libgit2/src/global.h +10 -1
  172. data/vendor/libgit2/src/graph.c +178 -0
  173. data/vendor/libgit2/src/hash.c +25 -52
  174. data/vendor/libgit2/src/hash.h +21 -9
  175. data/vendor/libgit2/src/{sha1/sha1.c → hash/hash_generic.c} +20 -12
  176. data/vendor/libgit2/src/hash/hash_generic.h +24 -0
  177. data/vendor/libgit2/src/hash/hash_openssl.h +45 -0
  178. data/vendor/libgit2/src/hash/hash_win32.c +291 -0
  179. data/vendor/libgit2/src/hash/hash_win32.h +140 -0
  180. data/vendor/libgit2/src/hashsig.c +368 -0
  181. data/vendor/libgit2/src/hashsig.h +72 -0
  182. data/vendor/libgit2/src/ignore.c +22 -15
  183. data/vendor/libgit2/src/ignore.h +6 -1
  184. data/vendor/libgit2/src/index.c +770 -171
  185. data/vendor/libgit2/src/index.h +13 -5
  186. data/vendor/libgit2/src/indexer.c +286 -431
  187. data/vendor/libgit2/src/iterator.c +854 -466
  188. data/vendor/libgit2/src/iterator.h +134 -109
  189. data/vendor/libgit2/src/map.h +1 -1
  190. data/vendor/libgit2/src/merge.c +296 -0
  191. data/vendor/libgit2/src/merge.h +22 -0
  192. data/vendor/libgit2/src/message.c +1 -1
  193. data/vendor/libgit2/src/message.h +1 -1
  194. data/vendor/libgit2/src/mwindow.c +35 -30
  195. data/vendor/libgit2/src/mwindow.h +2 -2
  196. data/vendor/libgit2/src/netops.c +162 -98
  197. data/vendor/libgit2/src/netops.h +50 -15
  198. data/vendor/libgit2/src/notes.c +109 -58
  199. data/vendor/libgit2/src/notes.h +2 -1
  200. data/vendor/libgit2/src/object.c +46 -57
  201. data/vendor/libgit2/src/object.h +1 -8
  202. data/vendor/libgit2/src/odb.c +151 -40
  203. data/vendor/libgit2/src/odb.h +5 -1
  204. data/vendor/libgit2/src/odb_loose.c +4 -5
  205. data/vendor/libgit2/src/odb_pack.c +122 -80
  206. data/vendor/libgit2/src/offmap.h +65 -0
  207. data/vendor/libgit2/src/oid.c +12 -4
  208. data/vendor/libgit2/src/oidmap.h +1 -1
  209. data/vendor/libgit2/src/pack-objects.c +88 -61
  210. data/vendor/libgit2/src/pack-objects.h +8 -8
  211. data/vendor/libgit2/src/pack.c +293 -28
  212. data/vendor/libgit2/src/pack.h +49 -4
  213. data/vendor/libgit2/src/path.c +103 -14
  214. data/vendor/libgit2/src/path.h +23 -7
  215. data/vendor/libgit2/src/pathspec.c +168 -0
  216. data/vendor/libgit2/src/pathspec.h +40 -0
  217. data/vendor/libgit2/src/pool.c +29 -4
  218. data/vendor/libgit2/src/pool.h +8 -1
  219. data/vendor/libgit2/src/posix.c +26 -27
  220. data/vendor/libgit2/src/posix.h +2 -3
  221. data/vendor/libgit2/src/pqueue.c +23 -1
  222. data/vendor/libgit2/src/pqueue.h +23 -1
  223. data/vendor/libgit2/src/push.c +653 -0
  224. data/vendor/libgit2/src/push.h +51 -0
  225. data/vendor/libgit2/src/refdb.c +185 -0
  226. data/vendor/libgit2/src/refdb.h +46 -0
  227. data/vendor/libgit2/src/refdb_fs.c +1024 -0
  228. data/vendor/libgit2/src/refdb_fs.h +15 -0
  229. data/vendor/libgit2/src/reflog.c +77 -45
  230. data/vendor/libgit2/src/reflog.h +1 -3
  231. data/vendor/libgit2/src/refs.c +366 -1326
  232. data/vendor/libgit2/src/refs.h +22 -13
  233. data/vendor/libgit2/src/refspec.c +46 -7
  234. data/vendor/libgit2/src/refspec.h +11 -1
  235. data/vendor/libgit2/src/remote.c +758 -120
  236. data/vendor/libgit2/src/remote.h +10 -5
  237. data/vendor/libgit2/src/repo_template.h +6 -6
  238. data/vendor/libgit2/src/repository.c +315 -96
  239. data/vendor/libgit2/src/repository.h +5 -3
  240. data/vendor/libgit2/src/reset.c +99 -81
  241. data/vendor/libgit2/src/revparse.c +157 -84
  242. data/vendor/libgit2/src/revwalk.c +68 -470
  243. data/vendor/libgit2/src/revwalk.h +44 -0
  244. data/vendor/libgit2/src/sha1_lookup.c +1 -1
  245. data/vendor/libgit2/src/sha1_lookup.h +1 -1
  246. data/vendor/libgit2/src/signature.c +68 -200
  247. data/vendor/libgit2/src/signature.h +1 -1
  248. data/vendor/libgit2/src/stash.c +663 -0
  249. data/vendor/libgit2/src/status.c +101 -79
  250. data/vendor/libgit2/src/strmap.h +1 -1
  251. data/vendor/libgit2/src/submodule.c +67 -51
  252. data/vendor/libgit2/src/submodule.h +1 -1
  253. data/vendor/libgit2/src/tag.c +35 -29
  254. data/vendor/libgit2/src/tag.h +1 -1
  255. data/vendor/libgit2/src/thread-utils.c +1 -1
  256. data/vendor/libgit2/src/thread-utils.h +2 -2
  257. data/vendor/libgit2/src/trace.c +39 -0
  258. data/vendor/libgit2/src/trace.h +56 -0
  259. data/vendor/libgit2/src/transport.c +81 -34
  260. data/vendor/libgit2/src/transports/cred.c +60 -0
  261. data/vendor/libgit2/src/transports/cred_helpers.c +49 -0
  262. data/vendor/libgit2/src/transports/git.c +234 -127
  263. data/vendor/libgit2/src/transports/http.c +761 -433
  264. data/vendor/libgit2/src/transports/local.c +460 -64
  265. data/vendor/libgit2/src/transports/smart.c +345 -0
  266. data/vendor/libgit2/src/transports/smart.h +179 -0
  267. data/vendor/libgit2/src/{pkt.c → transports/smart_pkt.c} +131 -12
  268. data/vendor/libgit2/src/transports/smart_protocol.c +856 -0
  269. data/vendor/libgit2/src/transports/winhttp.c +1136 -0
  270. data/vendor/libgit2/src/tree-cache.c +2 -2
  271. data/vendor/libgit2/src/tree-cache.h +1 -1
  272. data/vendor/libgit2/src/tree.c +239 -166
  273. data/vendor/libgit2/src/tree.h +11 -2
  274. data/vendor/libgit2/src/tsort.c +39 -23
  275. data/vendor/libgit2/src/unix/map.c +1 -1
  276. data/vendor/libgit2/src/unix/posix.h +12 -2
  277. data/vendor/libgit2/src/unix/realpath.c +30 -0
  278. data/vendor/libgit2/src/util.c +250 -13
  279. data/vendor/libgit2/src/util.h +71 -14
  280. data/vendor/libgit2/src/vector.c +123 -60
  281. data/vendor/libgit2/src/vector.h +24 -22
  282. data/vendor/libgit2/src/win32/dir.c +1 -1
  283. data/vendor/libgit2/src/win32/dir.h +1 -1
  284. data/vendor/libgit2/src/win32/error.c +77 -0
  285. data/vendor/libgit2/src/win32/error.h +13 -0
  286. data/vendor/libgit2/src/win32/findfile.c +143 -54
  287. data/vendor/libgit2/src/win32/findfile.h +10 -6
  288. data/vendor/libgit2/src/win32/map.c +1 -1
  289. data/vendor/libgit2/src/win32/mingw-compat.h +1 -1
  290. data/vendor/libgit2/src/win32/msvc-compat.h +10 -1
  291. data/vendor/libgit2/src/win32/posix.h +10 -1
  292. data/vendor/libgit2/src/win32/posix_w32.c +132 -63
  293. data/vendor/libgit2/src/win32/precompiled.c +1 -1
  294. data/vendor/libgit2/src/win32/pthread.c +1 -1
  295. data/vendor/libgit2/src/win32/pthread.h +1 -1
  296. data/vendor/libgit2/src/win32/utf-conv.c +5 -5
  297. data/vendor/libgit2/src/win32/utf-conv.h +3 -3
  298. data/vendor/libgit2/src/win32/version.h +20 -0
  299. metadata +308 -252
  300. data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  301. data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
  302. data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
  303. data/test/index_test.rb~ +0 -218
  304. data/vendor/libgit2/src/pkt.h +0 -91
  305. data/vendor/libgit2/src/ppc/sha1.c +0 -70
  306. data/vendor/libgit2/src/ppc/sha1.h +0 -26
  307. data/vendor/libgit2/src/protocol.c +0 -110
  308. data/vendor/libgit2/src/protocol.h +0 -21
  309. data/vendor/libgit2/src/sha1.h +0 -33
  310. data/vendor/libgit2/src/transport.h +0 -148
data/test/remote_test.rb CHANGED
@@ -1,13 +1,17 @@
1
1
  require "test_helper"
2
+ require 'net/http'
2
3
 
3
- context "Rugged::Tag tests" do
4
- setup do
5
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
6
- @repo = Rugged::Repository.new(@path)
7
- end
4
+ class RemoteTest < Rugged::TestCase
5
+ include Rugged::RepositoryAccess
6
+
7
+ def test_remote_connect
8
+ begin
9
+ Net::HTTP.new('github.com').head('/')
10
+ rescue SocketError => msg
11
+ skip "github is not reachable: #{msg}"
12
+ end
8
13
 
9
- test "is able to connect to the remote" do
10
- remote = Rugged::Remote.new(@repo, "git://github.com/libgit2/libgit2.git")
14
+ remote = Rugged::Remote.new(@repo, 'git://github.com/libgit2/libgit2.git')
11
15
 
12
16
  remote.connect(:fetch) do |r|
13
17
  assert r.connected?
@@ -16,10 +20,84 @@ context "Rugged::Tag tests" do
16
20
  assert !remote.connected?
17
21
  end
18
22
 
19
- test "can list remotes" do
23
+ def test_list_remotes
20
24
  remotes = @repo.remotes
21
25
  assert remotes.kind_of? Enumerable
22
26
  assert_equal [ "libgit2" ], remotes.to_a
23
27
  end
24
28
 
29
+ def test_remote_new_name
30
+ remote = Rugged::Remote.new(@repo, 'git://github.com/libgit2/libgit2.git')
31
+ assert_nil remote.name
32
+ assert_equal 'git://github.com/libgit2/libgit2.git', remote.url
33
+ end
34
+
35
+ def test_remote_new_invalid_url
36
+ assert_raises ArgumentError do
37
+ Rugged::Remote.new(@repo, 'libgit2')
38
+ end
39
+ end
40
+
41
+ def test_remote_lookup
42
+ remote = Rugged::Remote.lookup(@repo, 'libgit2')
43
+ assert_equal 'git://github.com/libgit2/libgit2.git', remote.url
44
+ assert_equal 'libgit2', remote.name
45
+ end
46
+
47
+ def test_remote_lookup_missing
48
+ assert_nil Rugged::Remote.lookup(@repo, 'missing_remote')
49
+ end
50
+
51
+ def test_remote_lookup_invalid
52
+ assert_raises Rugged::ConfigError do
53
+ Rugged::Remote.lookup(@repo, "*\?")
54
+ end
55
+ end
56
+ end
57
+
58
+ class RemotePushTest < Rugged::SandboxedTestCase
59
+ def setup
60
+ super
61
+ @remote_repo = sandbox_init("testrepo.git")
62
+ # We can only push to bare repos
63
+ @remote_repo.config['core.bare'] = 'true'
64
+
65
+ @repo = sandbox_clone("testrepo.git", "testrepo")
66
+ Rugged::Reference.create(@repo,
67
+ "refs/heads/unit_test",
68
+ "8496071c1b46c854b31185ea97743be6a8774479")
69
+
70
+ @remote = Rugged::Remote.lookup(@repo, 'origin')
71
+ end
72
+
73
+ def test_push_single_ref
74
+ result = @remote.push(["refs/heads/master", "refs/heads/master:refs/heads/foobar", "refs/heads/unit_test"])
75
+ assert_equal({}, result)
76
+
77
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", @remote_repo.ref("refs/heads/foobar").target
78
+ assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @remote_repo.ref("refs/heads/unit_test").target
79
+ end
80
+
81
+ def test_push_to_non_bare_raise_error
82
+ @remote_repo.config['core.bare'] = 'false'
83
+
84
+ assert_raises Rugged::Error do
85
+ @remote.push(["refs/heads/master"])
86
+ end
87
+ end
88
+
89
+ def test_push_non_forward_raise_error
90
+ assert_raises Rugged::Error do
91
+ @remote.push(["refs/heads/unit_test:refs/heads/master"])
92
+ end
93
+
94
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", @remote_repo.ref("refs/heads/master").target
95
+ end
96
+
97
+ def test_push_non_forward_forced_raise_no_error
98
+ result = @remote.push(["+refs/heads/unit_test:refs/heads/master"])
99
+ assert_equal({}, result)
100
+
101
+ assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @remote_repo.ref("refs/heads/master").target
102
+ end
25
103
  end
@@ -1,22 +1,24 @@
1
1
  require "test_helper"
2
2
  require 'base64'
3
3
 
4
- context "Rugged::Repository packed stuff" do
5
- setup do
6
- path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
7
- @repo = Rugged::Repository.new(path)
8
- end
4
+ class PackfileTest < Rugged::TestCase
5
+ include Rugged::RepositoryAccess
9
6
 
10
- test "can tell if a packed object exists" do
7
+ def test_packfile_object_exists
11
8
  assert @repo.exists?("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
12
9
  assert @repo.exists?("f82a8eb4cb20e88d1030fd10d89286215a715396")
13
10
  end
14
11
 
15
- test "can read a packed object from the db" do
12
+ def test_read_packed_object
16
13
  rawobj = @repo.read("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
17
14
  assert_match 'tree f82a8eb4cb20e88d1030fd10d89286215a715396', rawobj.data
18
15
  assert_equal 230, rawobj.len
19
16
  assert_equal :commit, rawobj.type
20
17
  end
21
18
 
19
+ def test_read_packed_header
20
+ hash = @repo.read_header("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
21
+ assert_equal 230, hash[:len]
22
+ assert_equal :commit, hash[:type]
23
+ end
22
24
  end
@@ -0,0 +1,80 @@
1
+ class RepositoryResetTest < Rugged::TestCase
2
+ include Rugged::TempRepositoryAccess
3
+
4
+ def repo_file_path; File.join('subdir', 'README') end
5
+ def file_path; File.join(@path, 'subdir', 'README') end
6
+
7
+ def test_reset_with_rugged_tag
8
+ tag = @repo.lookup('0c37a5391bbff43c37f0d0371823a5509eed5b1d')
9
+ @repo.reset(tag, :soft)
10
+ assert_equal tag.target.oid , @repo.head.target
11
+ end
12
+
13
+ def test_reset_with_invalid_mode
14
+ assert_raises ArgumentError do
15
+ @repo.reset('441034f860c1d5d90e4188d11ae0d325176869a8', :tender)
16
+ end
17
+ end
18
+
19
+ def test_reset_soft
20
+ original_content = File.open(file_path) { |f| f.read }
21
+
22
+ @repo.reset('441034f860c1d5d90e4188d11ae0d325176869a8', :soft)
23
+ assert_equal '441034f860c1d5d90e4188d11ae0d325176869a8', @repo.head.target
24
+ assert_equal [:index_modified], @repo.status(repo_file_path)
25
+
26
+ new_content = File.open(file_path) { |f| f.read }
27
+
28
+ assert_equal original_content, new_content
29
+ end
30
+
31
+ def test_reset_mixed
32
+ original_content = File.open(file_path) { |f| f.read }
33
+
34
+ @repo.reset('441034f860c1d5d90e4188d11ae0d325176869a8', :mixed)
35
+ assert_equal [:worktree_modified], @repo.status(repo_file_path)
36
+
37
+ new_content = File.open(file_path) { |f| f.read }
38
+
39
+ assert_equal original_content, new_content
40
+ end
41
+
42
+ def test_reset_hard
43
+ original_content = File.open(file_path) { |f| f.read }
44
+
45
+ @repo.reset('441034f860c1d5d90e4188d11ae0d325176869a8', :hard)
46
+ assert_empty @repo.status(repo_file_path)
47
+
48
+ new_content = File.open(file_path) { |f| f.read }
49
+
50
+ refute_equal original_content, new_content
51
+ end
52
+
53
+ def test_reset_path
54
+ File.open(file_path, 'w') do |f|
55
+ f.puts "test content"
56
+ end
57
+ @repo.index.add(repo_file_path)
58
+ @repo.index.write
59
+
60
+ @repo.reset_path(repo_file_path, '441034f860c1d5d90e4188d11ae0d325176869a8')
61
+ assert_equal [:index_modified, :worktree_modified], @repo.status(repo_file_path)
62
+ end
63
+
64
+ def test_reset_path_no_target
65
+ File.open(file_path, 'w') do |f|
66
+ f.puts "test content"
67
+ end
68
+ @repo.index.add(repo_file_path)
69
+ @repo.index.write
70
+
71
+ @repo.reset_path(repo_file_path)
72
+ assert_equal [:index_deleted, :worktree_new], @repo.status(repo_file_path)
73
+ end
74
+
75
+ def test_reset_path_invalid_pathspec
76
+ assert_raises TypeError do
77
+ @repo.reset_path([:invalid_reset_path], '441034f860c1d5d90e4188d11ae0d325176869a8')
78
+ end
79
+ end
80
+ end
data/test/repo_test.rb CHANGED
@@ -1,22 +1,16 @@
1
1
  require 'test_helper'
2
2
  require 'base64'
3
3
 
4
- context "Rugged::Repository stuff" do
5
- setup do
6
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
7
- @repo = Rugged::Repository.new(@path)
4
+ class RepositoryTest < Rugged::TestCase
5
+ include Rugged::RepositoryAccess
8
6
 
9
- @test_content = "my test data\n"
10
- @test_content_type = 'blob'
11
- end
12
-
13
- test "last_commit returns the most recent commit" do
7
+ def test_last_commit
14
8
  assert @repo.respond_to? :last_commit
15
9
  assert "36060c58702ed4c2a40832c51758d5344201d89a", @repo.last_commit.oid
16
10
  end
17
11
 
18
- test "fails to open unexisting repositories" do
19
- assert_raises Rugged::OSError do
12
+ def test_fails_to_open_unexisting_repos
13
+ assert_raises IOError, Rugged::OSError do
20
14
  Rugged::Repository.new("fakepath/123/")
21
15
  end
22
16
 
@@ -25,118 +19,247 @@ context "Rugged::Repository stuff" do
25
19
  end
26
20
  end
27
21
 
28
- test "can tell if an object exists or not" do
22
+ def test_can_check_if_objects_exist
29
23
  assert @repo.exists?("8496071c1b46c854b31185ea97743be6a8774479")
30
24
  assert @repo.exists?("1385f264afb75a56a5bec74243be9b367ba4ca08")
31
25
  assert !@repo.exists?("ce08fe4884650f067bd5703b6a59a8b3b3c99a09")
32
26
  assert !@repo.exists?("8496071c1c46c854b31185ea97743be6a8774479")
33
27
  end
34
28
 
35
- test "can read an object from the db" do
29
+ def test_can_read_a_raw_object
36
30
  rawobj = @repo.read("8496071c1b46c854b31185ea97743be6a8774479")
37
31
  assert_match 'tree 181037049a54a1eb5fab404658a3a250b44335d7', rawobj.data
38
32
  assert_equal 172, rawobj.len
39
33
  assert_equal :commit, rawobj.type
40
34
  end
41
35
 
42
- test "checks that reading fails on unexisting objects" do
43
- assert_raise Rugged::OdbError do
44
- @repo.read("a496071c1b46c854b31185ea97743be6a8774471")
45
- end
36
+ def test_can_read_object_headers
37
+ hash = @repo.read_header("8496071c1b46c854b31185ea97743be6a8774479")
38
+ assert_equal 172, hash[:len]
39
+ assert_equal :commit, hash[:type]
46
40
  end
47
41
 
48
- test "can hash data" do
49
- oid = Rugged::Repository::hash(@test_content, @test_content_type)
50
- assert_equal "76b1b55ab653581d6f2c7230d34098e837197674", oid
42
+ def test_check_reads_fail_on_missing_objects
43
+ assert_raises Rugged::OdbError do
44
+ @repo.read("a496071c1b46c854b31185ea97743be6a8774471")
45
+ end
51
46
  end
52
47
 
53
- test "can write to the db" do
54
- oid = @repo.write(@test_content, @test_content_type)
55
- assert_equal "76b1b55ab653581d6f2c7230d34098e837197674", oid
56
- assert @repo.exists?("76b1b55ab653581d6f2c7230d34098e837197674")
57
-
58
- rm_loose(oid)
48
+ def test_check_read_headers_fail_on_missing_objects
49
+ assert_raises Rugged::OdbError do
50
+ @repo.read_header("a496071c1b46c854b31185ea97743be6a8774471")
51
+ end
59
52
  end
60
53
 
61
- test "can walk in a block" do
54
+ def test_walking_with_block
62
55
  oid = "a4a7dce85cf63874e984719f4fdd239f5145052f"
63
56
  list = []
64
57
  @repo.walk(oid) { |c| list << c }
65
58
  assert list.map {|c| c.oid[0,5] }.join('.'), "a4a7d.c4780.9fd73.4a202.5b5b0.84960"
66
59
  end
67
60
 
68
- test "can walk without a block" do
61
+ def test_walking_without_block
69
62
  commits = @repo.walk('a4a7dce85cf63874e984719f4fdd239f5145052f')
70
63
 
71
64
  assert commits.kind_of?(Enumerable)
72
65
  assert commits.count > 0
73
66
  end
74
67
 
75
- test "can lookup an object" do
68
+ def test_lookup_object
76
69
  object = @repo.lookup("8496071c1b46c854b31185ea97743be6a8774479")
77
-
78
70
  assert object.kind_of?(Rugged::Commit)
79
71
  end
80
72
 
81
- test "can find a ref" do
73
+ def test_find_reference
82
74
  ref = @repo.ref('refs/heads/master')
83
75
 
84
76
  assert ref.kind_of?(Rugged::Reference)
85
77
  assert_equal 'refs/heads/master', ref.name
86
78
  end
87
79
 
88
- test "can return all refs" do
89
- refs = @repo.refs
90
-
91
- assert_equal 4, refs.length
92
- end
93
-
94
- test "can return all refs that match" do
80
+ def test_match_all_refs
95
81
  refs = @repo.refs 'refs/heads'
96
-
97
82
  assert_equal 2, refs.length
98
83
  end
99
84
 
100
- test "can return the names of all refs" do
85
+ def test_return_all_ref_names
101
86
  refs = @repo.ref_names
102
-
103
87
  refs.each {|name| assert name.kind_of?(String)}
104
- assert_equal 4, refs.count
88
+ assert_equal 5, refs.count
105
89
  end
106
90
 
107
- test "can return all tags" do
91
+ def test_return_all_tags
108
92
  tags = @repo.tags
109
-
110
93
  assert_equal 2, tags.count
111
94
  end
112
95
 
113
- test "can return all tags that match" do
96
+ def test_return_matching_tags
114
97
  tags = @repo.tags 'v0.9'
115
-
116
98
  assert_equal 1, tags.count
117
99
  end
118
100
 
119
- test "can return all remotes" do
101
+ def test_return_all_remotes
120
102
  remotes = @repo.remotes
121
-
122
103
  assert_equal 1, remotes.count
123
104
  end
124
105
 
125
- test "can lookup head from repo" do
106
+ def test_lookup_head
126
107
  head = @repo.head
127
108
  assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", head.target
128
109
  assert_equal :direct, head.type
129
110
  end
130
111
 
131
- test "can access a file" do
112
+ def test_access_a_file
132
113
  sha = '36060c58702ed4c2a40832c51758d5344201d89a'
133
- content = @repo.file_at(sha, 'new.txt')
134
- assert_equal "new file\n", content
114
+ blob = @repo.blob_at(sha, 'new.txt')
115
+ assert_equal "new file\n", blob.content
135
116
  end
136
117
 
137
- test "garbage collection methods don't crash" do
118
+ def test_garbage_collection
138
119
  Rugged::Repository.new(@path)
139
120
  ObjectSpace.garbage_collect
140
121
  end
141
122
 
123
+ def test_enumerate_all_objects
124
+ assert_equal 36, @repo.each_id.to_a.length
125
+ end
126
+
127
+ def test_loading_alternates
128
+ 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
131
+ assert repo.read('146ae76773c91e3b1d00cf7a338ec55ae58297e2')
132
+ end
133
+
134
+ def test_alternates_with_invalid_path_type
135
+ assert_raises TypeError do
136
+ Rugged::Repository.new(@path, :alternates => [:invalid_input])
137
+ end
138
+ end
139
+
140
+ def test_find_merge_base_between_oids
141
+ commit1 = 'a4a7dce85cf63874e984719f4fdd239f5145052f'
142
+ commit2 = '36060c58702ed4c2a40832c51758d5344201d89a'
143
+ base = '5b5b025afb0b4c913b4c338a42934a3863bf3644'
144
+ assert_equal base, @repo.merge_base(commit1, commit2)
145
+ end
146
+
147
+ def test_find_merge_base_between_commits
148
+ commit1 = @repo.lookup('a4a7dce85cf63874e984719f4fdd239f5145052f')
149
+ commit2 = @repo.lookup('36060c58702ed4c2a40832c51758d5344201d89a')
150
+ base = '5b5b025afb0b4c913b4c338a42934a3863bf3644'
151
+ assert_equal base, @repo.merge_base(commit1, commit2)
152
+ end
153
+
154
+ def test_find_merge_base_between_ref_and_oid
155
+ commit1 = 'a4a7dce85cf63874e984719f4fdd239f5145052f'
156
+ commit2 = "refs/heads/master"
157
+ base = '5b5b025afb0b4c913b4c338a42934a3863bf3644'
158
+ assert_equal base, @repo.merge_base(commit1, commit2)
159
+ end
160
+ end
161
+
162
+ class RepositoryWriteTest < Rugged::TestCase
163
+ include Rugged::TempRepositoryAccess
164
+
165
+ TEST_CONTENT = "my test data\n"
166
+ TEST_CONTENT_TYPE = 'blob'
167
+
168
+ def test_can_hash_data
169
+ oid = Rugged::Repository::hash(TEST_CONTENT, TEST_CONTENT_TYPE)
170
+ assert_equal "76b1b55ab653581d6f2c7230d34098e837197674", oid
171
+ end
172
+
173
+ def test_write_to_odb
174
+ oid = @repo.write(TEST_CONTENT, TEST_CONTENT_TYPE)
175
+ assert_equal "76b1b55ab653581d6f2c7230d34098e837197674", oid
176
+ assert @repo.exists?("76b1b55ab653581d6f2c7230d34098e837197674")
177
+ end
178
+
179
+ def test_no_merge_base_between_unrelated_branches
180
+ info = @repo.rev_parse('HEAD').to_hash
181
+ baseless = Rugged::Commit.create(@repo, info.merge(:parents => []))
182
+ assert_nil @repo.merge_base('HEAD', baseless)
183
+ end
184
+ end
185
+
186
+ class RepositoryInitTest < Rugged::TestCase
187
+ def setup
188
+ @tmppath = Dir.mktmpdir
189
+ end
190
+
191
+ def teardown
192
+ FileUtils.remove_entry_secure(@tmppath)
193
+ end
194
+
195
+ def test_init_bare_false
196
+ repo = Rugged::Repository.init_at(@tmppath, false)
197
+ refute repo.bare?
198
+ end
199
+
200
+ def test_init_bare_true
201
+ repo = Rugged::Repository.init_at(@tmppath, true)
202
+ assert repo.bare?
203
+ end
204
+
205
+ def test_init_bare_truthy
206
+ repo = Rugged::Repository.init_at(@tmppath, :bare)
207
+ assert repo.bare?
208
+ end
209
+
210
+ def test_init_non_bare_default
211
+ repo = Rugged::Repository.init_at(@tmppath)
212
+ refute repo.bare?
213
+ end
214
+ end
215
+
216
+ class RepositoryPushTest < Rugged::SandboxedTestCase
217
+ def setup
218
+ super
219
+ @remote_repo = sandbox_init("testrepo.git")
220
+ # We can only push to bare repos
221
+ @remote_repo.config['core.bare'] = 'true'
222
+
223
+ @repo = sandbox_clone("testrepo.git", "testrepo")
224
+ Rugged::Reference.create(@repo,
225
+ "refs/heads/unit_test",
226
+ "8496071c1b46c854b31185ea97743be6a8774479")
227
+ end
228
+
229
+ def test_push_single_ref
230
+ result = @repo.push("origin", ["refs/heads/master", "refs/heads/master:refs/heads/foobar", "refs/heads/unit_test"])
231
+ assert_equal({}, result)
232
+
233
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", @remote_repo.ref("refs/heads/foobar").target
234
+ assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @remote_repo.ref("refs/heads/unit_test").target
235
+ end
236
+
237
+ def test_push_to_remote_instance
238
+ origin = Rugged::Remote.lookup(@repo, "origin")
239
+ result = @repo.push(origin, ["refs/heads/master"])
240
+ assert_equal({}, result)
241
+ end
242
+
243
+ def test_push_to_non_bare_raise_error
244
+ @remote_repo.config['core.bare'] = 'false'
245
+
246
+ assert_raises Rugged::Error do
247
+ @repo.push("origin", ["refs/heads/master"])
248
+ end
249
+ end
250
+
251
+ def test_push_non_forward_raise_error
252
+ assert_raises Rugged::Error do
253
+ @repo.push("origin", ["refs/heads/unit_test:refs/heads/master"])
254
+ end
255
+
256
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", @remote_repo.ref("refs/heads/master").target
257
+ end
258
+
259
+ def test_push_non_forward_forced_raise_no_error
260
+ result = @repo.push("origin", ["+refs/heads/unit_test:refs/heads/master"])
261
+ assert_equal({}, result)
262
+
263
+ assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @remote_repo.ref("refs/heads/master").target
264
+ end
142
265
  end