Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae6bb09

Browse files
committed
Added git_stash_apply() and git_stash_pop() APIs
1 parent e06b104 commit ae6bb09

4 files changed

Lines changed: 651 additions & 4 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
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

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,47 @@ GIT_EXTERN(int) git_stash_save(
6161
const char *message,
6262
unsigned int flags);
6363

64+
typedef enum {
65+
GIT_APPLY_DEFAULT = 0,
66+
67+
/* Try to reinstate not only the working tree's changes,
68+
* but also the index's ones.
69+
*/
70+
GIT_APPLY_REINSTATE_INDEX = (1 << 0),
71+
} git_apply_flags;
72+
73+
/**
74+
* Apply a single stashed state from the stash list.
75+
*
76+
* If any untracked or ignored file saved in the stash already exist in the
77+
* workdir, the function will return GIT_EEXISTS and both the workdir and index
78+
* will be left untouched.
79+
*
80+
* If local changes in the workdir would be overwritten when applying
81+
* modifications saved in the stash, the function will return GIT_EMERGECONFLICT
82+
* and the index will be left untouched. The workdir files will be left
83+
* unmodified as well but restored untracked or ignored files that were saved
84+
* in the stash will be left around in the workdir.
85+
*
86+
* If passing the GIT_APPLY_REINSTATE_INDEX flag and there would be conflicts
87+
* when reinstating the index, the function will return GIT_EUNMERGED and both
88+
* the workdir and index will be left untouched.
89+
*
90+
* @param repo The owning repository.
91+
*
92+
* @param index The position within the stash list. 0 points to the
93+
* most recent stashed state.
94+
*
95+
* @param flags Flags to control the applying process. (see GIT_APPLY_* above)
96+
*
97+
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
98+
* index, or error code. (see details above)
99+
*/
100+
GIT_EXTERN(int) git_stash_apply(
101+
git_repository *repo,
102+
size_t index,
103+
unsigned int flags);
104+
64105
/**
65106
* This is a callback function you can provide to iterate over all the
66107
* stashed states that will be invoked per entry.
@@ -70,7 +111,7 @@ GIT_EXTERN(int) git_stash_save(
70111
* @param message The stash message.
71112
* @param stash_id The commit oid of the stashed state.
72113
* @param payload Extra parameter to callback function.
73-
* @return 0 to continue iterating or non-zero to stop
114+
* @return 0 to continue iterating or non-zero to stop.
74115
*/
75116
typedef int (*git_stash_cb)(
76117
size_t index,
@@ -90,7 +131,7 @@ typedef int (*git_stash_cb)(
90131
*
91132
* @param payload Extra parameter to callback function.
92133
*
93-
* @return 0 on success, non-zero callback return value, or error code
134+
* @return 0 on success, non-zero callback return value, or error code.
94135
*/
95136
GIT_EXTERN(int) git_stash_foreach(
96137
git_repository *repo,
@@ -105,13 +146,32 @@ GIT_EXTERN(int) git_stash_foreach(
105146
* @param index The position within the stash list. 0 points to the
106147
* most recent stashed state.
107148
*
108-
* @return 0 on success, or error code
149+
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
150+
* index, or error code.
109151
*/
110-
111152
GIT_EXTERN(int) git_stash_drop(
112153
git_repository *repo,
113154
size_t index);
114155

156+
/**
157+
* Apply a single stashed state from the stash list and remove it from the list
158+
* if successful.
159+
*
160+
* @param repo The owning repository.
161+
*
162+
* @param index The position within the stash list. 0 points to the
163+
* most recent stashed state.
164+
*
165+
* @param flags Flags to control the applying process. (see GIT_APPLY_* above)
166+
*
167+
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
168+
* index, or error code. (see git_stash_apply() above for details)
169+
*/
170+
GIT_EXTERN(int) git_stash_pop(
171+
git_repository *repo,
172+
size_t index,
173+
unsigned int flags);
174+
115175
/** @} */
116176
GIT_END_DECL
117177
#endif

0 commit comments

Comments
 (0)