Skip to content

Commit bf8dd3f

Browse files
swisspolEdward Thomson
authored and
Edward Thomson
committed
Added git_stash_apply() and git_stash_pop() APIs
1 parent 9cdd657 commit bf8dd3f

File tree

4 files changed

+651
-4
lines changed

4 files changed

+651
-4
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Microsoft Corporation
4949
Olivier Ramonat
5050
Peter Drahoš
5151
Pierre Habouzit
52+
Pierre-Olivier Latour
5253
Przemyslaw Pawelczyk
5354
Ramsay Jones
5455
Robert G. Jakabosky

include/git2/stash.h

+64-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,47 @@ GIT_EXTERN(int) git_stash_save(
7070
const char *message,
7171
unsigned int flags);
7272

73+
typedef enum {
74+
GIT_APPLY_DEFAULT = 0,
75+
76+
/* Try to reinstate not only the working tree's changes,
77+
* but also the index's ones.
78+
*/
79+
GIT_APPLY_REINSTATE_INDEX = (1 << 0),
80+
} git_apply_flags;
81+
82+
/**
83+
* Apply a single stashed state from the stash list.
84+
*
85+
* If any untracked or ignored file saved in the stash already exist in the
86+
* workdir, the function will return GIT_EEXISTS and both the workdir and index
87+
* will be left untouched.
88+
*
89+
* If local changes in the workdir would be overwritten when applying
90+
* modifications saved in the stash, the function will return GIT_EMERGECONFLICT
91+
* and the index will be left untouched. The workdir files will be left
92+
* unmodified as well but restored untracked or ignored files that were saved
93+
* in the stash will be left around in the workdir.
94+
*
95+
* If passing the GIT_APPLY_REINSTATE_INDEX flag and there would be conflicts
96+
* when reinstating the index, the function will return GIT_EUNMERGED and both
97+
* the workdir and index will be left untouched.
98+
*
99+
* @param repo The owning repository.
100+
*
101+
* @param index The position within the stash list. 0 points to the
102+
* most recent stashed state.
103+
*
104+
* @param flags Flags to control the applying process. (see GIT_APPLY_* above)
105+
*
106+
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
107+
* index, or error code. (see details above)
108+
*/
109+
GIT_EXTERN(int) git_stash_apply(
110+
git_repository *repo,
111+
size_t index,
112+
unsigned int flags);
113+
73114
/**
74115
* This is a callback function you can provide to iterate over all the
75116
* stashed states that will be invoked per entry.
@@ -79,7 +120,7 @@ GIT_EXTERN(int) git_stash_save(
79120
* @param message The stash message.
80121
* @param stash_id The commit oid of the stashed state.
81122
* @param payload Extra parameter to callback function.
82-
* @return 0 to continue iterating or non-zero to stop
123+
* @return 0 to continue iterating or non-zero to stop.
83124
*/
84125
typedef int (*git_stash_cb)(
85126
size_t index,
@@ -99,7 +140,7 @@ typedef int (*git_stash_cb)(
99140
*
100141
* @param payload Extra parameter to callback function.
101142
*
102-
* @return 0 on success, non-zero callback return value, or error code
143+
* @return 0 on success, non-zero callback return value, or error code.
103144
*/
104145
GIT_EXTERN(int) git_stash_foreach(
105146
git_repository *repo,
@@ -114,13 +155,32 @@ GIT_EXTERN(int) git_stash_foreach(
114155
* @param index The position within the stash list. 0 points to the
115156
* most recent stashed state.
116157
*
117-
* @return 0 on success, or error code
158+
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
159+
* index, or error code.
118160
*/
119-
120161
GIT_EXTERN(int) git_stash_drop(
121162
git_repository *repo,
122163
size_t index);
123164

165+
/**
166+
* Apply a single stashed state from the stash list and remove it from the list
167+
* if successful.
168+
*
169+
* @param repo The owning repository.
170+
*
171+
* @param index The position within the stash list. 0 points to the
172+
* most recent stashed state.
173+
*
174+
* @param flags Flags to control the applying process. (see GIT_APPLY_* above)
175+
*
176+
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
177+
* index, or error code. (see git_stash_apply() above for details)
178+
*/
179+
GIT_EXTERN(int) git_stash_pop(
180+
git_repository *repo,
181+
size_t index,
182+
unsigned int flags);
183+
124184
/** @} */
125185
GIT_END_DECL
126186
#endif

0 commit comments

Comments
 (0)