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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2010 Scott Chacon
3
+ Copyright (c) 2013 GitHub, Inc
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Rugged
2
2
  **libgit2 bindings in Ruby**
3
3
 
4
- Rugged is a library for accessing libgit2 in Ruby. It gives you the speed and
4
+ Rugged is a library for accessing [libgit2](https://github.com/libgit2/libgit2) in Ruby. It gives you the speed and
5
5
  portability of libgit2 with the beauty of the Ruby language.
6
6
 
7
7
  ### libgit2
@@ -45,7 +45,7 @@ If you're working against a bare repository, you'll need to indicate that:
45
45
 
46
46
  ```ruby
47
47
  # Second parameter indicates whether the repo is a bare repository
48
- Rugged::Repository.init_at('.', true)
48
+ Rugged::Repository.init_at('.', :bare)
49
49
  ```
50
50
 
51
51
  You can also let Rugged discover the path to the .git directory if you give it a
@@ -98,7 +98,7 @@ object = repo.read('a0ae5566e3c8a3bddffab21022056f0b5e03ef07')
98
98
  object.len
99
99
  # => 237
100
100
  object.data
101
- # => "tree 76f23f186076fc291742816721ea8c3e95567241\nparent 8e3c5c52b8f29da0adc7e8be8a037cbeaea6de6b\nauthor Vicent Mart\303\255 <tanoku@gmail.com> 1333859005 +0200\ncommitter Vicent Mart\303\255 <tanoku@gmail.com> 1333859005 +0200\n\nAdd `Repository#file_at`\n"
101
+ # => "tree 76f23f186076fc291742816721ea8c3e95567241\nparent 8e3c5c52b8f29da0adc7e8be8a037cbeaea6de6b\nauthor Vicent Mart\303\255 <tanoku@gmail.com> 1333859005 +0200\ncommitter Vicent Mart\303\255 <tanoku@gmail.com> 1333859005 +0200\n\nAdd `Repository#blob_at`\n"
102
102
  object.type
103
103
  # => :commit
104
104
  ```
@@ -109,12 +109,28 @@ There's a few ways to write to a repository. To write directly from your
109
109
  instantiated repository object:
110
110
 
111
111
  ```ruby
112
- sha = repo.hash(content, type)
113
112
  sha = repo.write(content, type)
114
113
  ```
115
114
 
116
115
  You can also use the `Commit` object directly to craft a commit; this is a bit
117
- more high-level, so it may be preferable.
116
+ more high-level, so it may be preferable:
117
+
118
+ ```ruby
119
+ oid = repo.write("This is a blob.", :blob)
120
+ index = Rugged::Index.new
121
+ index.add(:path => "README.md", :oid => oid, :mode => 0100644)
122
+
123
+ options = {}
124
+ options[:tree] = index.write_tree(repo)
125
+
126
+ options[:author] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
127
+ options[:committer] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
128
+ options[:message] ||= "Making a commit via Rugged!"
129
+ options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact
130
+ options[:update_ref] = 'HEAD'
131
+
132
+ Rugged::Commit.create(repo, options)
133
+ ```
118
134
 
119
135
  ---
120
136
 
@@ -143,7 +159,7 @@ commit = repo.lookup('a0ae5566e3c8a3bddffab21022056f0b5e03ef07')
143
159
  # => #<Rugged::Commit:2245304380>
144
160
 
145
161
  commit.message
146
- # => "Add `Repository#file_at`\n"
162
+ # => "Add `Repository#blob_at`\n"
147
163
 
148
164
  commit.time
149
165
  # => Sat Apr 07 21:23:25 -0700 2012
@@ -168,7 +184,8 @@ Rugged::Commit.create(r,
168
184
  :message => "Hello world\n\n",
169
185
  :committer => author,
170
186
  :parents => ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1"],
171
- :tree => some_tree) #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
187
+ :tree => some_tree,
188
+ :update_ref => "HEAD") #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
172
189
  ```
173
190
 
174
191
  ### Tag Objects
@@ -178,7 +195,7 @@ tag = repo.lookup(tag_sha)
178
195
 
179
196
  object = tag.target
180
197
  sha = tag.target.oid
181
- str = tag.target_type # "commit", "tag", "blob"
198
+ str = tag.target_type # :commit, :tag, :blob
182
199
  str = tag.name # "v1.0"
183
200
  str = tag.message
184
201
  person = tag.tagger
@@ -216,14 +233,20 @@ tree.each_blob { |entry| puts entry[:name] } # list only files
216
233
  You can also write trees with the `TreeBuilder`:
217
234
 
218
235
  ```ruby
219
- entry = {:type => :blob,
220
- :name => "README.txt",
221
- :oid => "1385f264afb75a56a5bec74243be9b367ba4ca08",
222
- :filemode => 33188}
223
-
236
+ oid = repo.write("This is a blob.", :blob)
224
237
  builder = Rugged::Tree::Builder.new
225
- builder << entry
226
- sha = builder.write(repo)
238
+ builder << { :type => :blob, :name => "README.md", :oid => oid, :filemode => 0100644 }
239
+
240
+ options = {}
241
+ options[:tree] = builder.write(repo)
242
+
243
+ options[:author] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
244
+ options[:committer] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
245
+ options[:message] ||= "Making a commit via Rugged!"
246
+ options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact
247
+ options[:update_ref] = 'HEAD'
248
+
249
+ Rugged::Commit.create(repo, options)
227
250
  ```
228
251
 
229
252
  ---
@@ -271,10 +294,10 @@ index.entries
271
294
  index.each { |i| puts i.inspect }
272
295
 
273
296
  # Get a particular entry in the index.
274
- index.get_entry(path)
297
+ index[path]
275
298
 
276
299
  # Unstage.
277
- index.remove(i/path)
300
+ index.remove(path)
278
301
 
279
302
  # Stage. Also updates existing entry if there is one.
280
303
  index.add(ientry)
@@ -287,14 +310,14 @@ index.add(path)
287
310
 
288
311
  ### Refs
289
312
 
290
- The `RefList` class allows you to list, create and delete packed and loose refs.
313
+ The `Rugged::Reference` class allows you to list, create and delete packed and loose refs.
291
314
 
292
315
  ```ruby
293
316
  ref = repo.head # or...
294
317
  ref = Rugged::Reference.lookup(repo, "refs/heads/master")
295
318
 
296
319
  sha = ref.target
297
- str = ref.type # "commit"
320
+ str = ref.type # :direct
298
321
  str = ref.name # "refs/heads/master"
299
322
  ```
300
323
 
@@ -319,7 +342,7 @@ It is also easy to create, update, rename or delete a reference:
319
342
  ```ruby
320
343
  ref = Rugged::Reference.create(repo, "refs/heads/unit_test", some_commit_sha)
321
344
 
322
- ref.target = new_sha
345
+ ref.set_target(new_sha)
323
346
 
324
347
  ref.rename("refs/heads/blead")
325
348
 
@@ -331,14 +354,56 @@ Finally, you can access the reflog for any branch:
331
354
  ```ruby
332
355
  ref = Rugged::Reference.lookup(repo, "refs/heads/master")
333
356
  entry = ref.log.first
334
- sha = entry[:oid_old]
335
- sha = entry[:oid_new]
357
+ sha = entry[:id_old]
358
+ sha = entry[:id_new]
336
359
  str = entry[:message]
337
360
  prsn = entry[:committer]
338
361
  ```
339
362
 
340
363
  ---
341
364
 
365
+ ### Branches
366
+
367
+ `Rugged::Branch` will help you with all of your branch-related needs.
368
+
369
+ Iterate over all branches:
370
+
371
+ ```ruby
372
+ Rugged::Branch.each_name(repo).sort
373
+ # => ["master", "origin/HEAD", "origin/master", "origin/packed"]
374
+
375
+ Rugged::Branch.each_name(repo, :local).sort
376
+ # => ["master"]
377
+
378
+ Rugged::Branch.each_name(repo, :remote).sort
379
+ # => ["origin/HEAD", "origin/master", "origin/packed"]
380
+ ```
381
+
382
+ Look up branches and get attributes:
383
+
384
+ ```ruby
385
+ branch = Rugged::Branch.lookup(repo, "master")
386
+ branch.name # => 'master'
387
+ branch.canonical_name # => 'refs/heads/master'
388
+ ```
389
+
390
+ Look up the oid for the tip of a branch:
391
+
392
+ ```ruby
393
+ Rugged::Branch.lookup(repo, "master").tip.oid
394
+ # => "36060c58702ed4c2a40832c51758d5344201d89a"
395
+ ```
396
+
397
+ Creation and deletion:
398
+
399
+ ```ruby
400
+ branch = repo.create_branch("test_branch")
401
+ branch.move("new_branch")
402
+ branch.delete!
403
+ ```
404
+
405
+ ---
406
+
342
407
  ### Config files
343
408
 
344
409
  It's also easy to read and manipulate the Git config file data with Rugged.
@@ -380,16 +445,7 @@ for the topic), send a pull request.
380
445
 
381
446
  ## Development
382
447
 
383
- First you need to install libgit2:
384
-
385
- $ git clone https://github.com/libgit2/libgit2.git
386
- $ cd libgit2
387
- $ mkdir build && cd build
388
- $ cmake ..
389
- $ make
390
- $ make install
391
-
392
- Now that those are installed, you can install Rugged:
448
+ Simply clone and install:
393
449
 
394
450
  $ git clone https://github.com/libgit2/rugged.git
395
451
  $ cd rugged
@@ -8,7 +8,9 @@ def sys(cmd)
8
8
  ret
9
9
  end
10
10
 
11
- if `which make`.strip.empty?
11
+ MAKE_PROGRAM = find_executable('gmake') || find_executable('make')
12
+
13
+ if MAKE_PROGRAM.nil?
12
14
  STDERR.puts "ERROR: GNU make is required to build Rugged"
13
15
  exit(1)
14
16
  end
@@ -27,7 +29,7 @@ else
27
29
 
28
30
  if !File.exists?(LIBGIT2_LIB_PATH)
29
31
  Dir.chdir(LIBGIT2_DIR) do
30
- sys("make -f Makefile.embed")
32
+ sys("#{MAKE_PROGRAM} -f Makefile.embed")
31
33
  FileUtils.cp 'libgit2.a', LIBGIT2_LIB_PATH
32
34
  end
33
35
  end
data/ext/rugged/rugged.c CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2011 GitHub, Inc
4
+ * Copyright (c) 2013 GitHub, Inc
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -25,7 +25,7 @@
25
25
  #include "rugged.h"
26
26
 
27
27
  const char *RUGGED_ERROR_NAMES[] = {
28
- NULL, /* GITERR_NOMEMORY, */
28
+ "NoMemError", /* GITERR_NOMEMORY, */
29
29
  "OSError", /* GITERR_OS, */
30
30
  "InvalidError", /* GITERR_INVALID, */
31
31
  "ReferenceError", /* GITERR_REFERENCE, */
@@ -36,7 +36,7 @@ const char *RUGGED_ERROR_NAMES[] = {
36
36
  "OdbError", /* GITERR_ODB, */
37
37
  "IndexError", /* GITERR_INDEX, */
38
38
  "ObjectError", /* GITERR_OBJECT, */
39
- "NetworkError" /* GITERR_NET, */
39
+ "NetworkError", /* GITERR_NET, */
40
40
  "TagError", /* GITERR_TAG, */
41
41
  "TreeError", /* GITERR_TREE, */
42
42
  "IndexerError", /* GITERR_INDEXER, */
@@ -50,6 +50,58 @@ VALUE rb_eRuggedErrors[RUGGED_ERROR_COUNT];
50
50
 
51
51
  static VALUE rb_mShutdownHook;
52
52
 
53
+ /*
54
+ * call-seq:
55
+ * Rugged.libgit2_version -> version
56
+ *
57
+ * Returns an array representing the current libgit2 version in use. Using
58
+ * the array makes it easier for the end-user to take conditional actions
59
+ * based on each respective version attribute: major, minor, rev.
60
+ *
61
+ * Rugged.libgit2_version
62
+ * #=> [0, 17, 0]
63
+ */
64
+ static VALUE rb_git_libgit2_version(VALUE self)
65
+ {
66
+ int major;
67
+ int minor;
68
+ int rev;
69
+
70
+ git_libgit2_version(&major, &minor, &rev);
71
+
72
+ // We return an array of three elements to represent the version components
73
+ return rb_ary_new3(3, INT2NUM(major), INT2NUM(minor), INT2NUM(rev));
74
+ }
75
+
76
+ /*
77
+ * call-seq:
78
+ * Rugged.capabilities-> capabilities
79
+ *
80
+ * Returns an array representing the 'capabilities' that libgit2 was compiled
81
+ * with — this includes GIT_CAP_THREADS (thread support) and GIT_CAP_HTTPS (https).
82
+ * This is implemented in libgit2 with simple bitwise ops; we offer Rubyland an array
83
+ * of symbols representing the capabilities.
84
+ *
85
+ * The possible capabilities are "threads" and "https".
86
+ *
87
+ * Rugged.capabilities
88
+ * #=> [:threads, :https]
89
+ */
90
+ static VALUE rb_git_capabilities(VALUE self)
91
+ {
92
+ VALUE ret_arr = rb_ary_new();
93
+
94
+ int caps = git_libgit2_capabilities();
95
+
96
+ if (caps & GIT_CAP_THREADS)
97
+ rb_ary_push(ret_arr, CSTR2SYM("threads"));
98
+
99
+ if (caps & GIT_CAP_HTTPS)
100
+ rb_ary_push(ret_arr, CSTR2SYM("https"));
101
+
102
+ return ret_arr;
103
+ }
104
+
53
105
  /*
54
106
  * call-seq:
55
107
  * Rugged.hex_to_raw(oid) -> raw_buffer
@@ -227,16 +279,19 @@ void rugged_exception_raise(int errorcode)
227
279
  VALUE err_klass = rb_eRuggedError;
228
280
  VALUE err_obj;
229
281
  const git_error *error;
282
+ const char *err_message;
230
283
 
231
284
  error = giterr_last();
232
285
 
233
- if (!error)
234
- return;
235
-
236
- if (error->klass >= 0 && error->klass < RUGGED_ERROR_COUNT)
286
+ if (error && error->klass >= 0 && error->klass < RUGGED_ERROR_COUNT) {
237
287
  err_klass = rb_eRuggedErrors[error->klass];
288
+ err_message = error->message;
289
+ } else {
290
+ err_klass = rb_eRuggedErrors[2]; /* InvalidError */
291
+ err_message = "Unknown Error";
292
+ }
238
293
 
239
- err_obj = rb_exc_new2(err_klass, error->message);
294
+ err_obj = rb_exc_new2(err_klass, err_message);
240
295
  giterr_clear();
241
296
  rb_exc_raise(err_obj);
242
297
  }
@@ -250,13 +305,18 @@ void Init_rugged()
250
305
  int i;
251
306
 
252
307
  rb_eRuggedError = rb_define_class_under(rb_mRugged, "Error", rb_eStandardError);
253
- rb_eRuggedErrors[0] = rb_eNoMemError;
254
308
 
255
- for (i = 1; i < RUGGED_ERROR_COUNT; ++i) {
309
+ rb_eRuggedErrors[0] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[0], rb_eNoMemError);
310
+ rb_eRuggedErrors[1] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[1], rb_eIOError);
311
+ rb_eRuggedErrors[2] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[2], rb_eArgError);
312
+
313
+ for (i = 3; i < RUGGED_ERROR_COUNT; ++i) {
256
314
  rb_eRuggedErrors[i] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[i], rb_eRuggedError);
257
315
  }
258
316
  }
259
317
 
318
+ rb_define_module_function(rb_mRugged, "libgit2_version", rb_git_libgit2_version, 0);
319
+ rb_define_module_function(rb_mRugged, "capabilities", rb_git_capabilities, 0);
260
320
  rb_define_module_function(rb_mRugged, "hex_to_raw", rb_git_hex_to_raw, 1);
261
321
  rb_define_module_function(rb_mRugged, "raw_to_hex", rb_git_raw_to_hex, 1);
262
322
  rb_define_module_function(rb_mRugged, "minimize_oid", rb_git_minimize_oid, -1);
@@ -275,6 +335,8 @@ void Init_rugged()
275
335
  Init_rugged_branch();
276
336
  Init_rugged_config();
277
337
  Init_rugged_remote();
338
+ Init_rugged_notes();
339
+ Init_rugged_settings();
278
340
 
279
341
  /* Constants */
280
342
  rb_define_const(rb_mRugged, "SORT_NONE", INT2FIX(0));
data/ext/rugged/rugged.h CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2011 GitHub, Inc
4
+ * Copyright (c) 2013 GitHub, Inc
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -57,6 +57,8 @@ void Init_rugged_revwalk();
57
57
  void Init_rugged_reference();
58
58
  void Init_rugged_config();
59
59
  void Init_rugged_remote();
60
+ void Init_rugged_notes();
61
+ void Init_rugged_settings();
60
62
 
61
63
  VALUE rb_git_object_init(git_otype type, int argc, VALUE *argv, VALUE self);
62
64
 
@@ -65,15 +67,16 @@ VALUE rugged_raw_read(git_repository *repo, const git_oid *oid);
65
67
  VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name);
66
68
 
67
69
  VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index);
68
- VALUE rugged_object_new(VALUE owner, git_object *object);
69
70
  VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg);
71
+ VALUE rugged_object_new(VALUE owner, git_object *object);
70
72
  VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref);
71
73
 
72
74
  VALUE rugged_otype_new(git_otype t);
73
75
  git_otype rugged_otype_get(VALUE rb_type);
74
76
 
75
77
  git_signature *rugged_signature_get(VALUE rb_person);
76
- git_object *rugged_object_load(git_repository *repo, VALUE object_value, git_otype type);
78
+ git_object *rugged_object_get(git_repository *repo, VALUE object_value, git_otype type);
79
+ void rugged_oid_get(git_oid *oid, git_repository *repo, VALUE p);
77
80
 
78
81
  static inline void rugged_set_owner(VALUE object, VALUE owner)
79
82
  {
@@ -101,6 +104,14 @@ static inline int rugged_parse_bool(VALUE boolean)
101
104
  return boolean ? 1 : 0;
102
105
  }
103
106
 
107
+ extern VALUE rb_cRuggedRepo;
108
+
109
+ static inline void rugged_check_repo(VALUE rb_repo)
110
+ {
111
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
112
+ rb_raise(rb_eTypeError, "Expecting a Rugged Repository");
113
+ }
114
+
104
115
  /* support for string encodings in 1.9 */
105
116
  #ifdef HAVE_RUBY_ENCODING_H
106
117
  # define rugged_str_new(str, len, enc) rb_enc_str_new(str, len, enc)
@@ -120,11 +131,4 @@ static inline VALUE rugged_create_oid(const git_oid *oid)
120
131
  return rugged_str_new(out, 40, NULL);
121
132
  }
122
133
 
123
- #define RUGGED_UNPACK_REFERENCE(_rb_obj, _rugged_obj) {\
124
- if (DATA_PTR(_rb_obj) == NULL)\
125
- rb_raise(rb_eRuntimeError,\
126
- "This Git Reference has been deleted and no longer exists on the repository");\
127
- Data_Get_Struct(_rb_obj, git_reference, _rugged_obj);\
128
- }
129
-
130
134
  #endif