1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 module libgit2_d.submodule;
8 
9 
10 private static import libgit2_d.buffer;
11 private static import libgit2_d.checkout;
12 private static import libgit2_d.oid;
13 private static import libgit2_d.remote;
14 private static import libgit2_d.types;
15 private static import std.traits;
16 
17 /**
18  * @file git2/submodule.h
19  * @brief Git submodule management utilities
20  *
21  * Submodule support in libgit2 builds a list of known submodules and keeps
22  * it in the repository.  The list is built from the .gitmodules file, the
23  * .git/config file, the index, and the HEAD tree.  Items in the working
24  * directory that look like submodules (i.e. a git repo) but are not
25  * mentioned in those places won't be tracked.
26  *
27  * @defgroup git_submodule Git submodule management routines
28  * @ingroup Git
29  * @{
30  */
31 extern (C):
32 nothrow @nogc:
33 public:
34 
35 /**
36  * Return codes for submodule status.
37  *
38  * A combination of these flags will be returned to describe the status of a
39  * submodule.  Depending on the "ignore" property of the submodule, some of
40  * the flags may never be returned because they indicate changes that are
41  * supposed to be ignored.
42  *
43  * Submodule info is contained in 4 places: the HEAD tree, the index, config
44  * files (both .git/config and .gitmodules), and the working directory.  Any
45  * or all of those places might be missing information about the submodule
46  * depending on what state the repo is in.  We consider all four places to
47  * build the combination of status flags.
48  *
49  * There are four values that are not really status, but give basic info
50  * about what sources of submodule data are available.  These will be
51  * returned even if ignore is set to "ALL".
52  *
53  * * IN_HEAD   - superproject head contains submodule
54  * * IN_INDEX  - superproject index contains submodule
55  * * IN_CONFIG - superproject gitmodules has submodule
56  * * IN_WD     - superproject workdir has submodule
57  *
58  * The following values will be returned so long as ignore is not "ALL".
59  *
60  * * INDEX_ADDED       - in index, not in head
61  * * INDEX_DELETED     - in head, not in index
62  * * INDEX_MODIFIED    - index and head don't match
63  * * WD_UNINITIALIZED  - workdir contains empty directory
64  * * WD_ADDED          - in workdir, not index
65  * * WD_DELETED        - in index, not workdir
66  * * WD_MODIFIED       - index and workdir head don't match
67  *
68  * The following can only be returned if ignore is "NONE" or "UNTRACKED".
69  *
70  * * WD_INDEX_MODIFIED - submodule workdir index is dirty
71  * * WD_WD_MODIFIED    - submodule workdir has modified files
72  *
73  * Lastly, the following will only be returned for ignore "NONE".
74  *
75  * * WD_UNTRACKED      - wd contains untracked files
76  */
77 enum git_submodule_status_t
78 {
79 	GIT_SUBMODULE_STATUS_IN_HEAD = 1u << 0,
80 	GIT_SUBMODULE_STATUS_IN_INDEX = 1u << 1,
81 	GIT_SUBMODULE_STATUS_IN_CONFIG = 1u << 2,
82 	GIT_SUBMODULE_STATUS_IN_WD = 1u << 3,
83 	GIT_SUBMODULE_STATUS_INDEX_ADDED = 1u << 4,
84 	GIT_SUBMODULE_STATUS_INDEX_DELETED = 1u << 5,
85 	GIT_SUBMODULE_STATUS_INDEX_MODIFIED = 1u << 6,
86 	GIT_SUBMODULE_STATUS_WD_UNINITIALIZED = 1u << 7,
87 	GIT_SUBMODULE_STATUS_WD_ADDED = 1u << 8,
88 	GIT_SUBMODULE_STATUS_WD_DELETED = 1u << 9,
89 	GIT_SUBMODULE_STATUS_WD_MODIFIED = 1u << 10,
90 	GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = 1u << 11,
91 	GIT_SUBMODULE_STATUS_WD_WD_MODIFIED = 1u << 12,
92 	GIT_SUBMODULE_STATUS_WD_UNTRACKED = 1u << 13,
93 }
94 
95 enum GIT_SUBMODULE_STATUS__IN_FLAGS = 0x000Fu;
96 enum GIT_SUBMODULE_STATUS__INDEX_FLAGS = 0x0070u;
97 enum GIT_SUBMODULE_STATUS__WD_FLAGS = 0x3F80u;
98 
99 pragma(inline, true)
100 pure nothrow @safe @nogc
101 bool GIT_SUBMODULE_STATUS_IS_UNMODIFIED(T)(S)
102 	if (std.traits.isIntegral!(T))
103 
104 	do
105 	{
106 		return (S & ~.GIT_SUBMODULE_STATUS__IN_FLAGS) == 0;
107 	}
108 
109 pragma(inline, true)
110 pure nothrow @safe @nogc
111 bool GIT_SUBMODULE_STATUS_IS_INDEX_UNMODIFIED(T)(S)
112 	if (std.traits.isIntegral!(T))
113 
114 	do
115 	{
116 		return (S & .GIT_SUBMODULE_STATUS__INDEX_FLAGS) == 0;
117 	}
118 
119 pragma(inline, true)
120 pure nothrow @safe @nogc
121 bool GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(T)(S)
122 	if (std.traits.isIntegral!(T))
123 
124 	do
125 	{
126 		return (S & (.GIT_SUBMODULE_STATUS__WD_FLAGS & ~.git_submodule_status_t.GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)) == 0;
127 	}
128 
129 pragma(inline, true)
130 pure nothrow @safe @nogc
131 bool GIT_SUBMODULE_STATUS_IS_WD_DIRTY(T)(S)
132 	if (std.traits.isIntegral!(T))
133 
134 	do
135 	{
136 		return (S & (.git_submodule_status_t.GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED | .git_submodule_status_t.GIT_SUBMODULE_STATUS_WD_WD_MODIFIED | .git_submodule_status_t.GIT_SUBMODULE_STATUS_WD_UNTRACKED)) != 0;
137 	}
138 
139 /**
140  * Function pointer to receive each submodule
141  *
142  * @param sm git_submodule currently being visited
143  * @param name name of the submodule
144  * @param payload value you passed to the foreach function as payload
145  * @return 0 on success or error code
146  */
147 alias git_submodule_cb = int function(libgit2_d.types.git_submodule* sm, const (char)* name, void* payload);
148 
149 /**
150  * Submodule update options structure
151  *
152  * Initialize with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`. Alternatively, you can
153  * use `git_submodule_update_options_init`.
154  */
155 struct git_submodule_update_options
156 {
157 	uint version_;
158 
159 	/**
160 	 * These options are passed to the checkout step. To disable
161 	 * checkout, set the `checkout_strategy` to
162 	 * `git_checkout_strategy_t.GIT_CHECKOUT_NONE`. Generally you will want the use
163 	 * git_checkout_strategy_t.GIT_CHECKOUT_SAFE to update files in the working
164 	 * directory.
165 	 */
166 	libgit2_d.checkout.git_checkout_options checkout_opts;
167 
168 	/**
169 	 * Options which control the fetch, including callbacks.
170 	 *
171 	 * The callbacks to use for reporting fetch progress, and for acquiring
172 	 * credentials in the event they are needed.
173 	 */
174 	libgit2_d.remote.git_fetch_options fetch_opts;
175 
176 	/**
177 	 * Allow fetching from the submodule's default remote if the target
178 	 * commit isn't found. Enabled by default.
179 	 */
180 	int allow_fetch;
181 }
182 
183 enum GIT_SUBMODULE_UPDATE_OPTIONS_VERSION = 1;
184 
185 pragma(inline, true)
186 pure nothrow @safe @nogc
187 .git_submodule_update_options GIT_SUBMODULE_UPDATE_OPTIONS_INIT()
188 
189 	do
190 	{
191 		libgit2_d.checkout.git_checkout_options CHECKOUT_OPTION =
192 		{
193 			version_: libgit2_d.checkout.GIT_CHECKOUT_OPTIONS_VERSION,
194 			checkout_strategy: libgit2_d.checkout.git_checkout_strategy_t.GIT_CHECKOUT_SAFE,
195 		};
196 
197 		.git_submodule_update_options OUTPUT =
198 		{
199 			version_: .GIT_SUBMODULE_UPDATE_OPTIONS_VERSION,
200 			checkout_opts: CHECKOUT_OPTION,
201 			fetch_opts: libgit2_d.remote.GIT_FETCH_OPTIONS_INIT(),
202 			allow_fetch: 1,
203 		};
204 
205 		return OUTPUT;
206 	}
207 
208 /**
209  * Initialize git_submodule_update_options structure
210  *
211  * Initializes a `git_submodule_update_options` with default values. Equivalent to
212  * creating an instance with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`.
213  *
214  * @param opts The `git_submodule_update_options` struct to initialize.
215  * @param version The struct version; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION`.
216  * @return Zero on success; -1 on failure.
217  */
218 //GIT_EXTERN
219 int git_submodule_update_options_init(.git_submodule_update_options* opts, uint version_);
220 
221 /**
222  * Update a submodule. This will clone a missing submodule and
223  * checkout the subrepository to the commit specified in the index of
224  * the containing repository. If the submodule repository doesn't contain
225  * the target commit (e.g. because fetchRecurseSubmodules isn't set), then
226  * the submodule is fetched using the fetch options supplied in options.
227  *
228  * @param submodule Submodule object
229  * @param init If the submodule is not initialized, setting this flag to true
230  *        will initialize the submodule before updating. Otherwise, this will
231  *        return an error if attempting to update an uninitialzed repository.
232  *        but setting this to true forces them to be updated.
233  * @param options configuration options for the update.  If null, the
234  *        function works as though GIT_SUBMODULE_UPDATE_OPTIONS_INIT was passed.
235  * @return 0 on success, any non-zero return value from a callback
236  *         function, or a negative value to indicate an error (use
237  *         `git_error_last` for a detailed error message).
238  */
239 //GIT_EXTERN
240 int git_submodule_update(libgit2_d.types.git_submodule* submodule, int init, .git_submodule_update_options* options);
241 
242 /**
243  * Lookup submodule information by name or path.
244  *
245  * Given either the submodule name or path (they are usually the same), this
246  * returns a structure describing the submodule.
247  *
248  * There are two expected error scenarios:
249  *
250  * - The submodule is not mentioned in the HEAD, the index, and the config,
251  *   but does "exist" in the working directory (i.e. there is a subdirectory
252  *   that appears to be a Git repository).  In this case, this function
253  *   returns git_error_code.GIT_EEXISTS to indicate a sub-repository exists but not in a
254  *   state where a git_submodule can be instantiated.
255  * - The submodule is not mentioned in the HEAD, index, or config and the
256  *   working directory doesn't contain a value git repo at that path.
257  *   There may or may not be anything else at that path, but nothing that
258  *   looks like a submodule.  In this case, this returns git_error_code.GIT_ENOTFOUND.
259  *
260  * You must call `git_submodule_free` when done with the submodule.
261  *
262  * @param out_ Output ptr to submodule; pass null to just get return code
263  * @param repo The parent repository
264  * @param name The name of or path to the submodule; trailing slashes okay
265  * @return 0 on success, git_error_code.GIT_ENOTFOUND if submodule does not exist,
266  *         git_error_code.GIT_EEXISTS if a repository is found in working directory only,
267  *         -1 on other errors.
268  */
269 //GIT_EXTERN
270 int git_submodule_lookup(libgit2_d.types.git_submodule** out_, libgit2_d.types.git_repository* repo, const (char)* name);
271 
272 /**
273  * Release a submodule
274  *
275  * @param submodule Submodule object
276  */
277 //GIT_EXTERN
278 void git_submodule_free(libgit2_d.types.git_submodule* submodule);
279 
280 /**
281  * Iterate over all tracked submodules of a repository.
282  *
283  * See the note on `git_submodule` above.  This iterates over the tracked
284  * submodules as described therein.
285  *
286  * If you are concerned about items in the working directory that look like
287  * submodules but are not tracked, the diff API will generate a diff record
288  * for workdir items that look like submodules but are not tracked, showing
289  * them as added in the workdir.  Also, the status API will treat the entire
290  * subdirectory of a contained git repo as a single git_status_t.GIT_STATUS_WT_NEW item.
291  *
292  * @param repo The repository
293  * @param callback Function to be called with the name of each submodule.
294  *        Return a non-zero value to terminate the iteration.
295  * @param payload Extra data to pass to callback
296  * @return 0 on success, -1 on error, or non-zero return value of callback
297  */
298 //GIT_EXTERN
299 int git_submodule_foreach(libgit2_d.types.git_repository* repo, .git_submodule_cb callback, void* payload);
300 
301 /**
302  * Set up a new git submodule for checkout.
303  *
304  * This does "git submodule add" up to the fetch and checkout of the
305  * submodule contents.  It preps a new submodule, creates an entry in
306  * .gitmodules and creates an empty initialized repository either at the
307  * given path in the working directory or in .git/modules with a gitlink
308  * from the working directory to the new repo.
309  *
310  * To fully emulate "git submodule add" call this function, then open the
311  * submodule repo and perform the clone step as needed (if you don't need
312  * anything custom see `git_submodule_add_clone()`). Lastly, call
313  * `git_submodule_add_finalize()` to wrap up adding the new submodule and
314  * .gitmodules to the index to be ready to commit.
315  *
316  * You must call `git_submodule_free` on the submodule object when done.
317  *
318  * @param out_ The newly created submodule ready to open for clone
319  * @param repo The repository in which you want to create the submodule
320  * @param url URL for the submodule's remote
321  * @param path Path at which the submodule should be created
322  * @param use_gitlink Should workdir contain a gitlink to the repo in
323  *        .git/modules vs. repo directly in workdir.
324  * @return 0 on success, git_error_code.GIT_EEXISTS if submodule already exists,
325  *         -1 on other errors.
326  */
327 //GIT_EXTERN
328 int git_submodule_add_setup(libgit2_d.types.git_submodule** out_, libgit2_d.types.git_repository* repo, const (char)* url, const (char)* path, int use_gitlink);
329 
330 /**
331  * Perform the clone step for a newly created submodule.
332  *
333  * This performs the necessary `git_clone` to setup a newly-created submodule.
334  *
335  * @param out_ The newly created repository object. Optional.
336  * @param submodule The submodule currently waiting for its clone.
337  * @param opts The options to use.
338  *
339  * @return 0 on success, -1 on other errors (see git_clone).
340  */
341 //GIT_EXTERN
342 int git_submodule_clone(libgit2_d.types.git_repository** out_, libgit2_d.types.git_submodule* submodule, const (.git_submodule_update_options)* opts);
343 
344 /**
345  * Resolve the setup of a new git submodule.
346  *
347  * This should be called on a submodule once you have called add setup
348  * and done the clone of the submodule.  This adds the .gitmodules file
349  * and the newly cloned submodule to the index to be ready to be committed
350  * (but doesn't actually do the commit).
351  *
352  * @param submodule The submodule to finish adding.
353  */
354 //GIT_EXTERN
355 int git_submodule_add_finalize(libgit2_d.types.git_submodule* submodule);
356 
357 /**
358  * Add current submodule HEAD commit to index of superproject.
359  *
360  * @param submodule The submodule to add to the index
361  * @param write_index Boolean if this should immediately write the index
362  *            file.  If you pass this as false, you will have to get the
363  *            git_index and explicitly call `git_index_write()` on it to
364  *            save the change.
365  * @return 0 on success, <0 on failure
366  */
367 //GIT_EXTERN
368 int git_submodule_add_to_index(libgit2_d.types.git_submodule* submodule, int write_index);
369 
370 /**
371  * Get the containing repository for a submodule.
372  *
373  * This returns a pointer to the repository that contains the submodule.
374  * This is a just a reference to the repository that was passed to the
375  * original `git_submodule_lookup()` call, so if that repository has been
376  * freed, then this may be a dangling reference.
377  *
378  * @param submodule Pointer to submodule object
379  * @return Pointer to `libgit2_d.types.git_repository`
380  */
381 //GIT_EXTERN
382 libgit2_d.types.git_repository* git_submodule_owner(libgit2_d.types.git_submodule* submodule);
383 
384 /**
385  * Get the name of submodule.
386  *
387  * @param submodule Pointer to submodule object
388  * @return Pointer to the submodule name
389  */
390 //GIT_EXTERN
391 const (char)* git_submodule_name(libgit2_d.types.git_submodule* submodule);
392 
393 /**
394  * Get the path to the submodule.
395  *
396  * The path is almost always the same as the submodule name, but the
397  * two are actually not required to match.
398  *
399  * @param submodule Pointer to submodule object
400  * @return Pointer to the submodule path
401  */
402 //GIT_EXTERN
403 const (char)* git_submodule_path(libgit2_d.types.git_submodule* submodule);
404 
405 /**
406  * Get the URL for the submodule.
407  *
408  * @param submodule Pointer to submodule object
409  * @return Pointer to the submodule url
410  */
411 //GIT_EXTERN
412 const (char)* git_submodule_url(libgit2_d.types.git_submodule* submodule);
413 
414 /**
415  * Resolve a submodule url relative to the given repository.
416  *
417  * @param out_ buffer to store the absolute submodule url in
418  * @param repo Pointer to repository object
419  * @param url Relative url
420  * @return 0 or an error code
421  */
422 //GIT_EXTERN
423 int git_submodule_resolve_url(libgit2_d.buffer.git_buf* out_, libgit2_d.types.git_repository* repo, const (char)* url);
424 
425 /**
426  * Get the branch for the submodule.
427  *
428  * @param submodule Pointer to submodule object
429  * @return Pointer to the submodule branch
430  */
431 //GIT_EXTERN
432 const (char)* git_submodule_branch(libgit2_d.types.git_submodule* submodule);
433 
434 /**
435  * Set the branch for the submodule in the configuration
436  *
437  * After calling this, you may wish to call `git_submodule_sync()` to
438  * write the changes to the checked out submodule repository.
439  *
440  * @param repo the repository to affect
441  * @param name the name of the submodule to configure
442  * @param branch Branch that should be used for the submodule
443  * @return 0 on success, <0 on failure
444  */
445 //GIT_EXTERN
446 int git_submodule_set_branch(libgit2_d.types.git_repository* repo, const (char)* name, const (char)* branch);
447 
448 /**
449  * Set the URL for the submodule in the configuration
450  *
451  *
452  * After calling this, you may wish to call `git_submodule_sync()` to
453  * write the changes to the checked out submodule repository.
454  *
455  * @param repo the repository to affect
456  * @param name the name of the submodule to configure
457  * @param url URL that should be used for the submodule
458  * @return 0 on success, <0 on failure
459  */
460 //GIT_EXTERN
461 int git_submodule_set_url(libgit2_d.types.git_repository* repo, const (char)* name, const (char)* url);
462 
463 /**
464  * Get the OID for the submodule in the index.
465  *
466  * @param submodule Pointer to submodule object
467  * @return Pointer to git_oid or null if submodule is not in index.
468  */
469 //GIT_EXTERN
470 const (libgit2_d.oid.git_oid)* git_submodule_index_id(libgit2_d.types.git_submodule* submodule);
471 
472 /**
473  * Get the OID for the submodule in the current HEAD tree.
474  *
475  * @param submodule Pointer to submodule object
476  * @return Pointer to git_oid or null if submodule is not in the HEAD.
477  */
478 //GIT_EXTERN
479 const (libgit2_d.oid.git_oid)* git_submodule_head_id(libgit2_d.types.git_submodule* submodule);
480 
481 /**
482  * Get the OID for the submodule in the current working directory.
483  *
484  * This returns the OID that corresponds to looking up 'HEAD' in the checked
485  * out submodule.  If there are pending changes in the index or anything
486  * else, this won't notice that.  You should call `git_submodule_status()`
487  * for a more complete picture about the state of the working directory.
488  *
489  * @param submodule Pointer to submodule object
490  * @return Pointer to git_oid or null if submodule is not checked out.
491  */
492 //GIT_EXTERN
493 const (libgit2_d.oid.git_oid)* git_submodule_wd_id(libgit2_d.types.git_submodule* submodule);
494 
495 /**
496  * Get the ignore rule that will be used for the submodule.
497  *
498  * These values control the behavior of `git_submodule_status()` for this
499  * submodule.  There are four ignore values:
500  *
501  *  - **git_submodule_ignore_t.GIT_SUBMODULE_IGNORE_NONE** will consider any change to the contents
502  *    of the submodule from a clean checkout to be dirty, including the
503  *    addition of untracked files.  This is the default if unspecified.
504  *  - **git_submodule_ignore_t.GIT_SUBMODULE_IGNORE_UNTRACKED** examines the contents of the
505  *    working tree (i.e. call `git_status_foreach()` on the submodule) but
506  *    UNTRACKED files will not count as making the submodule dirty.
507  *  - **git_submodule_ignore_t.GIT_SUBMODULE_IGNORE_DIRTY** means to only check if the HEAD of the
508  *    submodule has moved for status.  This is fast since it does not need to
509  *    scan the working tree of the submodule at all.
510  *  - **git_submodule_ignore_t.GIT_SUBMODULE_IGNORE_ALL** means not to open the submodule repo.
511  *    The working directory will be consider clean so long as there is a
512  *    checked out version present.
513  *
514  * @param submodule The submodule to check
515  * @return The current libgit2_d.types.git_submodule_ignore_t valyue what will be used for
516  *         this submodule.
517  */
518 //GIT_EXTERN
519 libgit2_d.types.git_submodule_ignore_t git_submodule_ignore(libgit2_d.types.git_submodule* submodule);
520 
521 /**
522  * Set the ignore rule for the submodule in the configuration
523  *
524  * This does not affect any currently-loaded instances.
525  *
526  * @param repo the repository to affect
527  * @param name the name of the submdule
528  * @param ignore The new value for the ignore rule
529  * @return 0 or an error code
530  */
531 //GIT_EXTERN
532 int git_submodule_set_ignore(libgit2_d.types.git_repository* repo, const (char)* name, libgit2_d.types.git_submodule_ignore_t ignore);
533 
534 /**
535  * Get the update rule that will be used for the submodule.
536  *
537  * This value controls the behavior of the `git submodule update` command.
538  * There are four useful values documented with `libgit2_d.types.git_submodule_update_t`.
539  *
540  * @param submodule The submodule to check
541  * @return The current libgit2_d.types.git_submodule_update_t value that will be used
542  *         for this submodule.
543  */
544 //GIT_EXTERN
545 libgit2_d.types.git_submodule_update_t git_submodule_update_strategy(libgit2_d.types.git_submodule* submodule);
546 
547 /**
548  * Set the update rule for the submodule in the configuration
549  *
550  * This setting won't affect any existing instances.
551  *
552  * @param repo the repository to affect
553  * @param name the name of the submodule to configure
554  * @param update The new value to use
555  * @return 0 or an error code
556  */
557 //GIT_EXTERN
558 int git_submodule_set_update(libgit2_d.types.git_repository* repo, const (char)* name, libgit2_d.types.git_submodule_update_t update);
559 
560 /**
561  * Read the fetchRecurseSubmodules rule for a submodule.
562  *
563  * This accesses the submodule.<name>.fetchRecurseSubmodules value for
564  * the submodule that controls fetching behavior for the submodule.
565  *
566  * Note that at this time, libgit2 does not honor this setting and the
567  * fetch functionality current ignores submodules.
568  *
569  * @return 0 if fetchRecurseSubmodules is false, 1 if true
570  */
571 //GIT_EXTERN
572 libgit2_d.types.git_submodule_recurse_t git_submodule_fetch_recurse_submodules(libgit2_d.types.git_submodule* submodule);
573 
574 /**
575  * Set the fetchRecurseSubmodules rule for a submodule in the configuration
576  *
577  * This setting won't affect any existing instances.
578  *
579  * @param repo the repository to affect
580  * @param name the submodule to configure
581  * @param fetch_recurse_submodules Boolean value
582  * @return old value for fetchRecurseSubmodules
583  */
584 //GIT_EXTERN
585 int git_submodule_set_fetch_recurse_submodules(libgit2_d.types.git_repository* repo, const (char)* name, libgit2_d.types.git_submodule_recurse_t fetch_recurse_submodules);
586 
587 /**
588  * Copy submodule info into ".git/config" file.
589  *
590  * Just like "git submodule init", this copies information about the
591  * submodule into ".git/config".  You can use the accessor functions
592  * above to alter the in-memory git_submodule object and control what
593  * is written to the config, overriding what is in .gitmodules.
594  *
595  * @param submodule The submodule to write into the superproject config
596  * @param overwrite By default, existing entries will not be overwritten,
597  *                  but setting this to true forces them to be updated.
598  * @return 0 on success, <0 on failure.
599  */
600 //GIT_EXTERN
601 int git_submodule_init(libgit2_d.types.git_submodule* submodule, int overwrite);
602 
603 /**
604  * Set up the subrepository for a submodule in preparation for clone.
605  *
606  * This function can be called to init and set up a submodule
607  * repository from a submodule in preparation to clone it from
608  * its remote.
609  *
610  * @param out_ Output pointer to the created git repository.
611  * @param sm The submodule to create a new subrepository from.
612  * @param use_gitlink Should the workdir contain a gitlink to
613  *        the repo in .git/modules vs. repo directly in workdir.
614  * @return 0 on success, <0 on failure.
615  */
616 //GIT_EXTERN
617 int git_submodule_repo_init(libgit2_d.types.git_repository** out_, const (libgit2_d.types.git_submodule)* sm, int use_gitlink);
618 
619 /**
620  * Copy submodule remote info into submodule repo.
621  *
622  * This copies the information about the submodules URL into the checked out
623  * submodule config, acting like "git submodule sync".  This is useful if
624  * you have altered the URL for the submodule (or it has been altered by a
625  * fetch of upstream changes) and you need to update your local repo.
626  */
627 //GIT_EXTERN
628 int git_submodule_sync(libgit2_d.types.git_submodule* submodule);
629 
630 /**
631  * Open the repository for a submodule.
632  *
633  * This is a newly opened repository object.  The caller is responsible for
634  * calling `git_repository_free()` on it when done.  Multiple calls to this
635  * function will return distinct `libgit2_d.types.git_repository` objects.  This will only
636  * work if the submodule is checked out into the working directory.
637  *
638  * @param repo Pointer to the submodule repo which was opened
639  * @param submodule Submodule to be opened
640  * @return 0 on success, <0 if submodule repo could not be opened.
641  */
642 //GIT_EXTERN
643 int git_submodule_open(libgit2_d.types.git_repository** repo, libgit2_d.types.git_submodule* submodule);
644 
645 /**
646  * Reread submodule info from config, index, and HEAD.
647  *
648  * Call this to reread cached submodule information for this submodule if
649  * you have reason to believe that it has changed.
650  *
651  * @param submodule The submodule to reload
652  * @param force Force reload even if the data doesn't seem out of date
653  * @return 0 on success, <0 on error
654  */
655 //GIT_EXTERN
656 int git_submodule_reload(libgit2_d.types.git_submodule* submodule, int force);
657 
658 /**
659  * Get the status for a submodule.
660  *
661  * This looks at a submodule and tries to determine the status.  It
662  * will return a combination of the `GIT_SUBMODULE_STATUS` values above.
663  * How deeply it examines the working directory to do this will depend
664  * on the `libgit2_d.types.git_submodule_ignore_t` value for the submodule.
665  *
666  * @param status Combination of `GIT_SUBMODULE_STATUS` flags
667  * @param repo the repository in which to look
668  * @param name name of the submodule
669  * @param ignore the ignore rules to follow
670  * @return 0 on success, <0 on error
671  */
672 //GIT_EXTERN
673 int git_submodule_status(uint* status, libgit2_d.types.git_repository* repo, const (char)* name, libgit2_d.types.git_submodule_ignore_t ignore);
674 
675 /**
676  * Get the locations of submodule information.
677  *
678  * This is a bit like a very lightweight version of `git_submodule_status`.
679  * It just returns a made of the first four submodule status values (i.e.
680  * the ones like git_submodule_status_t.GIT_SUBMODULE_STATUS_IN_HEAD, etc) that tell you where the
681  * submodule data comes from (i.e. the HEAD commit, gitmodules file, etc.).
682  * This can be useful if you want to know if the submodule is present in the
683  * working directory at this point in time, etc.
684  *
685  * @param location_status Combination of first four `GIT_SUBMODULE_STATUS` flags
686  * @param submodule Submodule for which to get status
687  * @return 0 on success, <0 on error
688  */
689 //GIT_EXTERN
690 int git_submodule_location(uint* location_status, libgit2_d.types.git_submodule* submodule);
691 
692 /** @} */