2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_git_stash_h__
8 #define INCLUDE_git_stash_h__
16 * @brief Git stash management routines
29 GIT_STASH_DEFAULT
= 0,
32 * All changes already added to the index are left intact in
33 * the working directory
35 GIT_STASH_KEEP_INDEX
= (1 << 0),
38 * All untracked files are also stashed and then cleaned up
39 * from the working directory
41 GIT_STASH_INCLUDE_UNTRACKED
= (1 << 1),
44 * All ignored files are also stashed and then cleaned up from
45 * the working directory
47 GIT_STASH_INCLUDE_IGNORED
= (1 << 2),
51 * Save the local modifications to a new stash.
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.
56 * @param repo The owning repository.
58 * @param stasher The identity of the person performing the stashing.
60 * @param message Optional description along with the stashed state.
62 * @param flags Flags to control the stashing process. (see GIT_STASH_* above)
64 * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash,
67 GIT_EXTERN(int) git_stash_save(
70 const git_signature
*stasher
,
74 /** Stash application flags. */
76 GIT_STASH_APPLY_DEFAULT
= 0,
78 /* Try to reinstate not only the working tree's changes,
79 * but also the index's changes.
81 GIT_STASH_APPLY_REINSTATE_INDEX
= (1 << 0),
82 } git_stash_apply_flags
;
84 /** Stash apply progression states */
86 GIT_STASH_APPLY_PROGRESS_NONE
= 0,
88 /** Loading the stashed data from the object database. */
89 GIT_STASH_APPLY_PROGRESS_LOADING_STASH
,
91 /** The stored index is being analyzed. */
92 GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX
,
94 /** The modified files are being analyzed. */
95 GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED
,
97 /** The untracked and ignored files are being analyzed. */
98 GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED
,
100 /** The untracked files are being written to disk. */
101 GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED
,
103 /** The modified files are being written to disk. */
104 GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED
,
106 /** The stash was applied successfully. */
107 GIT_STASH_APPLY_PROGRESS_DONE
,
108 } git_stash_apply_progress_t
;
111 * Stash application progress notification function.
112 * Return 0 to continue processing, or a negative value to
113 * abort the stash application.
115 typedef int GIT_CALLBACK(git_stash_apply_progress_cb
)(
116 git_stash_apply_progress_t progress
,
120 * Stash application options structure
122 * Initialize with `GIT_STASH_APPLY_OPTIONS_INIT`. Alternatively, you can
123 * use `git_stash_apply_options_init`.
126 typedef struct git_stash_apply_options
{
127 unsigned int version
;
129 /** See `git_stash_apply_flags`, above. */
132 /** Options to use when writing files to the working directory. */
133 git_checkout_options checkout_options
;
135 /** Optional callback to notify the consumer of application progress. */
136 git_stash_apply_progress_cb progress_cb
;
137 void *progress_payload
;
138 } git_stash_apply_options
;
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 }
147 * Initialize git_stash_apply_options structure
149 * Initializes a `git_stash_apply_options` with default values. Equivalent to
150 * creating an instance with `GIT_STASH_APPLY_OPTIONS_INIT`.
152 * @param opts The `git_stash_apply_options` struct to initialize.
153 * @param version The struct version; pass `GIT_STASH_APPLY_OPTIONS_VERSION`.
154 * @return Zero on success; -1 on failure.
156 GIT_EXTERN(int) git_stash_apply_options_init(
157 git_stash_apply_options
*opts
, unsigned int version
);
160 * Apply a single stashed state from the stash list.
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.
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
174 * Note that a minimum checkout strategy of `GIT_CHECKOUT_SAFE` is implied.
176 * @param repo The owning repository.
177 * @param index The position within the stash list. 0 points to the
178 * most recent stashed state.
179 * @param options Optional options to control how stashes are applied.
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
185 GIT_EXTERN(int) git_stash_apply(
186 git_repository
*repo
,
188 const git_stash_apply_options
*options
);
191 * This is a callback function you can provide to iterate over all the
192 * stashed states that will be invoked per entry.
194 * @param index The position within the stash list. 0 points to the
195 * most recent stashed state.
196 * @param message The stash message.
197 * @param stash_id The commit oid of the stashed state.
198 * @param payload Extra parameter to callback function.
199 * @return 0 to continue iterating or non-zero to stop.
201 typedef int GIT_CALLBACK(git_stash_cb
)(
204 const git_oid
*stash_id
,
208 * Loop over all the stashed states and issue a callback for each one.
210 * If the callback returns a non-zero value, this will stop looping.
212 * @param repo Repository where to find the stash.
214 * @param callback Callback to invoke per found stashed state. The most
215 * recent stash state will be enumerated first.
217 * @param payload Extra parameter to callback function.
219 * @return 0 on success, non-zero callback return value, or error code.
221 GIT_EXTERN(int) git_stash_foreach(
222 git_repository
*repo
,
223 git_stash_cb callback
,
227 * Remove a single stashed state from the stash list.
229 * @param repo The owning repository.
231 * @param index The position within the stash list. 0 points to the
232 * most recent stashed state.
234 * @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
235 * index, or error code.
237 GIT_EXTERN(int) git_stash_drop(
238 git_repository
*repo
,
242 * Apply a single stashed state from the stash list and remove it from the list
245 * @param repo The owning repository.
246 * @param index The position within the stash list. 0 points to the
247 * most recent stashed state.
248 * @param options Optional options to control how stashes are applied.
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)
253 GIT_EXTERN(int) git_stash_pop(
254 git_repository
*repo
,
256 const git_stash_apply_options
*options
);