@@ -52,10 +52,15 @@ int error = git_repository_init(&repo, "/tmp/…", true);
52
52
<h3 id =" repositories_init_options " >Init (Options)</h3 >
53
53
54
54
``` c
55
+ int error;
56
+ git_repository *repo = NULL ;
55
57
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
58
+
56
59
/* Customize options */
57
- git_repository *repo = NULL ;
58
- int error = git_repository_init_ext(&repo, " /tmp/…" , &opts);
60
+ opts.flags |= GIT_REPOSITORY_INIT_MKPATH; /* mkdir as needed to create repo */
61
+ opts.description = " My repository has a custom description" ;
62
+
63
+ error = git_repository_init_ext(&repo, " /tmp/…" , &opts);
59
64
```
60
65
61
66
([ ` git_repository_init_ext ` ] ( http://libgit2.github.com/libgit2/#HEAD/group/repository/git_repository_init_ext ) ,
@@ -139,8 +144,8 @@ error = git_repository_init(&repo, "/tmp/…", true);
139
144
140
145
/* Create an 'origin' remote with the mirror fetch refspec */
141
146
git_remote *origin = NULL ;
142
- error = git_remote_create_with_fetchspec(&origin, repo, " origin " ,
143
- " http://…" , " +refs/*:refs/*" );
147
+ error = git_remote_create_with_fetchspec(
148
+ &origin, repo, " origin " , " http://…" , " +refs/*:refs/*" );
144
149
145
150
/* Set remote.origin.mirror = true for compatibility with git-core */
146
151
git_config *cfg = NULL ;
@@ -168,14 +173,60 @@ int error = git_repository_open(&repo, "/tmp/…");
168
173
<h3 id =" repositories_opening_options " >Opening (Options)</h3 >
169
174
170
175
``` c
176
+ int error;
171
177
git_repository *repo = NULL ;
172
- int error = git_repository_open_ext(&repo, " /tmp/…" ,
173
- GIT_REPOSITORY_OPEN_NO_SEARCH, NULL );
178
+
179
+ /* Open repository, walking up from given directory to find root */
180
+ error = git_repository_open_ext(&repo, " /tmp/…" , 0 , NULL );
181
+
182
+ /* Open repository in given directory (or fail if not a repository) */
183
+ error = git_repository_open_ext(
184
+ &repo, " /tmp/…" , GIT_REPOSITORY_OPEN_NO_SEARCH, NULL );
185
+
186
+ /* Open repository with "ceiling" directories list to limit walking up */
187
+ error = git_repository_open_ext(
188
+ &repo, " /home/acct/…, GIT_REPOSITORY_OPEN_CROSS_FS, " /tmp:/usr:/home" );
174
189
```
175
190
176
191
([`git_repository_open_ext`](http://libgit2.github.com/libgit2/#HEAD/group/repository/git_repository_open_ext),
177
192
[`git_repository_open_flag_t`](http://libgit2.github.com/libgit2/#HEAD/type/git_repository_open_flag_t))
178
193
194
+ <h3 id=" repositories_open_bare" >Opening (Bare)</h3>
195
+
196
+ A fast way of opening a bare repository when the exact path is known.
197
+
198
+ ```c
199
+ git_repository *repo = NULL;
200
+ int error = git_repository_open_bare(&repo, " /var/data/…/repo.git" );
201
+ ```
202
+
203
+ ([`git_repository_open_bare`](http://libgit2.github.com/libgit2/#HEAD/group/repository/git_repository_open_bare))
204
+
205
+ <h3 id=" repositories_openable" >Is Directory A Repository?</h3>
206
+
207
+ ```c
208
+ /* Pass NULL for the output parameter to not open the repo immediately */
209
+ int error = git_repository_open_ext(
210
+ NULL, " /tmp/…" , GIT_REPOSITORY_OPEN_NO_SEARCH, NULL);
211
+ ```
212
+
213
+ ([`git_repository_open_ext`](http://libgit2.github.com/libgit2/#HEAD/group/repository/git_repository_open_ext),
214
+ [`git_repository_open_flag_t`](http://libgit2.github.com/libgit2/#HEAD/type/git_repository_open_flag_t))
215
+
216
+ <h3 id=" repositories_discover" >Find Repository Root</h3>
217
+
218
+ Check if a given path is inside a repository and return the repository
219
+ root directory if found.
220
+
221
+ ```c
222
+ git_buf root = {0};
223
+ int error = git_repository_discover(&root, " /tmp/…" , 0, NULL);
224
+ …
225
+ git_buf_free(&root); /* returned path data must be freed after use */
226
+ ```
227
+
228
+ ([`git_repository_discover`](http://libgit2.github.com/libgit2/#HEAD/group/repository/git_repository_discover))
229
+
179
230
180
231
181
232
<h2 id=" objects" >Objects</h2>
0 commit comments