]>
Commit | Line | Data |
---|---|---|
590fb68b | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
590fb68b | 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_stash_h__ | |
8 | #define INCLUDE_git_stash_h__ | |
9 | ||
10 | #include "common.h" | |
11 | #include "types.h" | |
ac3d33df | 12 | #include "checkout.h" |
590fb68b | 13 | |
14 | /** | |
15 | * @file git2/stash.h | |
16 | * @brief Git stash management routines | |
17 | * @ingroup Git | |
18 | * @{ | |
19 | */ | |
20 | GIT_BEGIN_DECL | |
21 | ||
a295bd2d CMN |
22 | /** |
23 | * Stash flags | |
24 | */ | |
1d8ec670 | 25 | typedef enum { |
a295bd2d CMN |
26 | /** |
27 | * No option, default | |
28 | */ | |
590fb68b | 29 | GIT_STASH_DEFAULT = 0, |
30 | ||
a295bd2d CMN |
31 | /** |
32 | * All changes already added to the index are left intact in | |
33 | * the working directory | |
590fb68b | 34 | */ |
35 | GIT_STASH_KEEP_INDEX = (1 << 0), | |
36 | ||
a295bd2d CMN |
37 | /** |
38 | * All untracked files are also stashed and then cleaned up | |
39 | * from the working directory | |
590fb68b | 40 | */ |
41 | GIT_STASH_INCLUDE_UNTRACKED = (1 << 1), | |
42 | ||
a295bd2d CMN |
43 | /** |
44 | * All ignored files are also stashed and then cleaned up from | |
45 | * the working directory | |
590fb68b | 46 | */ |
e579e0f7 | 47 | GIT_STASH_INCLUDE_IGNORED = (1 << 2) |
1d8ec670 | 48 | } git_stash_flags; |
590fb68b | 49 | |
50 | /** | |
51 | * Save the local modifications to a new stash. | |
52 | * | |
53 | * @param out Object id of the commit containing the stashed state. | |
54 | * This commit is also the target of the direct reference refs/stash. | |
55 | * | |
56 | * @param repo The owning repository. | |
57 | * | |
58 | * @param stasher The identity of the person performing the stashing. | |
59 | * | |
60 | * @param message Optional description along with the stashed state. | |
61 | * | |
1d8ec670 | 62 | * @param flags Flags to control the stashing process. (see GIT_STASH_* above) |
590fb68b | 63 | * |
64 | * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash, | |
65 | * or error code. | |
66 | */ | |
590fb68b | 67 | GIT_EXTERN(int) git_stash_save( |
68 | git_oid *out, | |
69 | git_repository *repo, | |
2274993b | 70 | const git_signature *stasher, |
590fb68b | 71 | const char *message, |
95746a57 | 72 | uint32_t flags); |
590fb68b | 73 | |
19c80a6f | 74 | /** Stash application flags. */ |
bf8dd3f5 | 75 | typedef enum { |
19c80a6f | 76 | GIT_STASH_APPLY_DEFAULT = 0, |
bf8dd3f5 POL |
77 | |
78 | /* Try to reinstate not only the working tree's changes, | |
19c80a6f | 79 | * but also the index's changes. |
bf8dd3f5 | 80 | */ |
e579e0f7 | 81 | GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0) |
19c80a6f ET |
82 | } git_stash_apply_flags; |
83 | ||
ac3d33df | 84 | /** Stash apply progression states */ |
4ea3eebf ET |
85 | typedef enum { |
86 | GIT_STASH_APPLY_PROGRESS_NONE = 0, | |
87 | ||
88 | /** Loading the stashed data from the object database. */ | |
89 | GIT_STASH_APPLY_PROGRESS_LOADING_STASH, | |
90 | ||
91 | /** The stored index is being analyzed. */ | |
92 | GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX, | |
93 | ||
94 | /** The modified files are being analyzed. */ | |
95 | GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED, | |
96 | ||
97 | /** The untracked and ignored files are being analyzed. */ | |
98 | GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED, | |
99 | ||
100 | /** The untracked files are being written to disk. */ | |
101 | GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED, | |
102 | ||
103 | /** The modified files are being written to disk. */ | |
104 | GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED, | |
105 | ||
106 | /** The stash was applied successfully. */ | |
e579e0f7 | 107 | GIT_STASH_APPLY_PROGRESS_DONE |
4ea3eebf ET |
108 | } git_stash_apply_progress_t; |
109 | ||
110 | /** | |
111 | * Stash application progress notification function. | |
112 | * Return 0 to continue processing, or a negative value to | |
113 | * abort the stash application. | |
114 | */ | |
ac3d33df | 115 | typedef int GIT_CALLBACK(git_stash_apply_progress_cb)( |
4ea3eebf ET |
116 | git_stash_apply_progress_t progress, |
117 | void *payload); | |
118 | ||
ac3d33df JK |
119 | /** |
120 | * Stash application options structure | |
19c80a6f | 121 | * |
ac3d33df | 122 | * Initialize with `GIT_STASH_APPLY_OPTIONS_INIT`. Alternatively, you can |
22a2d3d5 | 123 | * use `git_stash_apply_options_init`. |
19c80a6f | 124 | * |
19c80a6f ET |
125 | */ |
126 | typedef struct git_stash_apply_options { | |
127 | unsigned int version; | |
128 | ||
22a2d3d5 UG |
129 | /** See `git_stash_apply_flags`, above. */ |
130 | uint32_t flags; | |
19c80a6f ET |
131 | |
132 | /** Options to use when writing files to the working directory. */ | |
133 | git_checkout_options checkout_options; | |
4ea3eebf ET |
134 | |
135 | /** Optional callback to notify the consumer of application progress. */ | |
136 | git_stash_apply_progress_cb progress_cb; | |
137 | void *progress_payload; | |
19c80a6f ET |
138 | } git_stash_apply_options; |
139 | ||
140 | #define GIT_STASH_APPLY_OPTIONS_VERSION 1 | |
141 | #define GIT_STASH_APPLY_OPTIONS_INIT { \ | |
142 | GIT_STASH_APPLY_OPTIONS_VERSION, \ | |
143 | GIT_STASH_APPLY_DEFAULT, \ | |
144 | GIT_CHECKOUT_OPTIONS_INIT } | |
145 | ||
146 | /** | |
ac3d33df JK |
147 | * Initialize git_stash_apply_options structure |
148 | * | |
19c80a6f | 149 | * Initializes a `git_stash_apply_options` with default values. Equivalent to |
ac3d33df | 150 | * creating an instance with `GIT_STASH_APPLY_OPTIONS_INIT`. |
19c80a6f | 151 | * |
ac3d33df JK |
152 | * @param opts The `git_stash_apply_options` struct to initialize. |
153 | * @param version The struct version; pass `GIT_STASH_APPLY_OPTIONS_VERSION`. | |
19c80a6f ET |
154 | * @return Zero on success; -1 on failure. |
155 | */ | |
22a2d3d5 | 156 | GIT_EXTERN(int) git_stash_apply_options_init( |
19c80a6f | 157 | git_stash_apply_options *opts, unsigned int version); |
bf8dd3f5 POL |
158 | |
159 | /** | |
160 | * Apply a single stashed state from the stash list. | |
161 | * | |
958950b6 ET |
162 | * If local changes in the working directory conflict with changes in the |
163 | * stash then GIT_EMERGECONFLICT will be returned. In this case, the index | |
164 | * will always remain unmodified and all files in the working directory will | |
165 | * remain unmodified. However, if you are restoring untracked files or | |
166 | * ignored files and there is a conflict when applying the modified files, | |
167 | * then those files will remain in the working directory. | |
bf8dd3f5 | 168 | * |
19c80a6f ET |
169 | * If passing the GIT_STASH_APPLY_REINSTATE_INDEX flag and there would be |
170 | * conflicts when reinstating the index, the function will return | |
171 | * GIT_EMERGECONFLICT and both the working directory and index will be left | |
172 | * unmodified. | |
173 | * | |
174 | * Note that a minimum checkout strategy of `GIT_CHECKOUT_SAFE` is implied. | |
bf8dd3f5 POL |
175 | * |
176 | * @param repo The owning repository. | |
bf8dd3f5 | 177 | * @param index The position within the stash list. 0 points to the |
f0957589 | 178 | * most recent stashed state. |
93e2c744 | 179 | * @param options Optional options to control how stashes are applied. |
bf8dd3f5 | 180 | * |
958950b6 ET |
181 | * @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the |
182 | * given index, GIT_EMERGECONFLICT if changes exist in the working | |
183 | * directory, or an error code | |
bf8dd3f5 POL |
184 | */ |
185 | GIT_EXTERN(int) git_stash_apply( | |
186 | git_repository *repo, | |
187 | size_t index, | |
19c80a6f | 188 | const git_stash_apply_options *options); |
bf8dd3f5 | 189 | |
23388413 | 190 | /** |
373cf6a9 RB |
191 | * This is a callback function you can provide to iterate over all the |
192 | * stashed states that will be invoked per entry. | |
23388413 | 193 | * |
194 | * @param index The position within the stash list. 0 points to the | |
373cf6a9 | 195 | * most recent stashed state. |
23388413 | 196 | * @param message The stash message. |
1d8ec670 | 197 | * @param stash_id The commit oid of the stashed state. |
23388413 | 198 | * @param payload Extra parameter to callback function. |
bf8dd3f5 | 199 | * @return 0 to continue iterating or non-zero to stop. |
23388413 | 200 | */ |
ac3d33df | 201 | typedef int GIT_CALLBACK(git_stash_cb)( |
23388413 | 202 | size_t index, |
c25aa7cd | 203 | const char *message, |
1d8ec670 | 204 | const git_oid *stash_id, |
23388413 | 205 | void *payload); |
206 | ||
207 | /** | |
208 | * Loop over all the stashed states and issue a callback for each one. | |
209 | * | |
210 | * If the callback returns a non-zero value, this will stop looping. | |
211 | * | |
212 | * @param repo Repository where to find the stash. | |
213 | * | |
373cf6a9 RB |
214 | * @param callback Callback to invoke per found stashed state. The most |
215 | * recent stash state will be enumerated first. | |
23388413 | 216 | * |
217 | * @param payload Extra parameter to callback function. | |
218 | * | |
bf8dd3f5 | 219 | * @return 0 on success, non-zero callback return value, or error code. |
23388413 | 220 | */ |
221 | GIT_EXTERN(int) git_stash_foreach( | |
222 | git_repository *repo, | |
1d8ec670 | 223 | git_stash_cb callback, |
23388413 | 224 | void *payload); |
225 | ||
e4c64cf2 | 226 | /** |
227 | * Remove a single stashed state from the stash list. | |
228 | * | |
229 | * @param repo The owning repository. | |
230 | * | |
231 | * @param index The position within the stash list. 0 points to the | |
232 | * most recent stashed state. | |
233 | * | |
bf8dd3f5 POL |
234 | * @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given |
235 | * index, or error code. | |
e4c64cf2 | 236 | */ |
e4c64cf2 | 237 | GIT_EXTERN(int) git_stash_drop( |
238 | git_repository *repo, | |
239 | size_t index); | |
240 | ||
bf8dd3f5 POL |
241 | /** |
242 | * Apply a single stashed state from the stash list and remove it from the list | |
243 | * if successful. | |
244 | * | |
245 | * @param repo The owning repository. | |
bf8dd3f5 | 246 | * @param index The position within the stash list. 0 points to the |
f0957589 | 247 | * most recent stashed state. |
93e2c744 | 248 | * @param options Optional options to control how stashes are applied. |
bf8dd3f5 POL |
249 | * |
250 | * @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given | |
251 | * index, or error code. (see git_stash_apply() above for details) | |
252 | */ | |
253 | GIT_EXTERN(int) git_stash_pop( | |
254 | git_repository *repo, | |
255 | size_t index, | |
19c80a6f | 256 | const git_stash_apply_options *options); |
bf8dd3f5 | 257 | |
590fb68b | 258 | /** @} */ |
259 | GIT_END_DECL | |
260 | #endif |