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
data/lib/rugged.rb CHANGED
@@ -9,4 +9,5 @@ require 'rugged/walker'
9
9
  require 'rugged/tree'
10
10
  require 'rugged/tag'
11
11
  require 'rugged/branch'
12
+ require 'rugged/diff'
12
13
  require 'rugged/remote'
data/lib/rugged/commit.rb CHANGED
@@ -6,7 +6,22 @@ module Rugged
6
6
  end
7
7
 
8
8
  def inspect
9
- "#<Rugged::Commit:#{object_id} {message: #{message.inspect}, tree: #{tree.inspect}, parents: #{parent_oids}>"
9
+ "#<Rugged::Commit:#{object_id} {message: #{message.inspect}, tree: #{tree.inspect}, parents: #{parent_oids}}>"
10
+ end
11
+
12
+ # Return a diff between this commit and its first parent or another commit or tree.
13
+ #
14
+ # See Rugged::Tree#diff for more details.
15
+ def diff(*args)
16
+ args.unshift(parents.first) if args.size == 1 && args.first.is_a?(Hash)
17
+ self.tree.diff(*args)
18
+ end
19
+
20
+ # Return a diff between this commit and the workdir.
21
+ #
22
+ # See Rugged::Tree#diff_workdir for more details.
23
+ def diff_workdir(options = {})
24
+ self.tree.diff_workdir(options)
10
25
  end
11
26
 
12
27
  # The time when this commit was made effective. This is the same value
@@ -0,0 +1,9 @@
1
+ # Loaded by script/console. Land helpers here.
2
+
3
+ def repo
4
+ Rugged::Repository.new(File.expand_path('../../../', __FILE__))
5
+ end
6
+
7
+ Pry.config.prompt = lambda do |context, nesting, pry|
8
+ "[rugged] #{context}> "
9
+ end
@@ -0,0 +1,19 @@
1
+ require 'rugged/diff/patch'
2
+ require 'rugged/diff/hunk'
3
+ require 'rugged/diff/line'
4
+ require 'rugged/diff/delta'
5
+
6
+ module Rugged
7
+ class Diff
8
+ include Enumerable
9
+ alias each each_patch
10
+
11
+ def patches
12
+ each_patch.to_a
13
+ end
14
+
15
+ def deltas
16
+ each_delta.to_a
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,54 @@
1
+ module Rugged
2
+ class Diff
3
+ class Delta
4
+ include Enumerable
5
+
6
+ attr_reader :owner
7
+ alias diff owner
8
+
9
+ attr_reader :old_file
10
+ attr_reader :new_file
11
+ attr_reader :similarity
12
+ attr_reader :status
13
+ attr_reader :binary
14
+
15
+ alias binary? binary
16
+
17
+ def added?
18
+ status == :added
19
+ end
20
+
21
+ def deleted?
22
+ status == :deleted
23
+ end
24
+
25
+ def modified?
26
+ status == :modified
27
+ end
28
+
29
+ def renamed?
30
+ status == :renamed
31
+ end
32
+
33
+ def copied?
34
+ status == :copied
35
+ end
36
+
37
+ def ignored?
38
+ status == :ignored
39
+ end
40
+
41
+ def untracked?
42
+ status == :untracked
43
+ end
44
+
45
+ def typechange?
46
+ status == :typechange
47
+ end
48
+
49
+ def inspect
50
+ "#<#{self.class.name}:#{object_id} {old_file: #{old_file.inspect}, new_file: #{new_file.inspect}, similarity: #{similarity.inspect}, status: #{status.inspect}>"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,23 @@
1
+ module Rugged
2
+ class Diff
3
+ class Hunk
4
+ include Enumerable
5
+ alias each each_line
6
+
7
+ attr_reader :line_count, :header, :range, :owner
8
+
9
+ alias size line_count
10
+ alias count line_count
11
+ alias delta owner
12
+
13
+ def inspect
14
+ "#<#{self.class.name}:#{object_id} {header: #{header.inspect}, range: #{range.inspect}>"
15
+ end
16
+
17
+ # Returns an Array containing all lines of the hunk.
18
+ def lines
19
+ each_line.to_a
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ module Rugged
2
+ class Diff
3
+ class Line
4
+ attr_reader :line_origin, :content, :owner, :old_lineno, :new_lineno
5
+
6
+ alias hunk owner
7
+
8
+ def context?
9
+ @line_origin == :context
10
+ end
11
+
12
+ def addition?
13
+ @line_origin == :addition
14
+ end
15
+
16
+ def deletion?
17
+ @line_origin == :deletion
18
+ end
19
+
20
+ def eof_newline?
21
+ @line_origin == :eof_newline
22
+ end
23
+
24
+ def inspect
25
+ "#<#{self.class.name}:#{object_id} {line_origin: #{line_origin.inspect}, content: #{content.inspect}>"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ module Rugged
2
+ class Diff
3
+ class Patch
4
+ include Enumerable
5
+ alias each each_hunk
6
+
7
+ alias size hunk_count
8
+ alias count hunk_count
9
+
10
+ attr_accessor :owner
11
+ alias diff owner
12
+
13
+ def inspect
14
+ "#<#{self.class.name}:#{object_id}>"
15
+ end
16
+
17
+ # Returns the number of changes in the patch.
18
+ def changes
19
+ additions + deletions
20
+ end
21
+
22
+ # Returns an Array containing all hunks of the patch.
23
+ def hunks
24
+ each_hunk.to_a
25
+ end
26
+ end
27
+ end
28
+ end
@@ -17,6 +17,35 @@ module Rugged
17
17
  self.lookup self.head.target
18
18
  end
19
19
 
20
+ def diff(left, right, opts = {})
21
+ left = rev_parse(left) if left.kind_of?(String)
22
+ right = rev_parse(right) if right.kind_of?(String)
23
+
24
+ if !left.is_a?(Rugged::Tree) && !left.is_a?(Rugged::Commit) && !left.nil?
25
+ raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
26
+ end
27
+
28
+ if !right.is_a?(Rugged::Tree) && !right.is_a?(Rugged::Commit) && !right.nil?
29
+ raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
30
+ end
31
+
32
+ if left
33
+ left.diff(right, opts)
34
+ elsif right
35
+ right.diff(left, opts.merge(:reverse => !opts[:reverse]))
36
+ end
37
+ end
38
+
39
+ def diff_workdir(left, opts = {})
40
+ left = rev_parse(left) if left.kind_of?(String)
41
+
42
+ if !left.is_a?(Rugged::Tree) && !left.is_a?(Rugged::Commit)
43
+ raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
44
+ end
45
+
46
+ left.diff_workdir(opts)
47
+ end
48
+
20
49
  # Walks over a set of commits using Rugged::Walker.
21
50
  #
22
51
  # from - The String SHA1 to push onto Walker to begin our walk.
@@ -32,14 +61,6 @@ module Rugged
32
61
  walker.each(&block)
33
62
  end
34
63
 
35
- # Find the HEAD of this repository.
36
- #
37
- # Returns a Reference.
38
- def head
39
- ref = Reference.lookup(self, "HEAD")
40
- ref.resolve
41
- end
42
-
43
64
  # Look up a SHA1.
44
65
  #
45
66
  # Returns one of the four classes that inherit from Rugged::Object.
@@ -74,37 +95,12 @@ module Rugged
74
95
  Rugged::Reference.lookup(self, ref_name)
75
96
  end
76
97
 
77
- # Retuns all the References that match a pattern.
78
- #
79
- # refs - A Regexp (or String) to search for. Optional.
80
- #
81
- # Examples:
82
- #
83
- # # All refs
84
- # repo.refs
85
- #
86
- # # All remote refs
87
- # repo.refs 'refs/remotes'
88
- #
89
- # Returns an Array of References.
90
- def refs(pattern = nil)
91
- r = []
92
- ref_names.each do |ref_name|
93
- if pattern
94
- p = Regexp.new(pattern)
95
- r << Rugged::Reference.lookup(self, ref_name) if p.match(ref_name)
96
- else
97
- r << Rugged::Reference.lookup(self, ref_name)
98
- end
99
- end
100
- r
98
+ def refs(glob = nil)
99
+ Rugged::Reference.each(self, glob)
101
100
  end
102
101
 
103
- # The names of all the refs.
104
- #
105
- # Returns an Enumerable::Enumerator containing all the String ref names.
106
- def ref_names
107
- Rugged::Reference.each(self)
102
+ def ref_names(glob = nil)
103
+ Rugged::Reference.each_name(self, glob)
108
104
  end
109
105
 
110
106
  # All the tags in the repository.
@@ -116,7 +112,8 @@ module Rugged
116
112
 
117
113
  # All the remotes in the repository.
118
114
  #
119
- # Returns an Enumerable::Enumerator containing all the String remote names.
115
+ # Returns an Enumerable::Enumerator containing all the Rugged::Remotes in
116
+ # the repository.
120
117
  def remotes
121
118
  Rugged::Remote.each(self)
122
119
  end
@@ -156,7 +153,7 @@ module Rugged
156
153
  tree = Rugged::Commit.lookup(self, revision).tree
157
154
  begin
158
155
  blob_data = tree.path(path)
159
- rescue Rugged::IndexerError
156
+ rescue Rugged::TreeError
160
157
  return nil
161
158
  end
162
159
  blob = Rugged::Blob.lookup(self, blob_data[:oid])
@@ -1,3 +1,3 @@
1
1
  module Rugged
2
- Version = VERSION = '0.18.0.gh.de28323'
2
+ Version = VERSION = '0.19.0'
3
3
  end
data/test/blob_test.rb CHANGED
@@ -10,6 +10,81 @@ class BlobTest < Rugged::TestCase
10
10
  assert_equal "new file\n", blob.content
11
11
  assert_equal :blob, blob.type
12
12
  assert_equal oid, blob.oid
13
+ assert_equal "new file\n", blob.text
14
+ end
15
+
16
+ def test_blob_sloc
17
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
18
+ blob = @repo.lookup(oid)
19
+ assert_equal 328, blob.sloc
20
+ end
21
+
22
+ def test_blob_content_with_size
23
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
24
+ blob = @repo.lookup(oid)
25
+ content = blob.content(10)
26
+ assert_equal "# Rugged\n*", content
27
+ assert_equal 10, content.size
28
+ end
29
+
30
+ def test_blob_content_with_size_gt_file_size
31
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
32
+ blob = @repo.lookup(oid)
33
+ content = blob.content(1000000)
34
+ assert_equal blob.size, content.size
35
+ end
36
+
37
+ def test_blob_content_with_zero_size
38
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
39
+ blob = @repo.lookup(oid)
40
+ content = blob.content(0)
41
+ assert_equal '', content
42
+ end
43
+
44
+ def test_blob_content_with_negative_size
45
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
46
+ blob = @repo.lookup(oid)
47
+ content = blob.content(-100)
48
+ assert_equal blob.size, content.size
49
+ end
50
+
51
+ def test_blob_text_with_max_lines
52
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
53
+ blob = @repo.lookup(oid)
54
+ assert_equal "# Rugged\n", blob.text(1)
55
+ end
56
+
57
+ def test_blob_text_with_lines_gt_file_lines
58
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
59
+ blob = @repo.lookup(oid)
60
+ text = blob.text(1000000)
61
+ assert_equal 464, text.lines.count
62
+ end
63
+
64
+ def test_blob_text_with_zero_lines
65
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
66
+ blob = @repo.lookup(oid)
67
+ text = blob.text(0)
68
+ assert_equal '', text
69
+ end
70
+
71
+ def test_blob_text_with_negative_lines
72
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
73
+ blob = @repo.lookup(oid)
74
+ text = blob.text(-100)
75
+ assert_equal 464, text.lines.count
76
+ end
77
+
78
+ def test_blob_text_default_encoding
79
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
80
+ blob = @repo.lookup(oid)
81
+ assert_equal Encoding::UTF_8, blob.text.encoding
82
+ end
83
+
84
+ def test_blob_text_set_encoding
85
+ oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
86
+ blob = @repo.lookup(oid)
87
+ assert_equal Encoding::ASCII_8BIT, blob.text(0, Encoding::ASCII_8BIT).encoding
13
88
  end
14
89
  end
15
90
 
@@ -29,6 +104,238 @@ class BlobWriteTest < Rugged::TestCase
29
104
  end
30
105
 
31
106
  def test_write_blob_data
32
- Rugged::Blob.create(@repo, "a new blob content")
107
+ assert_equal '1d83f106355e4309a293e42ad2a2c4b8bdbe77ae',
108
+ Rugged::Blob.from_buffer(@repo, "a new blob content")
109
+ end
110
+
111
+ def test_write_blob_from_workdir
112
+ assert_equal '1385f264afb75a56a5bec74243be9b367ba4ca08',
113
+ Rugged::Blob.from_workdir(@repo, "README")
114
+ end
115
+
116
+ def test_write_blob_from_disk
117
+ file_path = File.join(TEST_DIR, (File.join('fixtures', 'archive.tar.gz')))
118
+ File.open(file_path, 'rb') do |file|
119
+ oid = Rugged::Blob.from_disk(@repo, file.path)
120
+ assert oid
121
+
122
+ blob = @repo.lookup(oid)
123
+ file.rewind
124
+ assert_equal file.read, blob.content
125
+ end
126
+ end
127
+
128
+ def test_blob_is_binary
129
+ binary_file_path = File.join(TEST_DIR, (File.join('fixtures', 'archive.tar.gz')))
130
+ binary_blob = @repo.lookup(Rugged::Blob.from_disk(@repo, binary_file_path))
131
+ assert binary_blob.binary?
132
+
133
+ text_file_path = File.join(TEST_DIR, (File.join('fixtures', 'text_file.md')))
134
+ text_blob = @repo.lookup(Rugged::Blob.from_disk(@repo, text_file_path))
135
+ refute text_blob.binary?
33
136
  end
34
137
  end
138
+
139
+ class BlobDiffTest < Rugged::SandboxedTestCase
140
+ def test_diff_blob
141
+ repo = sandbox_init("diff")
142
+
143
+ a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
144
+ b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
145
+
146
+ blob = repo.lookup(a.tree["readme.txt"][:oid])
147
+ other = repo.lookup(b.tree["readme.txt"][:oid])
148
+
149
+ patch = blob.diff(other)
150
+
151
+ assert_equal :modified, patch.delta.status
152
+
153
+ hunks = []
154
+ patch.each_hunk do |hunk|
155
+ assert_instance_of Rugged::Diff::Hunk, hunk
156
+ hunks << hunk
157
+ end
158
+ assert_equal 3, hunks.size
159
+
160
+ assert hunks[0].header.start_with? "@@ -1,4 +1,4 @@"
161
+ assert hunks[1].header.start_with? "@@ -7,10 +7,6 @@"
162
+ assert hunks[2].header.start_with? "@@ -24,12 +20,9 @@"
163
+
164
+ lines = []
165
+ hunks[0].each_line do |line|
166
+ lines << line
167
+ end
168
+ assert_equal 5, lines.size
169
+
170
+ assert_equal :deletion, lines[0].line_origin
171
+ assert_equal "The Git feature that really makes it stand apart from nearly every other SCM\n", lines[0].content
172
+
173
+ assert_equal :addition, lines[1].line_origin
174
+ assert_equal "The Git feature that r3ally mak3s it stand apart from n3arly 3v3ry other SCM\n", lines[1].content
175
+
176
+ assert_equal :context, lines[2].line_origin
177
+ assert_equal "out there is its branching model.\n", lines[2].content
178
+
179
+ assert_equal :context, lines[3].line_origin
180
+ assert_equal "\n", lines[3].content
181
+
182
+ assert_equal :context, lines[4].line_origin
183
+ assert_equal "Git allows and encourages you to have multiple local branches that can be\n", lines[4].content
184
+ end
185
+
186
+ def test_diff_string
187
+ repo = sandbox_init("diff")
188
+
189
+ a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
190
+ b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
191
+
192
+ blob = repo.lookup(a.tree["readme.txt"][:oid])
193
+ other = repo.lookup(b.tree["readme.txt"][:oid]).content
194
+
195
+ patch = blob.diff(other)
196
+
197
+ assert_equal :modified, patch.delta.status
198
+
199
+ hunks = []
200
+ patch.each_hunk do |hunk|
201
+ assert_instance_of Rugged::Diff::Hunk, hunk
202
+ hunks << hunk
203
+ end
204
+ assert_equal 3, hunks.size
205
+
206
+ assert hunks[0].header.start_with? "@@ -1,4 +1,4 @@"
207
+ assert hunks[1].header.start_with? "@@ -7,10 +7,6 @@"
208
+ assert hunks[2].header.start_with? "@@ -24,12 +20,9 @@"
209
+
210
+ lines = []
211
+ hunks[0].each_line do |line|
212
+ lines << line
213
+ end
214
+ assert_equal 5, lines.size
215
+
216
+ assert_equal :deletion, lines[0].line_origin
217
+ assert_equal "The Git feature that really makes it stand apart from nearly every other SCM\n", lines[0].content
218
+
219
+ assert_equal :addition, lines[1].line_origin
220
+ assert_equal "The Git feature that r3ally mak3s it stand apart from n3arly 3v3ry other SCM\n", lines[1].content
221
+
222
+ assert_equal :context, lines[2].line_origin
223
+ assert_equal "out there is its branching model.\n", lines[2].content
224
+
225
+ assert_equal :context, lines[3].line_origin
226
+ assert_equal "\n", lines[3].content
227
+
228
+ assert_equal :context, lines[4].line_origin
229
+ assert_equal "Git allows and encourages you to have multiple local branches that can be\n", lines[4].content
230
+ end
231
+
232
+ def test_diff_nil
233
+ repo = sandbox_init("diff")
234
+
235
+ a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
236
+
237
+ blob = repo.lookup(a.tree["readme.txt"][:oid])
238
+
239
+ patch = blob.diff(nil)
240
+
241
+ assert_equal :deleted, patch.delta.status
242
+
243
+ hunks = []
244
+ patch.each_hunk do |hunk|
245
+ assert_instance_of Rugged::Diff::Hunk, hunk
246
+ hunks << hunk
247
+ end
248
+ assert_equal 1, hunks.size
249
+
250
+ assert hunks[0].header.start_with? "@@ -1,35 +0,0 @@"
251
+
252
+ lines = []
253
+ hunks[0].each_line do |line|
254
+ lines << line
255
+ end
256
+ assert_equal 35, lines.size
257
+
258
+ lines.each do |line|
259
+ assert_equal :deletion, line.line_origin
260
+ end
261
+ end
262
+
263
+ def test_diff_with_paths
264
+ repo = sandbox_init("diff")
265
+
266
+ a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
267
+ b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
268
+
269
+ blob = repo.lookup(a.tree["readme.txt"][:oid])
270
+ other = repo.lookup(b.tree["readme.txt"][:oid])
271
+
272
+ patch = blob.diff(other, :old_path => "old_readme.txt", :new_path => "new_readme.txt")
273
+ assert_equal "old_readme.txt", patch.delta.old_file[:path]
274
+ assert_equal "new_readme.txt", patch.delta.new_file[:path]
275
+ end
276
+ end
277
+
278
+ class BlobCreateFromChunksTest < Rugged::TestCase
279
+ include Rugged::TempRepositoryAccess
280
+
281
+ def test_write_blob_from_chunks_with_hintpath
282
+ file_path= File.join(TEST_DIR, (File.join('fixtures', 'archive.tar.gz')))
283
+ File.open(file_path, 'rb') do |io|
284
+ oid = Rugged::Blob.from_chunks(@repo, io, 'archive.tar.gz2')
285
+ io.rewind
286
+ blob = @repo.lookup(oid)
287
+ assert_equal io.read, blob.content
288
+ end
289
+ end
290
+
291
+ def test_write_blob_from_chunks_without_hintpath
292
+ file_path= File.join(TEST_DIR, (File.join('fixtures', 'archive.tar.gz')))
293
+ File.open(file_path, 'rb') do |io|
294
+ oid = Rugged::Blob.from_chunks(@repo, io)
295
+ io.rewind
296
+ blob = @repo.lookup(oid)
297
+ assert_equal io.read, blob.content
298
+ end
299
+ end
300
+
301
+ class BrokenIO
302
+ def read(length)
303
+ raise IOError
304
+ end
305
+ end
306
+
307
+ def test_write_blob_from_chunks_broken_io
308
+ oid = Rugged::Blob.from_chunks(@repo, BrokenIO.new)
309
+ blob = @repo.lookup(oid)
310
+ assert_equal 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391',
311
+ blob.oid
312
+ assert_equal 0, blob.size
313
+ end
314
+
315
+ class OverflowIO
316
+ def initialize()
317
+ @called = false
318
+ end
319
+
320
+ def read(size)
321
+ res = @called ? nil : 'a' * size * 4
322
+ @called = true
323
+ res
324
+ end
325
+ end
326
+
327
+ def test_write_blob_from_chunks_overflow_io
328
+ assert Rugged::Blob.from_chunks(@repo, OverflowIO.new)
329
+ end
330
+
331
+ class BadIO
332
+ def read(length)
333
+ :invalid_data
334
+ end
335
+ end
336
+
337
+ def test_write_blob_from_chunks_bad_io
338
+ assert Rugged::Blob.from_chunks(@repo, BadIO.new)
339
+ end
340
+
341
+ end