1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
/**
* @file git2/checkout.h
* @brief Git checkout routines
* @defgroup git_checkout Git checkout routines
* @ingroup Git
* @{
*/
/**
* Checkout behavior flags
*
* In libgit2, checkout is used to update the working directory and index
* to match a target tree. Unlike git checkout, it does not move the HEAD
* commit for you - use `git_repository_set_head` or the like to do that.
*
* Checkout looks at (up to) four things: the "target" tree you want to
* check out, the "baseline" tree of what was checked out previously, the
* working directory for actual files, and the index for staged changes.
*
* You give checkout one of three strategies for update:
*
* - `GIT_CHECKOUT_NONE` is a dry-run strategy that checks for conflicts,
* etc., but doesn't make any actual changes.
*
* - `GIT_CHECKOUT_FORCE` is at the opposite extreme, taking any action to
* make the working directory match the target (including potentially
* discarding modified files).
*
* - `GIT_CHECKOUT_SAFE` is between these two options, it will only make
* modifications that will not lose changes.
*
* | target == baseline | target != baseline |
* ---------------------|-----------------------|----------------------|
* workdir == baseline | no action | create, update, or |
* | | delete file |
* ---------------------|-----------------------|----------------------|
* workdir exists and | no action | conflict (notify |
* is != baseline | notify dirty MODIFIED | and cancel checkout) |
* ---------------------|-----------------------|----------------------|
* workdir missing, | notify dirty DELETED | create file |
* baseline present | | |
* ---------------------|-----------------------|----------------------|
*
* To emulate `git checkout`, use `GIT_CHECKOUT_SAFE` with a checkout
* notification callback (see below) that displays information about dirty
* files. The default behavior will cancel checkout on conflicts.
*
* To emulate `git checkout-index`, use `GIT_CHECKOUT_SAFE` with a
* notification callback that cancels the operation if a dirty-but-existing
* file is found in the working directory. This core git command isn't
* quite "force" but is sensitive about some types of changes.
*
* To emulate `git checkout -f`, use `GIT_CHECKOUT_FORCE`.
*
*
* There are some additional flags to modified the behavior of checkout:
*
* - GIT_CHECKOUT_ALLOW_CONFLICTS makes SAFE mode apply safe file updates
* even if there are conflicts (instead of cancelling the checkout).
*
* - GIT_CHECKOUT_REMOVE_UNTRACKED means remove untracked files (i.e. not
* in target, baseline, or index, and not ignored) from the working dir.
*
* - GIT_CHECKOUT_REMOVE_IGNORED means remove ignored files (that are also
* untracked) from the working directory as well.
*
* - GIT_CHECKOUT_UPDATE_ONLY means to only update the content of files that
* already exist. Files will not be created nor deleted. This just skips
* applying adds, deletes, and typechanges.
*
* - GIT_CHECKOUT_DONT_UPDATE_INDEX prevents checkout from writing the
* updated files' information to the index.
*
* - Normally, checkout will reload the index and git attributes from disk
* before any operations. GIT_CHECKOUT_NO_REFRESH prevents this reload.
*
* - Unmerged index entries are conflicts. GIT_CHECKOUT_SKIP_UNMERGED skips
* files with unmerged index entries instead. GIT_CHECKOUT_USE_OURS and
* GIT_CHECKOUT_USE_THEIRS to proceed with the checkout using either the
* stage 2 ("ours") or stage 3 ("theirs") version of files in the index.
*
* - GIT_CHECKOUT_DONT_OVERWRITE_IGNORED prevents ignored files from being
* overwritten. Normally, files that are ignored in the working directory
* are not considered "precious" and may be overwritten if the checkout
* target contains that file.
*
* - GIT_CHECKOUT_DONT_REMOVE_EXISTING prevents checkout from removing
* files or folders that fold to the same name on case insensitive
* filesystems. This can cause files to retain their existing names
* and write through existing symbolic links.
*/
typedef enum git_checkout_strategy_t;
/**
* Checkout notification flags
*
* Checkout will invoke an options notification callback (`notify_cb`) for
* certain cases - you pick which ones via `notify_flags`:
*
* - GIT_CHECKOUT_NOTIFY_CONFLICT invokes checkout on conflicting paths.
*
* - GIT_CHECKOUT_NOTIFY_DIRTY notifies about "dirty" files, i.e. those that
* do not need an update but no longer match the baseline. Core git
* displays these files when checkout runs, but won't stop the checkout.
*
* - GIT_CHECKOUT_NOTIFY_UPDATED sends notification for any file changed.
*
* - GIT_CHECKOUT_NOTIFY_UNTRACKED notifies about untracked files.
*
* - GIT_CHECKOUT_NOTIFY_IGNORED notifies about ignored files.
*
* Returning a non-zero value from this callback will cancel the checkout.
* The non-zero return value will be propagated back and returned by the
* git_checkout_... call.
*
* Notification callbacks are made prior to modifying any files on disk,
* so canceling on any notification will still happen prior to any files
* being modified.
*/
typedef enum git_checkout_notify_t;
typedef struct git_checkout_perfdata;
/** Checkout notification callback function */
typedef int ;
/** Checkout progress notification function */
typedef void ;
/** Checkout perfdata notification function */
typedef void ;
/**
* Checkout options structure
*
* Zero out for defaults. Initialize with `GIT_CHECKOUT_OPTIONS_INIT` macro to
* correctly set the `version` field. E.g.
*
* git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
*/
typedef struct git_checkout_options git_checkout_options;
/**
* Initializes a `git_checkout_options` with default values. Equivalent to
* creating an instance with GIT_CHECKOUT_OPTIONS_INIT.
*
* @param opts the `git_checkout_options` struct to initialize.
* @param version Version of struct; pass `GIT_CHECKOUT_OPTIONS_VERSION`
* @return Zero on success; -1 on failure.
*/
;
/**
* Updates files in the index and the working tree to match the content of
* the commit pointed at by HEAD.
*
* Note that this is _not_ the correct mechanism used to switch branches;
* do not change your `HEAD` and then call this method, that would leave
* you with checkout conflicts since your working directory would then
* appear to be dirty. Instead, checkout the target of the branch and
* then update `HEAD` using `git_repository_set_head` to point to the
* branch you checked out.
*
* @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL)
* @return 0 on success, GIT_EUNBORNBRANCH if HEAD points to a non
* existing branch, non-zero value returned by `notify_cb`, or
* other error code < 0 (use giterr_last for error details)
*/
;
/**
* Updates files in the working tree to match the content of the index.
*
* @param repo repository into which to check out (must be non-bare)
* @param index index to be checked out (or NULL to use repository index)
* @param opts specifies checkout options (may be NULL)
* @return 0 on success, non-zero return value from `notify_cb`, or error
* code < 0 (use giterr_last for error details)
*/
;
/**
* Updates files in the index and working tree to match the content of the
* tree pointed at by the treeish.
*
* @param repo repository to check out (must be non-bare)
* @param treeish a commit, tag or tree which content will be used to update
* the working directory (or NULL to use HEAD)
* @param opts specifies checkout options (may be NULL)
* @return 0 on success, non-zero return value from `notify_cb`, or error
* code < 0 (use giterr_last for error details)
*/
;
/** @} */