rugged 0.21.4 → 0.22.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -5
  3. data/ext/rugged/extconf.rb +9 -9
  4. data/ext/rugged/rugged.c +4 -2
  5. data/ext/rugged/rugged.h +3 -7
  6. data/ext/rugged/rugged_blob.c +57 -0
  7. data/ext/rugged/rugged_cred.c +23 -0
  8. data/ext/rugged/rugged_index.c +6 -2
  9. data/ext/rugged/rugged_remote.c +65 -52
  10. data/ext/rugged/rugged_remote_collection.c +59 -10
  11. data/ext/rugged/rugged_repo.c +345 -11
  12. data/ext/rugged/rugged_revwalk.c +10 -0
  13. data/ext/rugged/rugged_submodule.c +1042 -0
  14. data/ext/rugged/rugged_submodule_collection.c +236 -0
  15. data/ext/rugged/rugged_tag_collection.c +70 -2
  16. data/ext/rugged/rugged_tree.c +29 -10
  17. data/lib/rugged.rb +3 -0
  18. data/lib/rugged/attributes.rb +41 -0
  19. data/lib/rugged/blob.rb +28 -0
  20. data/lib/rugged/diff.rb +0 -1
  21. data/lib/rugged/diff/line.rb +1 -3
  22. data/lib/rugged/patch.rb +12 -2
  23. data/lib/rugged/repository.rb +7 -0
  24. data/lib/rugged/submodule_collection.rb +48 -0
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/CMakeLists.txt +27 -3
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  28. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  29. data/vendor/libgit2/deps/zlib/adler32.c +39 -29
  30. data/vendor/libgit2/deps/zlib/crc32.c +33 -50
  31. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  32. data/vendor/libgit2/deps/zlib/deflate.c +198 -65
  33. data/vendor/libgit2/deps/zlib/deflate.h +8 -4
  34. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  35. data/vendor/libgit2/deps/zlib/inffast.c +3 -3
  36. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  37. data/vendor/libgit2/deps/zlib/inflate.c +84 -52
  38. data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
  39. data/vendor/libgit2/deps/zlib/trees.c +18 -36
  40. data/vendor/libgit2/deps/zlib/zconf.h +4 -0
  41. data/vendor/libgit2/deps/zlib/zlib.h +250 -95
  42. data/vendor/libgit2/deps/zlib/zutil.c +13 -10
  43. data/vendor/libgit2/deps/zlib/zutil.h +41 -62
  44. data/vendor/libgit2/include/git2.h +4 -0
  45. data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
  46. data/vendor/libgit2/include/git2/attr.h +16 -13
  47. data/vendor/libgit2/include/git2/branch.h +11 -0
  48. data/vendor/libgit2/include/git2/buffer.h +16 -0
  49. data/vendor/libgit2/include/git2/checkout.h +12 -12
  50. data/vendor/libgit2/include/git2/cherrypick.h +15 -15
  51. data/vendor/libgit2/include/git2/clone.h +77 -69
  52. data/vendor/libgit2/include/git2/common.h +13 -1
  53. data/vendor/libgit2/include/git2/config.h +0 -14
  54. data/vendor/libgit2/include/git2/describe.h +162 -0
  55. data/vendor/libgit2/include/git2/diff.h +13 -8
  56. data/vendor/libgit2/include/git2/errors.h +5 -0
  57. data/vendor/libgit2/include/git2/global.h +38 -0
  58. data/vendor/libgit2/include/git2/merge.h +38 -64
  59. data/vendor/libgit2/include/git2/net.h +2 -2
  60. data/vendor/libgit2/include/git2/notes.h +17 -0
  61. data/vendor/libgit2/include/git2/oid.h +8 -4
  62. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  63. data/vendor/libgit2/include/git2/rebase.h +261 -0
  64. data/vendor/libgit2/include/git2/reflog.h +1 -1
  65. data/vendor/libgit2/include/git2/remote.h +25 -47
  66. data/vendor/libgit2/include/git2/repository.h +4 -1
  67. data/vendor/libgit2/include/git2/reset.h +10 -1
  68. data/vendor/libgit2/include/git2/revert.h +1 -1
  69. data/vendor/libgit2/include/git2/revwalk.h +28 -23
  70. data/vendor/libgit2/include/git2/status.h +19 -15
  71. data/vendor/libgit2/include/git2/submodule.h +18 -0
  72. data/vendor/libgit2/include/git2/sys/config.h +0 -1
  73. data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
  74. data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
  75. data/vendor/libgit2/include/git2/sys/refs.h +0 -11
  76. data/vendor/libgit2/include/git2/sys/repository.h +13 -0
  77. data/vendor/libgit2/include/git2/sys/transport.h +352 -0
  78. data/vendor/libgit2/include/git2/threads.h +10 -20
  79. data/vendor/libgit2/include/git2/transaction.h +111 -0
  80. data/vendor/libgit2/include/git2/transport.h +79 -313
  81. data/vendor/libgit2/include/git2/tree.h +4 -2
  82. data/vendor/libgit2/include/git2/types.h +77 -8
  83. data/vendor/libgit2/include/git2/version.h +2 -2
  84. data/vendor/libgit2/src/annotated_commit.c +121 -0
  85. data/vendor/libgit2/src/annotated_commit.h +22 -0
  86. data/vendor/libgit2/src/attr.c +8 -4
  87. data/vendor/libgit2/src/attr_file.c +24 -2
  88. data/vendor/libgit2/src/blame.c +0 -1
  89. data/vendor/libgit2/src/branch.c +32 -3
  90. data/vendor/libgit2/src/buf_text.c +9 -5
  91. data/vendor/libgit2/src/buf_text.h +3 -2
  92. data/vendor/libgit2/src/buffer.c +67 -10
  93. data/vendor/libgit2/src/buffer.h +4 -2
  94. data/vendor/libgit2/src/cache.c +9 -9
  95. data/vendor/libgit2/src/cache.h +1 -1
  96. data/vendor/libgit2/src/cc-compat.h +2 -0
  97. data/vendor/libgit2/src/checkout.c +263 -82
  98. data/vendor/libgit2/src/checkout.h +1 -0
  99. data/vendor/libgit2/src/cherrypick.c +41 -44
  100. data/vendor/libgit2/src/clone.c +96 -58
  101. data/vendor/libgit2/src/commit.c +5 -31
  102. data/vendor/libgit2/src/commit_list.h +3 -1
  103. data/vendor/libgit2/src/config.c +0 -17
  104. data/vendor/libgit2/src/config_cache.c +0 -2
  105. data/vendor/libgit2/src/config_file.c +12 -15
  106. data/vendor/libgit2/src/crlf.c +2 -1
  107. data/vendor/libgit2/src/describe.c +886 -0
  108. data/vendor/libgit2/src/diff.c +29 -3
  109. data/vendor/libgit2/src/diff_file.c +1 -0
  110. data/vendor/libgit2/src/diff_patch.c +2 -3
  111. data/vendor/libgit2/src/diff_print.c +11 -9
  112. data/vendor/libgit2/src/diff_tform.c +4 -4
  113. data/vendor/libgit2/src/errors.c +9 -7
  114. data/vendor/libgit2/src/fetch.c +6 -6
  115. data/vendor/libgit2/src/fetchhead.h +2 -4
  116. data/vendor/libgit2/src/filebuf.c +0 -2
  117. data/vendor/libgit2/src/filebuf.h +2 -3
  118. data/vendor/libgit2/src/fileops.c +9 -7
  119. data/vendor/libgit2/src/global.c +44 -35
  120. data/vendor/libgit2/src/global.h +2 -0
  121. data/vendor/libgit2/src/graph.c +2 -2
  122. data/vendor/libgit2/src/hash.h +3 -1
  123. data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
  124. data/vendor/libgit2/src/hash/hash_win32.c +1 -1
  125. data/vendor/libgit2/src/hashsig.c +1 -1
  126. data/vendor/libgit2/src/ignore.c +5 -88
  127. data/vendor/libgit2/src/index.c +70 -57
  128. data/vendor/libgit2/src/index.h +1 -0
  129. data/vendor/libgit2/src/indexer.c +16 -5
  130. data/vendor/libgit2/src/iterator.c +70 -1
  131. data/vendor/libgit2/src/iterator.h +5 -1
  132. data/vendor/libgit2/src/map.h +0 -1
  133. data/vendor/libgit2/src/merge.c +203 -327
  134. data/vendor/libgit2/src/merge.h +3 -13
  135. data/vendor/libgit2/src/mwindow.c +119 -8
  136. data/vendor/libgit2/src/mwindow.h +9 -1
  137. data/vendor/libgit2/src/netops.c +7 -8
  138. data/vendor/libgit2/src/netops.h +6 -16
  139. data/vendor/libgit2/src/notes.c +31 -4
  140. data/vendor/libgit2/src/notes.h +3 -0
  141. data/vendor/libgit2/src/odb.c +23 -1
  142. data/vendor/libgit2/src/odb_loose.c +1 -1
  143. data/vendor/libgit2/src/odb_pack.c +6 -3
  144. data/vendor/libgit2/src/oid.c +9 -1
  145. data/vendor/libgit2/src/oid.h +11 -0
  146. data/vendor/libgit2/src/oidarray.c +21 -0
  147. data/vendor/libgit2/src/oidarray.h +18 -0
  148. data/vendor/libgit2/src/oidmap.h +16 -0
  149. data/vendor/libgit2/src/pack.c +20 -7
  150. data/vendor/libgit2/src/pack.h +3 -0
  151. data/vendor/libgit2/src/path.c +120 -293
  152. data/vendor/libgit2/src/path.h +21 -44
  153. data/vendor/libgit2/src/pathspec.c +1 -1
  154. data/vendor/libgit2/src/pool.c +5 -11
  155. data/vendor/libgit2/src/pool.h +0 -2
  156. data/vendor/libgit2/src/posix.c +6 -6
  157. data/vendor/libgit2/src/posix.h +48 -28
  158. data/vendor/libgit2/src/push.c +19 -48
  159. data/vendor/libgit2/src/push.h +2 -4
  160. data/vendor/libgit2/src/rebase.c +1125 -0
  161. data/vendor/libgit2/src/refdb.c +19 -0
  162. data/vendor/libgit2/src/refdb.h +2 -1
  163. data/vendor/libgit2/src/refdb_fs.c +101 -29
  164. data/vendor/libgit2/src/reflog.c +1 -1
  165. data/vendor/libgit2/src/refs.c +38 -3
  166. data/vendor/libgit2/src/refs.h +13 -2
  167. data/vendor/libgit2/src/refspec.c +20 -2
  168. data/vendor/libgit2/src/remote.c +288 -154
  169. data/vendor/libgit2/src/remote.h +5 -1
  170. data/vendor/libgit2/src/repository.c +75 -36
  171. data/vendor/libgit2/src/repository.h +3 -25
  172. data/vendor/libgit2/src/reset.c +5 -1
  173. data/vendor/libgit2/src/revert.c +4 -6
  174. data/vendor/libgit2/src/revparse.c +15 -18
  175. data/vendor/libgit2/src/revwalk.c +96 -22
  176. data/vendor/libgit2/src/revwalk.h +5 -4
  177. data/vendor/libgit2/src/settings.c +22 -0
  178. data/vendor/libgit2/src/signature.c +37 -2
  179. data/vendor/libgit2/src/signature.h +3 -0
  180. data/vendor/libgit2/src/stash.c +17 -12
  181. data/vendor/libgit2/src/status.c +13 -3
  182. data/vendor/libgit2/src/strnlen.h +2 -1
  183. data/vendor/libgit2/src/submodule.c +75 -35
  184. data/vendor/libgit2/src/thread-utils.h +4 -9
  185. data/vendor/libgit2/src/trace.h +9 -1
  186. data/vendor/libgit2/src/transaction.c +352 -0
  187. data/vendor/libgit2/src/transport.c +91 -97
  188. data/vendor/libgit2/src/transports/auth.c +71 -0
  189. data/vendor/libgit2/src/transports/auth.h +63 -0
  190. data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
  191. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  192. data/vendor/libgit2/src/transports/cred.c +58 -0
  193. data/vendor/libgit2/src/transports/cred.h +14 -0
  194. data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
  195. data/vendor/libgit2/src/transports/git.c +1 -0
  196. data/vendor/libgit2/src/transports/http.c +208 -82
  197. data/vendor/libgit2/src/transports/local.c +2 -2
  198. data/vendor/libgit2/src/transports/smart.c +2 -0
  199. data/vendor/libgit2/src/transports/smart.h +2 -0
  200. data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
  201. data/vendor/libgit2/src/transports/ssh.c +243 -57
  202. data/vendor/libgit2/src/transports/winhttp.c +139 -35
  203. data/vendor/libgit2/src/tree-cache.c +118 -31
  204. data/vendor/libgit2/src/tree-cache.h +12 -7
  205. data/vendor/libgit2/src/tree.c +83 -64
  206. data/vendor/libgit2/src/tree.h +2 -3
  207. data/vendor/libgit2/src/unix/map.c +8 -2
  208. data/vendor/libgit2/src/unix/posix.h +23 -9
  209. data/vendor/libgit2/src/unix/realpath.c +8 -7
  210. data/vendor/libgit2/src/userdiff.h +3 -3
  211. data/vendor/libgit2/src/util.c +2 -92
  212. data/vendor/libgit2/src/util.h +3 -15
  213. data/vendor/libgit2/src/win32/findfile.c +0 -1
  214. data/vendor/libgit2/src/win32/map.c +3 -2
  215. data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
  216. data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
  217. data/vendor/libgit2/src/win32/posix.h +20 -32
  218. data/vendor/libgit2/src/win32/posix_w32.c +103 -31
  219. data/vendor/libgit2/src/win32/utf-conv.c +6 -36
  220. data/vendor/libgit2/src/win32/utf-conv.h +39 -0
  221. data/vendor/libgit2/src/win32/w32_util.h +0 -1
  222. metadata +32 -7
  223. data/vendor/libgit2/src/win32/path_w32.c +0 -305
  224. data/vendor/libgit2/src/win32/path_w32.h +0 -82
@@ -223,6 +223,15 @@ static VALUE rb_git_walker_push(VALUE self, VALUE rb_commit)
223
223
  return Qnil;
224
224
  }
225
225
 
226
+ static VALUE rb_git_walker_push_range(VALUE self, VALUE range)
227
+ {
228
+ git_revwalk *walk;
229
+ Data_Get_Struct(self, git_revwalk, walk);
230
+ int error = git_revwalk_push_range(walk, StringValuePtr(range));
231
+ rugged_exception_check(error);
232
+ return Qnil;
233
+ }
234
+
226
235
  /*
227
236
  * call-seq:
228
237
  * walker.hide(commit) -> nil
@@ -300,6 +309,7 @@ void Init_rugged_revwalk(void)
300
309
  rb_define_singleton_method(rb_cRuggedWalker, "new", rb_git_walker_new, 1);
301
310
 
302
311
  rb_define_method(rb_cRuggedWalker, "push", rb_git_walker_push, 1);
312
+ rb_define_method(rb_cRuggedWalker, "push_range", rb_git_walker_push_range, 1);
303
313
  rb_define_method(rb_cRuggedWalker, "each", rb_git_walker_each, -1);
304
314
  rb_define_method(rb_cRuggedWalker, "each_oid", rb_git_walker_each_oid, -1);
305
315
  rb_define_method(rb_cRuggedWalker, "walk", rb_git_walker_each, -1);
@@ -0,0 +1,1042 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2014 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+ extern VALUE rb_mRugged;
27
+ VALUE rb_cRuggedSubmodule;
28
+
29
+ static VALUE id_in_head, id_in_index, id_in_config, id_in_workdir;
30
+ static VALUE id_index_added, id_index_deleted, id_index_modified;
31
+ static VALUE id_wd_uninitialized, id_wd_added, id_wd_deleted, id_wd_modified;
32
+ static VALUE id_wd_index_modified, id_wd_wd_modified, id_wd_untracked;
33
+
34
+ static ID id_ignore_none, id_ignore_untracked, id_ignore_dirty, id_ignore_all;
35
+
36
+ static ID id_update_checkout, id_update_rebase, id_update_merge, id_update_none;
37
+
38
+ void init_status_list(void)
39
+ {
40
+ id_in_head = CSTR2SYM("in_head");
41
+ id_in_index = CSTR2SYM("in_index");
42
+ id_in_config = CSTR2SYM("in_config");
43
+ id_in_workdir = CSTR2SYM("in_workdir");
44
+ id_index_added = CSTR2SYM("added_to_index");
45
+ id_index_deleted = CSTR2SYM("deleted_from_index");
46
+ id_index_modified = CSTR2SYM("modified_in_index");
47
+ id_wd_uninitialized = CSTR2SYM("uninitialized");
48
+ id_wd_added = CSTR2SYM("added_to_workdir");
49
+ id_wd_deleted = CSTR2SYM("deleted_from_workdir");
50
+ id_wd_modified = CSTR2SYM("modified_in_workdir");
51
+ id_wd_index_modified = CSTR2SYM("dirty_workdir_index");
52
+ id_wd_wd_modified = CSTR2SYM("modified_files_in_workdir");
53
+ id_wd_untracked = CSTR2SYM("untracked_files_in_workdir");
54
+
55
+ return;
56
+ }
57
+
58
+ static VALUE submodule_status_flags_to_rb(unsigned int flags)
59
+ {
60
+ VALUE rb_flags = rb_ary_new();
61
+
62
+ if (flags & GIT_SUBMODULE_STATUS_IN_HEAD)
63
+ rb_ary_push(rb_flags, id_in_head);
64
+
65
+ if (flags & GIT_SUBMODULE_STATUS_IN_INDEX)
66
+ rb_ary_push(rb_flags, id_in_index);
67
+
68
+ if (flags & GIT_SUBMODULE_STATUS_IN_CONFIG)
69
+ rb_ary_push(rb_flags, id_in_config);
70
+
71
+ if (flags & GIT_SUBMODULE_STATUS_IN_WD)
72
+ rb_ary_push(rb_flags, id_in_workdir);
73
+
74
+ if (flags & GIT_SUBMODULE_STATUS_INDEX_ADDED)
75
+ rb_ary_push(rb_flags, id_index_added);
76
+
77
+ if (flags & GIT_SUBMODULE_STATUS_INDEX_DELETED)
78
+ rb_ary_push(rb_flags, id_index_deleted);
79
+
80
+ if (flags & GIT_SUBMODULE_STATUS_INDEX_MODIFIED)
81
+ rb_ary_push(rb_flags, id_index_modified);
82
+
83
+ if (flags & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)
84
+ rb_ary_push(rb_flags, id_wd_uninitialized);
85
+
86
+ if (flags & GIT_SUBMODULE_STATUS_WD_ADDED)
87
+ rb_ary_push(rb_flags, id_wd_added);
88
+
89
+ if (flags & GIT_SUBMODULE_STATUS_WD_DELETED)
90
+ rb_ary_push(rb_flags, id_wd_deleted);
91
+
92
+ if (flags & GIT_SUBMODULE_STATUS_WD_MODIFIED)
93
+ rb_ary_push(rb_flags, id_wd_modified);
94
+
95
+ if (flags & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED)
96
+ rb_ary_push(rb_flags, id_wd_index_modified);
97
+
98
+ if (flags & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED)
99
+ rb_ary_push(rb_flags, id_wd_wd_modified);
100
+
101
+ if (flags & GIT_SUBMODULE_STATUS_WD_UNTRACKED)
102
+ rb_ary_push(rb_flags, id_wd_untracked);
103
+
104
+ return rb_flags;
105
+ }
106
+
107
+ /*
108
+ * call-seq:
109
+ * submodule.status -> array
110
+ *
111
+ * Returns an +array+ with the status flags for a submodule.
112
+ *
113
+ * Depending on the #ignore_rule property of the submodule, some of
114
+ * the flags may never be returned because they indicate changes that are
115
+ * supposed to be ignored.
116
+ *
117
+ * Submodule info is contained in 4 places: the +HEAD+ tree, the index,
118
+ * config files (both +.git/config+ and +.gitmodules+), and the working
119
+ * directory. Any or all of those places might be missing information about
120
+ * the submodule depending on what state the repository is in. We consider
121
+ * all four places to build the combination of status flags.
122
+ *
123
+ * There are four values that are not really status, but give basic info
124
+ * about what sources of submodule data are available. These will be
125
+ * returned even if ignore is set to +:all+.
126
+ *
127
+ * :in_head ::
128
+ * superproject +HEAD+ contains submodule
129
+ * :in_index ::
130
+ * superproject index contains submodule
131
+ * :in_config ::
132
+ * superproject +.gitmodules+ has submodule
133
+ * :in_workdir ::
134
+ * superproject workdir has submodule
135
+ *
136
+ * The following values will be returned as long as ignore is not +:all+.
137
+ *
138
+ * :added_to_index ::
139
+ * submodule is in index, not in +HEAD+
140
+ * :deleted_from_index ::
141
+ * submodule is in +HEAD+, not in index
142
+ * :modified_in_index ::
143
+ * submodule in index and +HEAD+ don't match
144
+ * :uninitialized ::
145
+ * submodule in workdir is not initialized
146
+ * :added_to_workdir ::
147
+ * submodule is in workdir, not index
148
+ * :deleted_from_workdir ::
149
+ * submodule is in index, not workdir
150
+ * :modified_in_workdir ::
151
+ * submodule in index and workdir +HEAD+ don't match
152
+ *
153
+ * The following can only be returned if ignore is +:none+ or +:untracked+.
154
+ *
155
+ * :dirty_workdir_index ::
156
+ * submodule workdir index is dirty
157
+ * :modified_files_in_workdir ::
158
+ * submodule workdir has modified files
159
+ *
160
+ * Lastly, the following will only be returned for ignore +:none+.
161
+ *
162
+ * :untracked_files_in_workdir ::
163
+ * submodule workdir contains untracked files
164
+ */
165
+ static VALUE rb_git_submodule_status(VALUE self)
166
+ {
167
+ git_submodule *submodule;
168
+ unsigned int flags;
169
+
170
+ Data_Get_Struct(self, git_submodule, submodule);
171
+
172
+ rugged_exception_check(
173
+ git_submodule_status(&flags, submodule)
174
+ );
175
+
176
+ return submodule_status_flags_to_rb(flags);
177
+
178
+ }
179
+
180
+ #define RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(flag) \
181
+ git_submodule *submodule; \
182
+ unsigned int flags; \
183
+ Data_Get_Struct(self, git_submodule, submodule); \
184
+ rugged_exception_check( \
185
+ git_submodule_location(&flags, submodule) \
186
+ ); \
187
+ return (flags & flag) ? Qtrue : Qfalse; \
188
+
189
+ /*
190
+ * call-seq:
191
+ * submodule.in_head? -> true or false
192
+ *
193
+ * Returns +true+ if superproject +HEAD+ contains submodule.
194
+ */
195
+ static VALUE rb_git_submodule_status_in_head(VALUE self)
196
+ {
197
+ RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_HEAD)
198
+ }
199
+
200
+ /*
201
+ * call-seq:
202
+ * submodule.in_index? -> true or false
203
+ *
204
+ * Returns +true+ if superproject index contains submodule.
205
+ */
206
+ static VALUE rb_git_submodule_status_in_index(VALUE self)
207
+ {
208
+ RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_INDEX)
209
+ }
210
+
211
+ /*
212
+ * call-seq:
213
+ * submodule.in_config? -> true or false
214
+ *
215
+ * Returns +true+ if superproject +.gitmodules+ has submodule.
216
+ */
217
+ static VALUE rb_git_submodule_status_in_config(VALUE self)
218
+ {
219
+ RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_CONFIG)
220
+ }
221
+
222
+ /*
223
+ * call-seq:
224
+ * submodule.in_workdir? -> true or false
225
+ *
226
+ * Returns +true+ if superproject workdir has submodule.
227
+ */
228
+ static VALUE rb_git_submodule_status_in_workdir(VALUE self)
229
+ {
230
+ RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_WD)
231
+ }
232
+
233
+ #define RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(flag) \
234
+ git_submodule *submodule; \
235
+ unsigned int flags; \
236
+ Data_Get_Struct(self, git_submodule, submodule); \
237
+ rugged_exception_check( \
238
+ git_submodule_status(&flags, submodule) \
239
+ ); \
240
+ return (flags & flag) ? Qtrue : Qfalse; \
241
+
242
+ /*
243
+ * call-seq:
244
+ * submodule.added_to_index? -> true or false
245
+ *
246
+ * Returns +true+ if submodule is in index, not in +HEAD+.
247
+ */
248
+ static VALUE rb_git_submodule_status_added_to_index(VALUE self)
249
+ {
250
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_ADDED)
251
+ }
252
+
253
+ /*
254
+ * call-seq:
255
+ * submodule.deleted_from_index? -> true or false
256
+ *
257
+ * Returns +true+ if submodule is in +HEAD+, not in index
258
+ */
259
+ static VALUE rb_git_submodule_status_deleted_from_index(VALUE self)
260
+ {
261
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_DELETED)
262
+ }
263
+
264
+ /*
265
+ * call-seq:
266
+ * submodule.modified_in_index? -> true or false
267
+ *
268
+ * Returns +true+ if submodule in index and +HEAD+ don't match.
269
+ */
270
+ static VALUE rb_git_submodule_status_modified_in_index(VALUE self)
271
+ {
272
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_MODIFIED)
273
+ }
274
+
275
+ /*
276
+ * call-seq:
277
+ * submodule.uninitialized? -> true or false
278
+ *
279
+ * Returns +true+ if submodule in workdir is not initialized.
280
+ */
281
+ static VALUE rb_git_submodule_status_uninitialized(VALUE self)
282
+ {
283
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)
284
+ }
285
+
286
+ /*
287
+ * call-seq:
288
+ * submodule.added_to_workdir? -> true or false
289
+ *
290
+ * Returns +true+ if submodule is in workdir, not index.
291
+ */
292
+ static VALUE rb_git_submodule_status_added_to_workdir(VALUE self)
293
+ {
294
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_ADDED)
295
+ }
296
+
297
+ /*
298
+ * call-seq:
299
+ * submodule.deleted_from_workdir? -> true or false
300
+ *
301
+ * Returns +true+ if submodule is in index, not workdir.
302
+ */
303
+ static VALUE rb_git_submodule_status_deleted_from_workdir(VALUE self)
304
+ {
305
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_DELETED)
306
+ }
307
+
308
+ /*
309
+ * call-seq:
310
+ * submodule.modified_in_workdir? -> true or false
311
+ *
312
+ * Returns +true+ if submodule in index and workdir +HEAD+ don't match.
313
+ */
314
+ static VALUE rb_git_submodule_status_modified_in_workdir(VALUE self)
315
+ {
316
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_MODIFIED)
317
+ }
318
+
319
+ /*
320
+ * call-seq:
321
+ * submodule.dirty_workdir_index? -> true or false
322
+ *
323
+ * Returns +true+ if submodule workdir index is dirty.
324
+ */
325
+ static VALUE rb_git_submodule_status_dirty_workdir_index(VALUE self)
326
+ {
327
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED)
328
+ }
329
+
330
+ /*
331
+ * call-seq:
332
+ * submodule.modified_files_in_workdir? -> true or false
333
+ *
334
+ * Returns +true+ if submodule workdir has modified files.
335
+ */
336
+ static VALUE rb_git_submodule_status_modified_files_in_workdir(VALUE self)
337
+ {
338
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_WD_MODIFIED)
339
+ }
340
+
341
+ /*
342
+ * call-seq:
343
+ * submodule.untracked_files_in_workdir? -> true or false
344
+ *
345
+ * Returns +true+ if submodule workdir contains untracked files.
346
+ */
347
+ static VALUE rb_git_submodule_status_untracked_files_in_workdir(VALUE self)
348
+ {
349
+ RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_UNTRACKED)
350
+ }
351
+
352
+ #define RB_GIT_SUBMODULE_STATUS_CHECK(check) \
353
+ git_submodule *submodule; \
354
+ unsigned int flags; \
355
+ Data_Get_Struct(self, git_submodule, submodule); \
356
+ rugged_exception_check( \
357
+ git_submodule_status(&flags, submodule) \
358
+ ); \
359
+ return check(flags) ? Qtrue : Qfalse; \
360
+
361
+ /*
362
+ * call-seq:
363
+ * submodule.unmodified? -> true or false
364
+ *
365
+ * Returns +true+ if the submodule is unmodified.
366
+ */
367
+ static VALUE rb_git_submodule_status_unmodified(VALUE self)
368
+ {
369
+ RB_GIT_SUBMODULE_STATUS_CHECK(GIT_SUBMODULE_STATUS_IS_UNMODIFIED)
370
+ }
371
+
372
+ /*
373
+ * call-seq:
374
+ * submodule.dirty_workdir? -> true or false
375
+ *
376
+ * Returns +true+ if the submodule workdir is dirty.
377
+ *
378
+ * The workdir is considered dirty if the workdir index is modified, there
379
+ * are modified files in the workdir or if there are untracked files in the
380
+ * workdir.
381
+ */
382
+ static VALUE rb_git_submodule_status_dirty_workdir(VALUE self)
383
+ {
384
+ RB_GIT_SUBMODULE_STATUS_CHECK(GIT_SUBMODULE_STATUS_IS_WD_DIRTY)
385
+ }
386
+
387
+ /*
388
+ * call-seq:
389
+ * submodule.add_to_index([options]) -> submodule
390
+ *
391
+ * Add current submodule +HEAD+ commit to the index of superproject.
392
+ *
393
+ * The following options can be passed in the +options+ Hash:
394
+ *
395
+ * :write_index ::
396
+ * (default +true+) If this should immediately write the index file.
397
+ * If passed as +false+, Rugged::Repository#index can be used to explicitly
398
+ * call Rugged::Index#write to save the change.
399
+ */
400
+ static VALUE rb_git_submodule_add_to_index(int argc, VALUE *argv, VALUE self)
401
+ {
402
+ git_submodule *submodule;
403
+ VALUE rb_options;
404
+ int write_index = 1;
405
+
406
+ Data_Get_Struct(self, git_submodule, submodule);
407
+
408
+ rb_scan_args(argc, argv, ":", &rb_options);
409
+
410
+ if (!NIL_P(rb_options)) {
411
+ VALUE rb_val;
412
+
413
+ rb_val = rb_hash_aref(rb_options, CSTR2SYM("write_index"));
414
+ write_index = (rb_val != Qfalse);
415
+ }
416
+
417
+ rugged_exception_check(
418
+ git_submodule_add_to_index(submodule, write_index)
419
+ );
420
+
421
+ return self;
422
+ }
423
+
424
+ /*
425
+ * call-seq:
426
+ * submodule.reload -> submodule
427
+ *
428
+ * Reread submodule info from config, index, and +HEAD+.
429
+ *
430
+ * Call this to reread cached submodule information for this submodule if
431
+ * there is reason to believe that it has changed.
432
+ */
433
+ static VALUE rb_git_submodule_reload(VALUE self)
434
+ {
435
+ git_submodule *submodule;
436
+ Data_Get_Struct(self, git_submodule, submodule);
437
+
438
+ rugged_exception_check(
439
+ git_submodule_reload(submodule, 1)
440
+ );
441
+
442
+ return self;
443
+ }
444
+
445
+ /*
446
+ * call-seq:
447
+ * submodule.save -> submodule
448
+ *
449
+ * Write submodule settings to +.gitmodules+ file.
450
+ *
451
+ * This commits any in-memory changes to the submodule to the +.gitmodules+
452
+ * file on disk.
453
+ */
454
+ static VALUE rb_git_submodule_save(VALUE self)
455
+ {
456
+ git_submodule *submodule;
457
+ Data_Get_Struct(self, git_submodule, submodule);
458
+
459
+ rugged_exception_check(
460
+ git_submodule_save(submodule)
461
+ );
462
+
463
+ return self;
464
+ }
465
+
466
+ /*
467
+ * call-seq:
468
+ * submodule.sync -> submodule
469
+ *
470
+ * Copy submodule remote info into submodule repository.
471
+ *
472
+ * This copies the information about the submodules URL into the checked out
473
+ * submodule config, acting like <tt>"git submodule sync"</tt>. This is useful
474
+ * if the URL for the submodule was altered (by a manual change, or a fetch of
475
+ * upstream changes) and the local repository needs to be updated.
476
+ */
477
+ static VALUE rb_git_submodule_sync(VALUE self)
478
+ {
479
+ git_submodule *submodule;
480
+ Data_Get_Struct(self, git_submodule, submodule);
481
+
482
+ rugged_exception_check(
483
+ git_submodule_sync(submodule)
484
+ );
485
+
486
+ return self;
487
+ }
488
+
489
+ /*
490
+ * call-seq:
491
+ * submodule.init([options]) -> submodule
492
+ *
493
+ * Copy submodule info into +.git/config+ file.
494
+ *
495
+ * Just like <tt>"git submodule init"</tt>, this copies information about the
496
+ * submodule into +.git/config+.
497
+ *
498
+ * The following options can be passed in the +options+ Hash:
499
+ *
500
+ * :overwrite ::
501
+ * (defaults to +false+) - By default, existing entries
502
+ * will not be overwritten, but setting this to +true+ forces them to be
503
+ * updated.
504
+ */
505
+ static VALUE rb_git_submodule_init(int argc, VALUE *argv, VALUE self)
506
+ {
507
+ git_submodule *submodule;
508
+ VALUE rb_options;
509
+ int overwrite = 0;
510
+
511
+ Data_Get_Struct(self, git_submodule, submodule);
512
+
513
+ rb_scan_args(argc, argv, ":", &rb_options);
514
+
515
+ if (!NIL_P(rb_options)) {
516
+ VALUE rb_val;
517
+
518
+ rb_val = rb_hash_aref(rb_options, CSTR2SYM("overwrite"));
519
+ overwrite = RTEST(rb_val);
520
+ }
521
+
522
+ rugged_exception_check(
523
+ git_submodule_init(submodule, overwrite)
524
+ );
525
+
526
+ return self;
527
+ }
528
+
529
+ /*
530
+ * call-seq:
531
+ * submodule.name -> string
532
+ *
533
+ * Returns the name of the submodule.
534
+ */
535
+ static VALUE rb_git_submodule_name(VALUE self)
536
+ {
537
+ git_submodule *submodule;
538
+ const char *name;
539
+
540
+ Data_Get_Struct(self, git_submodule, submodule);
541
+
542
+ name = git_submodule_name(submodule);
543
+
544
+ return rb_str_new_utf8(name);
545
+ }
546
+
547
+ /*
548
+ * call-seq:
549
+ * submodule.url -> string or nil
550
+ *
551
+ * Returns the URL of the submodule.
552
+ */
553
+ static VALUE rb_git_submodule_url(VALUE self)
554
+ {
555
+
556
+ git_submodule *submodule;
557
+ const char *url;
558
+
559
+ Data_Get_Struct(self, git_submodule, submodule);
560
+
561
+ url = git_submodule_url(submodule);
562
+
563
+ return url ? rb_str_new_utf8(url) : Qnil;
564
+ }
565
+
566
+ /*
567
+ * call-seq:
568
+ * submodule.url = url -> url
569
+ *
570
+ * Set the URL in memory for the submodule.
571
+ *
572
+ * This will be used for any following submodule actions while this submodule
573
+ * data is in memory.
574
+ *
575
+ * After calling this, #save can be called to write the changes back to
576
+ * the +.gitmodules+ file and #sync to write the changes to the checked out
577
+ * submodule repository.
578
+ */
579
+ static VALUE rb_git_submodule_set_url(VALUE self, VALUE rb_url)
580
+ {
581
+ git_submodule *submodule;
582
+
583
+ Check_Type(rb_url, T_STRING);
584
+
585
+ Data_Get_Struct(self, git_submodule, submodule);
586
+
587
+ rugged_exception_check(
588
+ git_submodule_set_url(submodule, StringValueCStr(rb_url))
589
+ );
590
+ return rb_url;
591
+ }
592
+
593
+ /*
594
+ * call-seq:
595
+ * submodule.path -> string
596
+ *
597
+ * Returns the path of the submodule.
598
+ *
599
+ * The +path+ is almost always the same as the #name,
600
+ * but the two are actually not required to match.
601
+ */
602
+ static VALUE rb_git_submodule_path(VALUE self)
603
+ {
604
+ git_submodule *submodule;
605
+ const char *path;
606
+
607
+ Data_Get_Struct(self, git_submodule, submodule);
608
+
609
+ path = git_submodule_path(submodule);
610
+
611
+ return rb_str_new_utf8(path);
612
+ }
613
+
614
+ #define RB_GIT_OID_GETTER(_klass, _attribute) \
615
+ git_##_klass *object; \
616
+ const git_oid * oid; \
617
+ Data_Get_Struct(self, git_##_klass, object); \
618
+ oid = git_##_klass##_##_attribute(object); \
619
+ return oid ? rugged_create_oid(oid) : Qnil; \
620
+
621
+ /*
622
+ * call-seq:
623
+ * submodule.head_oid -> string or nil
624
+ *
625
+ * Returns the OID for the submodule in the current +HEAD+ tree or +nil+
626
+ * if the submodule is not in the +HEAD+.
627
+ */
628
+ static VALUE rb_git_submodule_head_id(VALUE self)
629
+ {
630
+ RB_GIT_OID_GETTER(submodule, head_id);
631
+ }
632
+
633
+ /*
634
+ * call-seq:
635
+ * submodule.index_oid -> string or nil
636
+ *
637
+ * Returns the OID for the submodule in the index or +nil+ if the submodule
638
+ * is not in the index.
639
+ */
640
+ static VALUE rb_git_submodule_index_id(VALUE self)
641
+ {
642
+ RB_GIT_OID_GETTER(submodule, index_id);
643
+ }
644
+
645
+ /*
646
+ * call-seq:
647
+ * submodule.workdir_oid -> string or nil
648
+ *
649
+ * Returns the OID for the submodule in the current working directory or
650
+ * +nil+ of the submodule is not checked out.
651
+ *
652
+ * This returns the OID that corresponds to looking up +HEAD+ in the checked
653
+ * out submodule. If there are pending changes in the index or anything
654
+ * else, this won't notice that. #status can be called for a more complete
655
+ * picture about the state of the working directory.
656
+ */
657
+ static VALUE rb_git_submodule_wd_id(VALUE self)
658
+ {
659
+ RB_GIT_OID_GETTER(submodule, wd_id);
660
+ }
661
+
662
+ /*
663
+ * call-seq:
664
+ * submodule.fetch_recurse_submodules? -> true or false
665
+ *
666
+ * Returns the +fetchRecurseSubmodules+ rule for a submodule.
667
+ *
668
+ * This accesses the <tt>submodule.<name>.fetchRecurseSubmodules</tt> value
669
+ * for the submodule that controls fetching behavior for the submodule.
670
+ *
671
+ * Note that at this time, +Rugged+ does not honor this setting and the fetch
672
+ * functionality currently ignores submodules.
673
+ *
674
+ */
675
+ static VALUE rb_git_submodule_fetch_recurse_submodules(VALUE self)
676
+ {
677
+ git_submodule *submodule;
678
+ Data_Get_Struct(self, git_submodule, submodule);
679
+
680
+ return git_submodule_fetch_recurse_submodules(submodule) ? Qtrue : Qfalse;
681
+ }
682
+
683
+ /*
684
+ * call-seq:
685
+ * submodule.fetch_recurse_submodules= bool -> bool
686
+ *
687
+ * Set the +fetchRecurseSubmodules+ rule in memory for a submodule.
688
+ *
689
+ * This sets the <tt>submodule.<name>.fetchRecurseSubmodules</tt> value for
690
+ * the submodule. #save can be called to persist the new value.
691
+ */
692
+ static VALUE rb_git_submodule_set_fetch_recurse_submodules(VALUE self, VALUE rb_fetch_recursive)
693
+ {
694
+ git_submodule *submodule;
695
+ Data_Get_Struct(self, git_submodule, submodule);
696
+
697
+ git_submodule_set_fetch_recurse_submodules(
698
+ submodule,
699
+ rugged_parse_bool(rb_fetch_recursive)
700
+ );
701
+
702
+ return rb_fetch_recursive;
703
+ }
704
+
705
+ static VALUE rb_git_subm_ignore_rule_fromC(git_submodule_ignore_t rule)
706
+ {
707
+ switch(rule) {
708
+ case GIT_SUBMODULE_IGNORE_NONE:
709
+ return ID2SYM(id_ignore_none);
710
+ case GIT_SUBMODULE_IGNORE_UNTRACKED:
711
+ return ID2SYM(id_ignore_untracked);
712
+ case GIT_SUBMODULE_IGNORE_DIRTY:
713
+ return ID2SYM(id_ignore_dirty);
714
+ case GIT_SUBMODULE_IGNORE_ALL:
715
+ return ID2SYM(id_ignore_all);
716
+ default:
717
+ return CSTR2SYM("unknown");
718
+ }
719
+ }
720
+
721
+ /*
722
+ * call-seq:
723
+ * submodule.ignore_rule -> symbol
724
+ *
725
+ * Returns the ignore rule for a submodule.
726
+ *
727
+ * There are four ignore values:
728
+ *
729
+ * :none (default)::
730
+ * will consider any change to the contents of the submodule from
731
+ * a clean checkout to be dirty, including the addition of untracked files.
732
+ * :untracked ::
733
+ * examines the contents of the working tree but untracked files will not
734
+ * count as making the submodule dirty.
735
+ * :dirty ::
736
+ * means to only check if the +HEAD+ of the submodule has moved for status.
737
+ * This is fast since it does not need to scan the working tree
738
+ * of the submodule at all.
739
+ * :all ::
740
+ * means not to open the submodule repository. The working directory will be
741
+ * considered clean so long as there is a checked out version present.
742
+ *
743
+ * See #status on how ignore rules reflect the returned status info
744
+ * for a submodule.
745
+ */
746
+ static VALUE rb_git_submodule_ignore_rule(VALUE self)
747
+ {
748
+ git_submodule *submodule;
749
+ git_submodule_ignore_t ignore;
750
+
751
+ Data_Get_Struct(self, git_submodule, submodule);
752
+ ignore = git_submodule_ignore(submodule);
753
+
754
+ return rb_git_subm_ignore_rule_fromC(ignore);
755
+ }
756
+
757
+ static git_submodule_ignore_t rb_git_subm_ignore_rule_toC(VALUE rb_ignore_rule)
758
+ {
759
+ ID id_ignore_rule;
760
+
761
+ Check_Type(rb_ignore_rule, T_SYMBOL);
762
+ id_ignore_rule = SYM2ID(rb_ignore_rule);
763
+
764
+ if (id_ignore_rule == id_ignore_none) {
765
+ return GIT_SUBMODULE_IGNORE_NONE;
766
+ } else if (id_ignore_rule == id_ignore_untracked) {
767
+ return GIT_SUBMODULE_IGNORE_UNTRACKED;
768
+ } else if (id_ignore_rule == id_ignore_dirty) {
769
+ return GIT_SUBMODULE_IGNORE_DIRTY;
770
+ } else if (id_ignore_rule == id_ignore_all) {
771
+ return GIT_SUBMODULE_IGNORE_ALL;
772
+ } else {
773
+ rb_raise(rb_eArgError, "Invalid submodule ignore rule type.");
774
+ }
775
+ }
776
+
777
+ /*
778
+ * call-seq:
779
+ * submodule.ignore_rule = rule -> rule
780
+ *
781
+ * Set the ignore_rule to +rule+ in memory for a submodule.
782
+ * See #ignore for a list of accepted rules.
783
+ *
784
+ * This will be used for any following actions (such as
785
+ * #status) while the submodule is in memory. The ignore
786
+ * rule can be persisted to the config with #save.
787
+ *
788
+ * Calling #reset_ignore_rule or #reload will
789
+ * revert the rule to the value that was in the config.
790
+ */
791
+ static VALUE rb_git_submodule_set_ignore_rule(VALUE self, VALUE rb_ignore_rule)
792
+ {
793
+ git_submodule *submodule;
794
+
795
+ Data_Get_Struct(self, git_submodule, submodule);
796
+
797
+ git_submodule_set_ignore(
798
+ submodule,
799
+ rb_git_subm_ignore_rule_toC(rb_ignore_rule)
800
+ );
801
+
802
+ return rb_ignore_rule;
803
+ }
804
+
805
+ /*
806
+ * call-seq:
807
+ * submodule.reset_ignore_rule -> submodule
808
+ *
809
+ * Revert the ignore rule set by #ignore_rule= to the value that
810
+ * was in the config.
811
+ */
812
+ static VALUE rb_git_submodule_reset_ignore_rule(VALUE self)
813
+ {
814
+ git_submodule *submodule;
815
+
816
+ Data_Get_Struct(self, git_submodule, submodule);
817
+
818
+ git_submodule_set_ignore(submodule, GIT_SUBMODULE_IGNORE_RESET);
819
+
820
+ return self;
821
+ }
822
+
823
+ static VALUE rb_git_subm_update_rule_fromC(git_submodule_update_t rule)
824
+ {
825
+ switch(rule) {
826
+ case GIT_SUBMODULE_UPDATE_CHECKOUT:
827
+ return ID2SYM(id_update_checkout);
828
+ case GIT_SUBMODULE_UPDATE_REBASE:
829
+ return ID2SYM(id_update_rebase);
830
+ case GIT_SUBMODULE_UPDATE_MERGE:
831
+ return ID2SYM(id_update_merge);
832
+ case GIT_SUBMODULE_UPDATE_NONE:
833
+ return ID2SYM(id_update_none);
834
+ default:
835
+ return CSTR2SYM("unknown");
836
+ }
837
+ }
838
+
839
+ /*
840
+ * call-seq:
841
+ * submodule.update_rule -> symbol
842
+ *
843
+ * Returns the update rule for a submodule.
844
+ *
845
+ * There are four update_rule values:
846
+ *
847
+ * :checkout (default)::
848
+ * the new commit specified in the superproject will be checked out in the
849
+ * submodule on a detached +HEAD+.
850
+ * :rebase ::
851
+ * the current branch of the submodule will be rebased onto the commit
852
+ * specified in the superproject.
853
+ * :merge ::
854
+ * the commit specified in the superproject will be merged into the current
855
+ * branch of the submodule.
856
+ * :none ::
857
+ * the submodule will not be updated
858
+ */
859
+ static VALUE rb_git_submodule_update_rule(VALUE self)
860
+ {
861
+ git_submodule *submodule;
862
+ git_submodule_update_t update;
863
+
864
+ Data_Get_Struct(self, git_submodule, submodule);
865
+ update = git_submodule_update(submodule);
866
+
867
+ return rb_git_subm_update_rule_fromC(update);
868
+ }
869
+
870
+ static git_submodule_update_t rb_git_subm_update_rule_toC(VALUE rb_update_rule)
871
+ {
872
+ ID id_update_rule;
873
+
874
+ Check_Type(rb_update_rule, T_SYMBOL);
875
+ id_update_rule = SYM2ID(rb_update_rule);
876
+
877
+ if (id_update_rule == id_update_checkout) {
878
+ return GIT_SUBMODULE_UPDATE_CHECKOUT;
879
+ } else if (id_update_rule == id_update_rebase) {
880
+ return GIT_SUBMODULE_UPDATE_REBASE;
881
+ } else if (id_update_rule == id_update_merge) {
882
+ return GIT_SUBMODULE_UPDATE_MERGE;
883
+ } else if (id_update_rule == id_update_none) {
884
+ return GIT_SUBMODULE_UPDATE_NONE;
885
+ } else {
886
+ rb_raise(rb_eArgError, "Invalid submodule update rule type.");
887
+ }
888
+ }
889
+
890
+ /*
891
+ * call-seq:
892
+ * submodule.update_rule = rule -> rule
893
+ *
894
+ * Set the update_rule to +rule+ in memory for a submodule.
895
+ * See #update_rule for a list of accepted rules.
896
+ *
897
+ * Calling #reset_update_rule or #reload will
898
+ * revert the +rule+ to the value that was in the config.
899
+ */
900
+ static VALUE rb_git_submodule_set_update_rule(VALUE self, VALUE rb_update_rule)
901
+ {
902
+ git_submodule *submodule;
903
+
904
+ Data_Get_Struct(self, git_submodule, submodule);
905
+
906
+ git_submodule_set_update(
907
+ submodule,
908
+ rb_git_subm_update_rule_toC(rb_update_rule)
909
+ );
910
+
911
+ return rb_update_rule;
912
+ }
913
+
914
+ /*
915
+ * call-seq:
916
+ * submodule.reset_update_rule -> submodule
917
+ *
918
+ * Revert the update rule set by #update_rule= to the value that
919
+ * was in the config.
920
+ */
921
+ static VALUE rb_git_submodule_reset_update_rule(VALUE self)
922
+ {
923
+ git_submodule *submodule;
924
+
925
+ Data_Get_Struct(self, git_submodule, submodule);
926
+
927
+ git_submodule_set_update(submodule, GIT_SUBMODULE_UPDATE_RESET);
928
+
929
+ return self;
930
+ }
931
+
932
+ /*
933
+ * call-seq:
934
+ * submodule.repository -> repository
935
+ *
936
+ * Returns the +repository+ for the submodule.
937
+ *
938
+ * The returned +repository+ is a newly opened Rugged::Repository object.
939
+ * This will only work if the submodule is checked out into the working
940
+ * directory.
941
+ */
942
+ static VALUE rb_git_submodule_repository(VALUE self)
943
+ {
944
+ git_submodule *submodule;
945
+ git_repository *repo;
946
+
947
+ Data_Get_Struct(self, git_submodule, submodule);
948
+
949
+ rugged_exception_check(
950
+ git_submodule_open(&repo, submodule)
951
+ );
952
+
953
+ return rugged_repo_new(rb_cRuggedRepo, repo);
954
+ }
955
+
956
+ /*
957
+ * call-seq:
958
+ * submodule.finalize_add -> submodule
959
+ *
960
+ * Resolve the setup of a new submodule.
961
+ *
962
+ * This should be called on a submodule once
963
+ * Rugged::SubmoduleCollection#setup_add is finished and the sumodule repo is
964
+ * cloned.
965
+ *
966
+ * This adds the +.gitmodules+ file and the newly cloned submodule to the index
967
+ * to be ready to be committed (but doesn't actually do the commit).
968
+ */
969
+ static VALUE rb_git_submodule_finalize_add(VALUE self)
970
+ {
971
+ git_submodule *submodule;
972
+ Data_Get_Struct(self, git_submodule, submodule);
973
+
974
+ rugged_exception_check(
975
+ git_submodule_add_finalize(submodule)
976
+ );
977
+
978
+ return self;
979
+ }
980
+
981
+ void Init_rugged_submodule(void)
982
+ {
983
+ init_status_list();
984
+ id_ignore_none = rb_intern("none");
985
+ id_ignore_dirty = rb_intern("dirty");
986
+ id_ignore_untracked = rb_intern("untracked");
987
+ id_ignore_all = rb_intern("all");
988
+
989
+ id_update_checkout = rb_intern("checkout");
990
+ id_update_rebase = rb_intern("rebase");
991
+ id_update_merge = rb_intern("merge");
992
+ id_update_none = rb_intern("none");
993
+
994
+ rb_cRuggedSubmodule = rb_define_class_under(rb_mRugged, "Submodule", rb_cObject);
995
+
996
+ rb_define_method(rb_cRuggedSubmodule, "finalize_add", rb_git_submodule_finalize_add, 0);
997
+
998
+ rb_define_method(rb_cRuggedSubmodule, "name", rb_git_submodule_name, 0);
999
+ rb_define_method(rb_cRuggedSubmodule, "url", rb_git_submodule_url, 0);
1000
+ rb_define_method(rb_cRuggedSubmodule, "url=", rb_git_submodule_set_url, 1);
1001
+ rb_define_method(rb_cRuggedSubmodule, "path", rb_git_submodule_path, 0);
1002
+ rb_define_method(rb_cRuggedSubmodule, "fetch_recurse_submodules?", rb_git_submodule_fetch_recurse_submodules, 0);
1003
+ rb_define_method(rb_cRuggedSubmodule, "fetch_recurse_submodules=", rb_git_submodule_set_fetch_recurse_submodules, 1);
1004
+
1005
+ rb_define_method(rb_cRuggedSubmodule, "ignore_rule", rb_git_submodule_ignore_rule, 0);
1006
+ rb_define_method(rb_cRuggedSubmodule, "ignore_rule=", rb_git_submodule_set_ignore_rule, 1);
1007
+ rb_define_method(rb_cRuggedSubmodule, "reset_ignore_rule", rb_git_submodule_reset_ignore_rule, 0);
1008
+ rb_define_method(rb_cRuggedSubmodule, "update_rule", rb_git_submodule_update_rule, 0);
1009
+ rb_define_method(rb_cRuggedSubmodule, "update_rule=", rb_git_submodule_set_update_rule, 1);
1010
+ rb_define_method(rb_cRuggedSubmodule, "reset_update_rule", rb_git_submodule_reset_update_rule, 0);
1011
+
1012
+ rb_define_method(rb_cRuggedSubmodule, "head_oid", rb_git_submodule_head_id, 0);
1013
+ rb_define_method(rb_cRuggedSubmodule, "index_oid", rb_git_submodule_index_id, 0);
1014
+ rb_define_method(rb_cRuggedSubmodule, "workdir_oid", rb_git_submodule_wd_id, 0);
1015
+
1016
+ rb_define_method(rb_cRuggedSubmodule, "status", rb_git_submodule_status, 0);
1017
+ rb_define_method(rb_cRuggedSubmodule, "in_head?", rb_git_submodule_status_in_head, 0);
1018
+ rb_define_method(rb_cRuggedSubmodule, "in_index?", rb_git_submodule_status_in_index, 0);
1019
+ rb_define_method(rb_cRuggedSubmodule, "in_config?", rb_git_submodule_status_in_config, 0);
1020
+ rb_define_method(rb_cRuggedSubmodule, "in_workdir?", rb_git_submodule_status_in_workdir, 0);
1021
+ rb_define_method(rb_cRuggedSubmodule, "added_to_index?", rb_git_submodule_status_added_to_index, 0);
1022
+ rb_define_method(rb_cRuggedSubmodule, "deleted_from_index?", rb_git_submodule_status_deleted_from_index, 0);
1023
+ rb_define_method(rb_cRuggedSubmodule, "modified_in_index?", rb_git_submodule_status_modified_in_index, 0);
1024
+ rb_define_method(rb_cRuggedSubmodule, "uninitialized?", rb_git_submodule_status_uninitialized, 0);
1025
+ rb_define_method(rb_cRuggedSubmodule, "added_to_workdir?", rb_git_submodule_status_added_to_workdir, 0);
1026
+ rb_define_method(rb_cRuggedSubmodule, "deleted_from_workdir?", rb_git_submodule_status_deleted_from_workdir, 0);
1027
+ rb_define_method(rb_cRuggedSubmodule, "modified_in_workdir?", rb_git_submodule_status_modified_in_workdir, 0);
1028
+ rb_define_method(rb_cRuggedSubmodule, "dirty_workdir_index?", rb_git_submodule_status_dirty_workdir_index, 0);
1029
+ rb_define_method(rb_cRuggedSubmodule, "modified_files_in_workdir?", rb_git_submodule_status_modified_files_in_workdir, 0);
1030
+ rb_define_method(rb_cRuggedSubmodule, "untracked_files_in_workdir?", rb_git_submodule_status_untracked_files_in_workdir, 0);
1031
+
1032
+ rb_define_method(rb_cRuggedSubmodule, "unmodified?", rb_git_submodule_status_unmodified, 0);
1033
+ rb_define_method(rb_cRuggedSubmodule, "dirty_workdir?", rb_git_submodule_status_dirty_workdir, 0);
1034
+
1035
+ rb_define_method(rb_cRuggedSubmodule, "repository", rb_git_submodule_repository, 0);
1036
+
1037
+ rb_define_method(rb_cRuggedSubmodule, "add_to_index", rb_git_submodule_add_to_index, -1);
1038
+ rb_define_method(rb_cRuggedSubmodule, "reload", rb_git_submodule_reload, 0);
1039
+ rb_define_method(rb_cRuggedSubmodule, "save", rb_git_submodule_save, 0);
1040
+ rb_define_method(rb_cRuggedSubmodule, "sync", rb_git_submodule_sync, 0);
1041
+ rb_define_method(rb_cRuggedSubmodule, "init", rb_git_submodule_init, -1);
1042
+ }