rugged 0.17.0.b6 → 0.17.0.b7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/README.md +3 -3
  2. data/Rakefile +3 -1
  3. data/ext/rugged/rugged.c +30 -0
  4. data/ext/rugged/rugged.h +9 -0
  5. data/ext/rugged/rugged_branch.c +306 -0
  6. data/ext/rugged/rugged_config.c +16 -13
  7. data/ext/rugged/rugged_index.c +25 -0
  8. data/ext/rugged/rugged_object.c +6 -2
  9. data/ext/rugged/rugged_reference.c +11 -18
  10. data/ext/rugged/rugged_revwalk.c +1 -1
  11. data/lib/rugged.rb +1 -0
  12. data/lib/rugged/branch.rb +28 -0
  13. data/lib/rugged/commit.rb +5 -5
  14. data/lib/rugged/repository.rb +32 -7
  15. data/lib/rugged/tag.rb +5 -1
  16. data/lib/rugged/version.rb +1 -1
  17. data/test/branch_test.rb +227 -0
  18. data/test/config_test.rb +1 -1
  19. data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  20. data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
  21. data/test/index_test.rb +31 -0
  22. data/test/index_test.rb~ +218 -0
  23. data/test/lib_test.rb +22 -0
  24. data/test/reference_test.rb +5 -3
  25. data/vendor/libgit2/Makefile.embed +1 -1
  26. data/vendor/libgit2/include/git2.h +1 -0
  27. data/vendor/libgit2/include/git2/branch.h +17 -13
  28. data/vendor/libgit2/include/git2/checkout.h +83 -22
  29. data/vendor/libgit2/include/git2/clone.h +6 -3
  30. data/vendor/libgit2/include/git2/common.h +1 -8
  31. data/vendor/libgit2/include/git2/config.h +185 -26
  32. data/vendor/libgit2/include/git2/diff.h +229 -17
  33. data/vendor/libgit2/include/git2/errors.h +39 -1
  34. data/vendor/libgit2/include/git2/ignore.h +6 -3
  35. data/vendor/libgit2/include/git2/indexer.h +1 -0
  36. data/vendor/libgit2/include/git2/merge.h +1 -1
  37. data/vendor/libgit2/include/git2/object.h +7 -4
  38. data/vendor/libgit2/include/git2/odb.h +4 -2
  39. data/vendor/libgit2/include/git2/odb_backend.h +6 -0
  40. data/vendor/libgit2/include/git2/oid.h +2 -0
  41. data/vendor/libgit2/include/git2/pack.h +89 -0
  42. data/vendor/libgit2/include/git2/refs.h +88 -0
  43. data/vendor/libgit2/include/git2/refspec.h +0 -8
  44. data/vendor/libgit2/include/git2/remote.h +34 -1
  45. data/vendor/libgit2/include/git2/repository.h +238 -6
  46. data/vendor/libgit2/include/git2/reset.h +4 -1
  47. data/vendor/libgit2/include/git2/revwalk.h +1 -1
  48. data/vendor/libgit2/include/git2/status.h +19 -14
  49. data/vendor/libgit2/include/git2/strarray.h +54 -0
  50. data/vendor/libgit2/include/git2/submodule.h +451 -45
  51. data/vendor/libgit2/include/git2/tag.h +16 -0
  52. data/vendor/libgit2/include/git2/tree.h +2 -2
  53. data/vendor/libgit2/include/git2/types.h +4 -0
  54. data/vendor/libgit2/src/amiga/map.c +4 -7
  55. data/vendor/libgit2/src/attr.c +21 -13
  56. data/vendor/libgit2/src/attr.h +3 -1
  57. data/vendor/libgit2/src/attr_file.c +14 -14
  58. data/vendor/libgit2/src/attr_file.h +6 -5
  59. data/vendor/libgit2/src/blob.c +22 -12
  60. data/vendor/libgit2/src/branch.c +62 -66
  61. data/vendor/libgit2/src/buffer.c +63 -14
  62. data/vendor/libgit2/src/buffer.h +4 -0
  63. data/vendor/libgit2/src/cache.c +5 -4
  64. data/vendor/libgit2/src/checkout.c +381 -159
  65. data/vendor/libgit2/src/clone.c +221 -94
  66. data/vendor/libgit2/src/common.h +13 -3
  67. data/vendor/libgit2/src/compress.c +53 -0
  68. data/vendor/libgit2/src/compress.h +16 -0
  69. data/vendor/libgit2/src/config.c +380 -175
  70. data/vendor/libgit2/src/config.h +2 -5
  71. data/vendor/libgit2/src/config_file.c +63 -46
  72. data/vendor/libgit2/src/config_file.h +16 -4
  73. data/vendor/libgit2/src/crlf.c +4 -3
  74. data/vendor/libgit2/src/delta.c +491 -0
  75. data/vendor/libgit2/src/delta.h +112 -0
  76. data/vendor/libgit2/src/diff.c +310 -67
  77. data/vendor/libgit2/src/diff.h +10 -1
  78. data/vendor/libgit2/src/diff_output.c +1030 -337
  79. data/vendor/libgit2/src/diff_output.h +86 -0
  80. data/vendor/libgit2/src/errors.c +10 -1
  81. data/vendor/libgit2/src/fetch.c +108 -24
  82. data/vendor/libgit2/src/filebuf.c +8 -2
  83. data/vendor/libgit2/src/fileops.c +342 -177
  84. data/vendor/libgit2/src/fileops.h +84 -7
  85. data/vendor/libgit2/src/filter.c +0 -35
  86. data/vendor/libgit2/src/filter.h +0 -12
  87. data/vendor/libgit2/src/{compat/fnmatch.c → fnmatch.c} +16 -4
  88. data/vendor/libgit2/src/{compat/fnmatch.h → fnmatch.h} +4 -3
  89. data/vendor/libgit2/src/global.c +4 -0
  90. data/vendor/libgit2/src/ignore.c +122 -23
  91. data/vendor/libgit2/src/ignore.h +1 -0
  92. data/vendor/libgit2/src/index.c +56 -10
  93. data/vendor/libgit2/src/index.h +2 -0
  94. data/vendor/libgit2/src/indexer.c +8 -9
  95. data/vendor/libgit2/src/iterator.c +244 -31
  96. data/vendor/libgit2/src/iterator.h +30 -1
  97. data/vendor/libgit2/src/message.c +1 -1
  98. data/vendor/libgit2/src/netops.c +44 -4
  99. data/vendor/libgit2/src/object.c +80 -69
  100. data/vendor/libgit2/src/object.h +39 -0
  101. data/vendor/libgit2/src/odb.c +79 -15
  102. data/vendor/libgit2/src/odb.h +20 -5
  103. data/vendor/libgit2/src/odb_pack.c +65 -33
  104. data/vendor/libgit2/src/oid.c +0 -3
  105. data/vendor/libgit2/src/pack-objects.c +1315 -0
  106. data/vendor/libgit2/src/pack-objects.h +87 -0
  107. data/vendor/libgit2/src/pack.c +36 -12
  108. data/vendor/libgit2/src/pack.h +1 -0
  109. data/vendor/libgit2/src/path.c +42 -9
  110. data/vendor/libgit2/src/path.h +14 -0
  111. data/vendor/libgit2/src/pkt.c +52 -2
  112. data/vendor/libgit2/src/pkt.h +10 -0
  113. data/vendor/libgit2/src/pool.h +11 -0
  114. data/vendor/libgit2/src/posix.h +8 -0
  115. data/vendor/libgit2/src/protocol.c +24 -2
  116. data/vendor/libgit2/src/protocol.h +4 -0
  117. data/vendor/libgit2/src/reflog.c +1 -1
  118. data/vendor/libgit2/src/refs.c +292 -124
  119. data/vendor/libgit2/src/refs.h +4 -2
  120. data/vendor/libgit2/src/refspec.c +117 -19
  121. data/vendor/libgit2/src/refspec.h +19 -0
  122. data/vendor/libgit2/src/remote.c +152 -48
  123. data/vendor/libgit2/src/remote.h +4 -1
  124. data/vendor/libgit2/src/repo_template.h +58 -0
  125. data/vendor/libgit2/src/repository.c +594 -179
  126. data/vendor/libgit2/src/repository.h +23 -22
  127. data/vendor/libgit2/src/reset.c +71 -29
  128. data/vendor/libgit2/src/revparse.c +26 -17
  129. data/vendor/libgit2/src/revwalk.c +36 -19
  130. data/vendor/libgit2/src/sha1.h +7 -0
  131. data/vendor/libgit2/src/{sha1.c → sha1/sha1.c} +0 -0
  132. data/vendor/libgit2/src/signature.c +12 -10
  133. data/vendor/libgit2/src/status.c +52 -6
  134. data/vendor/libgit2/src/submodule.c +1363 -255
  135. data/vendor/libgit2/src/submodule.h +102 -0
  136. data/vendor/libgit2/src/tag.c +42 -26
  137. data/vendor/libgit2/src/thread-utils.h +7 -7
  138. data/vendor/libgit2/src/transport.h +15 -1
  139. data/vendor/libgit2/src/transports/git.c +1 -1
  140. data/vendor/libgit2/src/transports/http.c +197 -36
  141. data/vendor/libgit2/src/tree.c +3 -3
  142. data/vendor/libgit2/src/unix/map.c +2 -0
  143. data/vendor/libgit2/src/unix/posix.h +1 -8
  144. data/vendor/libgit2/src/util.c +6 -1
  145. data/vendor/libgit2/src/util.h +7 -0
  146. data/vendor/libgit2/src/vector.c +16 -0
  147. data/vendor/libgit2/src/vector.h +1 -0
  148. data/vendor/libgit2/src/win32/dir.c +8 -21
  149. data/vendor/libgit2/src/win32/findfile.c +149 -0
  150. data/vendor/libgit2/src/win32/findfile.h +23 -0
  151. data/vendor/libgit2/src/win32/posix.h +3 -7
  152. data/vendor/libgit2/src/win32/posix_w32.c +44 -102
  153. data/vendor/libgit2/src/win32/pthread.c +68 -0
  154. data/vendor/libgit2/src/win32/pthread.h +7 -0
  155. data/vendor/libgit2/src/win32/utf-conv.c +60 -71
  156. data/vendor/libgit2/src/win32/utf-conv.h +4 -3
  157. metadata +70 -71
  158. data/vendor/libgit2/include/git2/windows.h +0 -59
@@ -24,6 +24,9 @@ GIT_BEGIN_DECL
24
24
  * Specifying a Mixed kind of reset will trigger a Soft reset and the index will
25
25
  * be replaced with the content of the commit tree.
26
26
  *
27
+ * Specifying a Hard kind of reset will trigger a Mixed reset and the working
28
+ * directory will be replaced with the content of the index.
29
+ *
27
30
  * TODO: Implement remaining kinds of resets.
28
31
  *
29
32
  * @param repo Repository where to perform the reset operation.
@@ -37,7 +40,7 @@ GIT_BEGIN_DECL
37
40
  *
38
41
  * @return GIT_SUCCESS or an error code
39
42
  */
40
- GIT_EXTERN(int) git_reset(git_repository *repo, const git_object *target, git_reset_type reset_type);
43
+ GIT_EXTERN(int) git_reset(git_repository *repo, git_object *target, git_reset_type reset_type);
41
44
 
42
45
  /** @} */
43
46
  GIT_END_DECL
@@ -201,7 +201,7 @@ GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname);
201
201
  * @param oid Pointer where to store the oid of the next commit
202
202
  * @param walk the walker to pop the commit from.
203
203
  * @return 0 if the next commit was found;
204
- * GIT_REVWALKOVER if there are no commits left to iterate
204
+ * GIT_ITEROVER if there are no commits left to iterate
205
205
  */
206
206
  GIT_EXTERN(int) git_revwalk_next(git_oid *oid, git_revwalk *walk);
207
207
 
@@ -19,19 +19,22 @@
19
19
  */
20
20
  GIT_BEGIN_DECL
21
21
 
22
- enum {
23
- GIT_STATUS_CURRENT = 0,
22
+ typedef enum {
23
+ GIT_STATUS_CURRENT = 0,
24
24
 
25
- GIT_STATUS_INDEX_NEW = (1 << 0),
26
- GIT_STATUS_INDEX_MODIFIED = (1 << 1),
27
- GIT_STATUS_INDEX_DELETED = (1 << 2),
25
+ GIT_STATUS_INDEX_NEW = (1u << 0),
26
+ GIT_STATUS_INDEX_MODIFIED = (1u << 1),
27
+ GIT_STATUS_INDEX_DELETED = (1u << 2),
28
+ GIT_STATUS_INDEX_RENAMED = (1u << 3),
29
+ GIT_STATUS_INDEX_TYPECHANGE = (1u << 4),
28
30
 
29
- GIT_STATUS_WT_NEW = (1 << 3),
30
- GIT_STATUS_WT_MODIFIED = (1 << 4),
31
- GIT_STATUS_WT_DELETED = (1 << 5),
31
+ GIT_STATUS_WT_NEW = (1u << 7),
32
+ GIT_STATUS_WT_MODIFIED = (1u << 8),
33
+ GIT_STATUS_WT_DELETED = (1u << 9),
34
+ GIT_STATUS_WT_TYPECHANGE = (1u << 10),
32
35
 
33
- GIT_STATUS_IGNORED = (1 << 6),
34
- };
36
+ GIT_STATUS_IGNORED = (1u << 14),
37
+ } git_status_t;
35
38
 
36
39
  /**
37
40
  * Gather file statuses and run a callback for each one.
@@ -146,10 +149,12 @@ GIT_EXTERN(int) git_status_file(
146
149
  /**
147
150
  * Test if the ignore rules apply to a given file.
148
151
  *
149
- * This function simply checks the ignore rules to see if they would apply
150
- * to the given file. Unlike git_status_file(), this indicates if the file
151
- * would be ignored regardless of whether the file is already in the index
152
- * or in the repository.
152
+ * This function checks the ignore rules to see if they would apply to the
153
+ * given file. This indicates if the file would be ignored regardless of
154
+ * whether the file is already in the index or commited to the repository.
155
+ *
156
+ * One way to think of this is if you were to do "git add ." on the
157
+ * directory containing the file, would it be added or not?
153
158
  *
154
159
  * @param ignored boolean returning 0 if the file is not ignored, 1 if it is
155
160
  * @param repo a repository object
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright (C) 2009-2012 the libgit2 contributors
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
+ #ifndef INCLUDE_git_strarray_h__
8
+ #define INCLUDE_git_strarray_h__
9
+
10
+ #include "common.h"
11
+
12
+ /**
13
+ * @file git2/strarray.h
14
+ * @brief Git string array routines
15
+ * @defgroup git_strarray Git string array routines
16
+ * @ingroup Git
17
+ * @{
18
+ */
19
+ GIT_BEGIN_DECL
20
+
21
+ /** Array of strings */
22
+ typedef struct _git_strarray git_strarray;
23
+ struct _git_strarray {
24
+ char **strings;
25
+ size_t count;
26
+ };
27
+
28
+ /**
29
+ * Close a string array object
30
+ *
31
+ * This method must always be called once a git_strarray is no
32
+ * longer needed, otherwise memory will leak.
33
+ *
34
+ * @param array array to close
35
+ */
36
+ GIT_EXTERN(void) git_strarray_free(git_strarray *array);
37
+
38
+ /**
39
+ * Copy a string array object from source to target.
40
+ *
41
+ * Note: target is overwritten and hence should be empty,
42
+ * otherwise its contents are leaked.
43
+ *
44
+ * @param tgt target
45
+ * @param src source
46
+ */
47
+ GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src);
48
+
49
+
50
+ /** @} */
51
+ GIT_END_DECL
52
+
53
+ #endif
54
+
@@ -20,54 +20,160 @@
20
20
  */
21
21
  GIT_BEGIN_DECL
22
22
 
23
+ /**
24
+ * Opaque structure representing a submodule.
25
+ *
26
+ * Submodule support in libgit2 builds a list of known submodules and keeps
27
+ * it in the repository. The list is built from the .gitmodules file, the
28
+ * .git/config file, the index, and the HEAD tree. Items in the working
29
+ * directory that look like submodules (i.e. a git repo) but are not
30
+ * mentioned in those places won't be tracked.
31
+ */
32
+ typedef struct git_submodule git_submodule;
33
+
34
+ /**
35
+ * Values that could be specified for the update rule of a submodule.
36
+ *
37
+ * Use the DEFAULT value if you have altered the update value via
38
+ * `git_submodule_set_update()` and wish to reset to the original default.
39
+ */
23
40
  typedef enum {
41
+ GIT_SUBMODULE_UPDATE_DEFAULT = -1,
24
42
  GIT_SUBMODULE_UPDATE_CHECKOUT = 0,
25
43
  GIT_SUBMODULE_UPDATE_REBASE = 1,
26
- GIT_SUBMODULE_UPDATE_MERGE = 2
44
+ GIT_SUBMODULE_UPDATE_MERGE = 2,
45
+ GIT_SUBMODULE_UPDATE_NONE = 3
27
46
  } git_submodule_update_t;
28
47
 
48
+ /**
49
+ * Values that could be specified for how closely to examine the
50
+ * working directory when getting submodule status.
51
+ *
52
+ * Use the DEFUALT value if you have altered the ignore value via
53
+ * `git_submodule_set_ignore()` and wish to reset to the original value.
54
+ */
29
55
  typedef enum {
30
- GIT_SUBMODULE_IGNORE_ALL = 0, /* never dirty */
31
- GIT_SUBMODULE_IGNORE_DIRTY = 1, /* only dirty if HEAD moved */
32
- GIT_SUBMODULE_IGNORE_UNTRACKED = 2, /* dirty if tracked files change */
33
- GIT_SUBMODULE_IGNORE_NONE = 3 /* any change or untracked == dirty */
56
+ GIT_SUBMODULE_IGNORE_DEFAULT = -1, /* reset to default */
57
+ GIT_SUBMODULE_IGNORE_NONE = 0, /* any change or untracked == dirty */
58
+ GIT_SUBMODULE_IGNORE_UNTRACKED = 1, /* dirty if tracked files change */
59
+ GIT_SUBMODULE_IGNORE_DIRTY = 2, /* only dirty if HEAD moved */
60
+ GIT_SUBMODULE_IGNORE_ALL = 3 /* never dirty */
34
61
  } git_submodule_ignore_t;
35
62
 
36
63
  /**
37
- * Description of submodule
64
+ * Return codes for submodule status.
38
65
  *
39
- * This record describes a submodule found in a repository. There
40
- * should be an entry for every submodule found in the HEAD and for
41
- * every submodule described in .gitmodules. The fields are as follows:
66
+ * A combination of these flags will be returned to describe the status of a
67
+ * submodule. Depending on the "ignore" property of the submodule, some of
68
+ * the flags may never be returned because they indicate changes that are
69
+ * supposed to be ignored.
42
70
  *
43
- * - `name` is the name of the submodule from .gitmodules.
44
- * - `path` is the path to the submodule from the repo working directory.
45
- * It is almost always the same as `name`.
46
- * - `url` is the url for the submodule.
47
- * - `oid` is the HEAD SHA1 for the submodule.
48
- * - `update` is a value from above - see gitmodules(5) update.
49
- * - `ignore` is a value from above - see gitmodules(5) ignore.
50
- * - `fetch_recurse` is 0 or 1 - see gitmodules(5) fetchRecurseSubmodules.
51
- * - `refcount` is for internal use.
71
+ * Submodule info is contained in 4 places: the HEAD tree, the index, config
72
+ * files (both .git/config and .gitmodules), and the working directory. Any
73
+ * or all of those places might be missing information about the submodule
74
+ * depending on what state the repo is in. We consider all four places to
75
+ * build the combination of status flags.
52
76
  *
53
- * If the submodule has been added to .gitmodules but not yet git added,
54
- * then the `oid` will be zero. If the submodule has been deleted, but
55
- * the delete has not been committed yet, then the `oid` will be set, but
56
- * the `url` will be NULL.
77
+ * There are four values that are not really status, but give basic info
78
+ * about what sources of submodule data are available. These will be
79
+ * returned even if ignore is set to "ALL".
80
+ *
81
+ * * IN_HEAD - superproject head contains submodule
82
+ * * IN_INDEX - superproject index contains submodule
83
+ * * IN_CONFIG - superproject gitmodules has submodule
84
+ * * IN_WD - superproject workdir has submodule
85
+ *
86
+ * The following values will be returned so long as ignore is not "ALL".
87
+ *
88
+ * * INDEX_ADDED - in index, not in head
89
+ * * INDEX_DELETED - in head, not in index
90
+ * * INDEX_MODIFIED - index and head don't match
91
+ * * WD_UNINITIALIZED - workdir contains empty directory
92
+ * * WD_ADDED - in workdir, not index
93
+ * * WD_DELETED - in index, not workdir
94
+ * * WD_MODIFIED - index and workdir head don't match
95
+ *
96
+ * The following can only be returned if ignore is "NONE" or "UNTRACKED".
97
+ *
98
+ * * WD_INDEX_MODIFIED - submodule workdir index is dirty
99
+ * * WD_WD_MODIFIED - submodule workdir has modified files
100
+ *
101
+ * Lastly, the following will only be returned for ignore "NONE".
102
+ *
103
+ * * WD_UNTRACKED - wd contains untracked files
57
104
  */
58
- typedef struct {
59
- char *name;
60
- char *path;
61
- char *url;
62
- git_oid oid; /* sha1 of submodule HEAD ref or zero if not committed */
63
- git_submodule_update_t update;
64
- git_submodule_ignore_t ignore;
65
- int fetch_recurse;
66
- int refcount;
67
- } git_submodule;
105
+ typedef enum {
106
+ GIT_SUBMODULE_STATUS_IN_HEAD = (1u << 0),
107
+ GIT_SUBMODULE_STATUS_IN_INDEX = (1u << 1),
108
+ GIT_SUBMODULE_STATUS_IN_CONFIG = (1u << 2),
109
+ GIT_SUBMODULE_STATUS_IN_WD = (1u << 3),
110
+ GIT_SUBMODULE_STATUS_INDEX_ADDED = (1u << 4),
111
+ GIT_SUBMODULE_STATUS_INDEX_DELETED = (1u << 5),
112
+ GIT_SUBMODULE_STATUS_INDEX_MODIFIED = (1u << 6),
113
+ GIT_SUBMODULE_STATUS_WD_UNINITIALIZED = (1u << 7),
114
+ GIT_SUBMODULE_STATUS_WD_ADDED = (1u << 8),
115
+ GIT_SUBMODULE_STATUS_WD_DELETED = (1u << 9),
116
+ GIT_SUBMODULE_STATUS_WD_MODIFIED = (1u << 10),
117
+ GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11),
118
+ GIT_SUBMODULE_STATUS_WD_WD_MODIFIED = (1u << 12),
119
+ GIT_SUBMODULE_STATUS_WD_UNTRACKED = (1u << 13),
120
+ } git_submodule_status_t;
121
+
122
+ #define GIT_SUBMODULE_STATUS_IS_UNMODIFIED(S) \
123
+ (((S) & ~(GIT_SUBMODULE_STATUS_IN_HEAD | \
124
+ GIT_SUBMODULE_STATUS_IN_INDEX | \
125
+ GIT_SUBMODULE_STATUS_IN_CONFIG | \
126
+ GIT_SUBMODULE_STATUS_IN_WD)) == 0)
127
+
128
+ #define GIT_SUBMODULE_STATUS_IS_WD_DIRTY(S) \
129
+ (((S) & (GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED | \
130
+ GIT_SUBMODULE_STATUS_WD_WD_MODIFIED | \
131
+ GIT_SUBMODULE_STATUS_WD_UNTRACKED)) != 0)
68
132
 
69
133
  /**
70
- * Iterate over all submodules of a repository.
134
+ * Lookup submodule information by name or path.
135
+ *
136
+ * Given either the submodule name or path (they are usually the same), this
137
+ * returns a structure describing the submodule.
138
+ *
139
+ * There are two expected error scenarios:
140
+ *
141
+ * - The submodule is not mentioned in the HEAD, the index, and the config,
142
+ * but does "exist" in the working directory (i.e. there is a subdirectory
143
+ * that is a valid self-contained git repo). In this case, this function
144
+ * returns GIT_EEXISTS to indicate the the submodule exists but not in a
145
+ * state where a git_submodule can be instantiated.
146
+ * - The submodule is not mentioned in the HEAD, index, or config and the
147
+ * working directory doesn't contain a value git repo at that path.
148
+ * There may or may not be anything else at that path, but nothing that
149
+ * looks like a submodule. In this case, this returns GIT_ENOTFOUND.
150
+ *
151
+ * The submodule object is owned by the containing repo and will be freed
152
+ * when the repo is freed. The caller need not free the submodule.
153
+ *
154
+ * @param submodule Pointer to submodule description object pointer..
155
+ * @param repo The repository.
156
+ * @param name The name of the submodule. Trailing slashes will be ignored.
157
+ * @return 0 on success, GIT_ENOTFOUND if submodule does not exist,
158
+ * GIT_EEXISTS if submodule exists in working directory only, -1 on
159
+ * other errors.
160
+ */
161
+ GIT_EXTERN(int) git_submodule_lookup(
162
+ git_submodule **submodule,
163
+ git_repository *repo,
164
+ const char *name);
165
+
166
+ /**
167
+ * Iterate over all tracked submodules of a repository.
168
+ *
169
+ * See the note on `git_submodule` above. This iterates over the tracked
170
+ * submodules as decribed therein.
171
+ *
172
+ * If you are concerned about items in the working directory that look like
173
+ * submodules but are not tracked, the diff API will generate a diff record
174
+ * for workdir items that look like submodules but are not tracked, showing
175
+ * them as added in the workdir. Also, the status API will treat the entire
176
+ * subdirectory of a contained git repo as a single GIT_STATUS_WT_NEW item.
71
177
  *
72
178
  * @param repo The repository
73
179
  * @param callback Function to be called with the name of each submodule.
@@ -77,26 +183,326 @@ typedef struct {
77
183
  */
78
184
  GIT_EXTERN(int) git_submodule_foreach(
79
185
  git_repository *repo,
80
- int (*callback)(const char *name, void *payload),
186
+ int (*callback)(git_submodule *sm, const char *name, void *payload),
81
187
  void *payload);
82
188
 
83
189
  /**
84
- * Lookup submodule information by name or path.
190
+ * Set up a new git submodule for checkout.
85
191
  *
86
- * Given either the submodule name or path (they are usually the same),
87
- * this returns a structure describing the submodule. If the submodule
88
- * does not exist, this will return GIT_ENOTFOUND and set the submodule
89
- * pointer to NULL.
192
+ * This does "git submodule add" up to the fetch and checkout of the
193
+ * submodule contents. It preps a new submodule, creates an entry in
194
+ * .gitmodules and creates an empty initialized repository either at the
195
+ * given path in the working directory or in .git/modules with a gitlink
196
+ * from the working directory to the new repo.
90
197
  *
91
- * @param submodule Pointer to submodule description object pointer..
92
- * @param repo The repository.
93
- * @param name The name of the submodule. Trailing slashes will be ignored.
94
- * @return 0 on success, GIT_ENOTFOUND if submodule does not exist, -1 on error
198
+ * To fully emulate "git submodule add" call this function, then open the
199
+ * submodule repo and perform the clone step as needed. Lastly, call
200
+ * `git_submodule_add_finalize()` to wrap up adding the new submodule and
201
+ * .gitmodules to the index to be ready to commit.
202
+ *
203
+ * @param submodule The newly created submodule ready to open for clone
204
+ * @param repo Superproject repository to contain the new submodule
205
+ * @param url URL for the submodules remote
206
+ * @param path Path at which the submodule should be created
207
+ * @param use_gitlink Should workdir contain a gitlink to the repo in
208
+ * .git/modules vs. repo directly in workdir.
209
+ * @return 0 on success, GIT_EEXISTS if submodule already exists,
210
+ * -1 on other errors.
95
211
  */
96
- GIT_EXTERN(int) git_submodule_lookup(
212
+ GIT_EXTERN(int) git_submodule_add_setup(
97
213
  git_submodule **submodule,
98
214
  git_repository *repo,
99
- const char *name);
215
+ const char *url,
216
+ const char *path,
217
+ int use_gitlink);
218
+
219
+ /**
220
+ * Resolve the setup of a new git submodule.
221
+ *
222
+ * This should be called on a submodule once you have called add setup
223
+ * and done the clone of the submodule. This adds the .gitmodules file
224
+ * and the newly cloned submodule to the index to be ready to be committed
225
+ * (but doesn't actually do the commit).
226
+ *
227
+ * @param submodule The submodule to finish adding.
228
+ */
229
+ GIT_EXTERN(int) git_submodule_add_finalize(git_submodule *submodule);
230
+
231
+ /**
232
+ * Add current submodule HEAD commit to index of superproject.
233
+ *
234
+ * @param submodule The submodule to add to the index
235
+ * @param write_index Boolean if this should immediately write the index
236
+ * file. If you pass this as false, you will have to get the
237
+ * git_index and explicitly call `git_index_write()` on it to
238
+ * save the change.
239
+ * @return 0 on success, <0 on failure
240
+ */
241
+ GIT_EXTERN(int) git_submodule_add_to_index(
242
+ git_submodule *submodule,
243
+ int write_index);
244
+
245
+ /**
246
+ * Write submodule settings to .gitmodules file.
247
+ *
248
+ * This commits any in-memory changes to the submodule to the gitmodules
249
+ * file on disk. You may also be interested in `git_submodule_init()` which
250
+ * writes submodule info to ".git/config" (which is better for local changes
251
+ * to submodule settings) and/or `git_submodule_sync()` which writes
252
+ * settings about remotes to the actual submodule repository.
253
+ *
254
+ * @param submodule The submodule to write.
255
+ * @return 0 on success, <0 on failure.
256
+ */
257
+ GIT_EXTERN(int) git_submodule_save(git_submodule *submodule);
258
+
259
+ /**
260
+ * Get the containing repository for a submodule.
261
+ *
262
+ * This returns a pointer to the repository that contains the submodule.
263
+ * This is a just a reference to the repository that was passed to the
264
+ * original `git_submodule_lookup()` call, so if that repository has been
265
+ * freed, then this may be a dangling reference.
266
+ *
267
+ * @param submodule Pointer to submodule object
268
+ * @return Pointer to `git_repository`
269
+ */
270
+ GIT_EXTERN(git_repository *) git_submodule_owner(git_submodule *submodule);
271
+
272
+ /**
273
+ * Get the name of submodule.
274
+ *
275
+ * @param submodule Pointer to submodule object
276
+ * @return Pointer to the submodule name
277
+ */
278
+ GIT_EXTERN(const char *) git_submodule_name(git_submodule *submodule);
279
+
280
+ /**
281
+ * Get the path to the submodule.
282
+ *
283
+ * The path is almost always the same as the submodule name, but the
284
+ * two are actually not required to match.
285
+ *
286
+ * @param submodule Pointer to submodule object
287
+ * @return Pointer to the submodule path
288
+ */
289
+ GIT_EXTERN(const char *) git_submodule_path(git_submodule *submodule);
290
+
291
+ /**
292
+ * Get the URL for the submodule.
293
+ *
294
+ * @param submodule Pointer to submodule object
295
+ * @return Pointer to the submodule url
296
+ */
297
+ GIT_EXTERN(const char *) git_submodule_url(git_submodule *submodule);
298
+
299
+ /**
300
+ * Set the URL for the submodule.
301
+ *
302
+ * This sets the URL in memory for the submodule. This will be used for
303
+ * any following submodule actions while this submodule data is in memory.
304
+ *
305
+ * After calling this, you may wish to call `git_submodule_save()` to write
306
+ * the changes back to the ".gitmodules" file and `git_submodule_sync()` to
307
+ * write the changes to the checked out submodule repository.
308
+ *
309
+ * @param submodule Pointer to the submodule object
310
+ * @param url URL that should be used for the submodule
311
+ * @return 0 on success, <0 on failure
312
+ */
313
+ GIT_EXTERN(int) git_submodule_set_url(git_submodule *submodule, const char *url);
314
+
315
+ /**
316
+ * Get the OID for the submodule in the index.
317
+ *
318
+ * @param submodule Pointer to submodule object
319
+ * @return Pointer to git_oid or NULL if submodule is not in index.
320
+ */
321
+ GIT_EXTERN(const git_oid *) git_submodule_index_oid(git_submodule *submodule);
322
+
323
+ /**
324
+ * Get the OID for the submodule in the current HEAD tree.
325
+ *
326
+ * @param submodule Pointer to submodule object
327
+ * @return Pointer to git_oid or NULL if submodule is not in the HEAD.
328
+ */
329
+ GIT_EXTERN(const git_oid *) git_submodule_head_oid(git_submodule *submodule);
330
+
331
+ /**
332
+ * Get the OID for the submodule in the current working directory.
333
+ *
334
+ * This returns the OID that corresponds to looking up 'HEAD' in the checked
335
+ * out submodule. If there are pending changes in the index or anything
336
+ * else, this won't notice that. You should call `git_submodule_status()`
337
+ * for a more complete picture about the state of the working directory.
338
+ *
339
+ * @param submodule Pointer to submodule object
340
+ * @return Pointer to git_oid or NULL if submodule is not checked out.
341
+ */
342
+ GIT_EXTERN(const git_oid *) git_submodule_wd_oid(git_submodule *submodule);
343
+
344
+ /**
345
+ * Get the ignore rule for the submodule.
346
+ *
347
+ * There are four ignore values:
348
+ *
349
+ * - **GIT_SUBMODULE_IGNORE_NONE** will consider any change to the contents
350
+ * of the submodule from a clean checkout to be dirty, including the
351
+ * addition of untracked files. This is the default if unspecified.
352
+ * - **GIT_SUBMODULE_IGNORE_UNTRACKED** examines the contents of the
353
+ * working tree (i.e. call `git_status_foreach()` on the submodule) but
354
+ * UNTRACKED files will not count as making the submodule dirty.
355
+ * - **GIT_SUBMODULE_IGNORE_DIRTY** means to only check if the HEAD of the
356
+ * submodule has moved for status. This is fast since it does not need to
357
+ * scan the working tree of the submodule at all.
358
+ * - **GIT_SUBMODULE_IGNORE_ALL** means not to open the submodule repo.
359
+ * The working directory will be consider clean so long as there is a
360
+ * checked out version present.
361
+ */
362
+ GIT_EXTERN(git_submodule_ignore_t) git_submodule_ignore(
363
+ git_submodule *submodule);
364
+
365
+ /**
366
+ * Set the ignore rule for the submodule.
367
+ *
368
+ * This sets the ignore rule in memory for the submodule. This will be used
369
+ * for any following actions (such as `git_submodule_status()`) while the
370
+ * submodule is in memory. You should call `git_submodule_save()` if you
371
+ * want to persist the new ignore role.
372
+ *
373
+ * Calling this again with GIT_SUBMODULE_IGNORE_DEFAULT or calling
374
+ * `git_submodule_reload()` will revert the rule to the value that was in the
375
+ * original config.
376
+ *
377
+ * @return old value for ignore
378
+ */
379
+ GIT_EXTERN(git_submodule_ignore_t) git_submodule_set_ignore(
380
+ git_submodule *submodule,
381
+ git_submodule_ignore_t ignore);
382
+
383
+ /**
384
+ * Get the update rule for the submodule.
385
+ */
386
+ GIT_EXTERN(git_submodule_update_t) git_submodule_update(
387
+ git_submodule *submodule);
388
+
389
+ /**
390
+ * Set the update rule for the submodule.
391
+ *
392
+ * This sets the update rule in memory for the submodule. You should call
393
+ * `git_submodule_save()` if you want to persist the new update rule.
394
+ *
395
+ * Calling this again with GIT_SUBMODULE_UPDATE_DEFAULT or calling
396
+ * `git_submodule_reload()` will revert the rule to the value that was in the
397
+ * original config.
398
+ *
399
+ * @return old value for update
400
+ */
401
+ GIT_EXTERN(git_submodule_update_t) git_submodule_set_update(
402
+ git_submodule *submodule,
403
+ git_submodule_update_t update);
404
+
405
+ /**
406
+ * Read the fetchRecurseSubmodules rule for a submodule.
407
+ *
408
+ * This accesses the submodule.<name>.fetchRecurseSubmodules value for
409
+ * the submodule that controls fetching behavior for the submodule.
410
+ *
411
+ * Note that at this time, libgit2 does not honor this setting and the
412
+ * fetch functionality current ignores submodules.
413
+ *
414
+ * @return 0 if fetchRecurseSubmodules is false, 1 if true
415
+ */
416
+ GIT_EXTERN(int) git_submodule_fetch_recurse_submodules(
417
+ git_submodule *submodule);
418
+
419
+ /**
420
+ * Set the fetchRecurseSubmodules rule for a submodule.
421
+ *
422
+ * This sets the submodule.<name>.fetchRecurseSubmodules value for
423
+ * the submodule. You should call `git_submodule_save()` if you want
424
+ * to persist the new value.
425
+ *
426
+ * @param submodule The submodule to modify
427
+ * @param fetch_recurse_submodules Boolean value
428
+ * @return old value for fetchRecurseSubmodules
429
+ */
430
+ GIT_EXTERN(int) git_submodule_set_fetch_recurse_submodules(
431
+ git_submodule *submodule,
432
+ int fetch_recurse_submodules);
433
+
434
+ /**
435
+ * Copy submodule info into ".git/config" file.
436
+ *
437
+ * Just like "git submodule init", this copies information about the
438
+ * submodule into ".git/config". You can use the accessor functions
439
+ * above to alter the in-memory git_submodule object and control what
440
+ * is written to the config, overriding what is in .gitmodules.
441
+ *
442
+ * @param submodule The submodule to write into the superproject config
443
+ * @param overwrite By default, existing entries will not be overwritten,
444
+ * but setting this to true forces them to be updated.
445
+ * @return 0 on success, <0 on failure.
446
+ */
447
+ GIT_EXTERN(int) git_submodule_init(git_submodule *submodule, int overwrite);
448
+
449
+ /**
450
+ * Copy submodule remote info into submodule repo.
451
+ *
452
+ * This copies the information about the submodules URL into the checked out
453
+ * submodule config, acting like "git submodule sync". This is useful if
454
+ * you have altered the URL for the submodule (or it has been altered by a
455
+ * fetch of upstream changes) and you need to update your local repo.
456
+ */
457
+ GIT_EXTERN(int) git_submodule_sync(git_submodule *submodule);
458
+
459
+ /**
460
+ * Open the repository for a submodule.
461
+ *
462
+ * This is a newly opened repository object. The caller is responsible for
463
+ * calling `git_repository_free()` on it when done. Multiple calls to this
464
+ * function will return distinct `git_repository` objects. This will only
465
+ * work if the submodule is checked out into the working directory.
466
+ *
467
+ * @param subrepo Pointer to the submodule repo which was opened
468
+ * @param submodule Submodule to be opened
469
+ * @return 0 on success, <0 if submodule repo could not be opened.
470
+ */
471
+ GIT_EXTERN(int) git_submodule_open(
472
+ git_repository **repo,
473
+ git_submodule *submodule);
474
+
475
+ /**
476
+ * Reread submodule info from config, index, and HEAD.
477
+ *
478
+ * Call this to reread cached submodule information for this submodule if
479
+ * you have reason to believe that it has changed.
480
+ */
481
+ GIT_EXTERN(int) git_submodule_reload(git_submodule *submodule);
482
+
483
+ /**
484
+ * Reread all submodule info.
485
+ *
486
+ * Call this to reload all cached submodule information for the repo.
487
+ */
488
+ GIT_EXTERN(int) git_submodule_reload_all(git_repository *repo);
489
+
490
+ /**
491
+ * Get the status for a submodule.
492
+ *
493
+ * This looks at a submodule and tries to determine the status. It
494
+ * will return a combination of the `GIT_SUBMODULE_STATUS` values above.
495
+ * How deeply it examines the working directory to do this will depend
496
+ * on the `git_submodule_ignore_t` value for the submodule - which can be
497
+ * set either temporarily or permanently with `git_submodule_set_ignore()`.
498
+ *
499
+ * @param status Combination of `GIT_SUBMODULE_STATUS` flags
500
+ * @param submodule Submodule for which to get status
501
+ * @return 0 on success, <0 on error
502
+ */
503
+ GIT_EXTERN(int) git_submodule_status(
504
+ unsigned int *status,
505
+ git_submodule *submodule);
100
506
 
101
507
  /** @} */
102
508
  GIT_END_DECL