]> git.proxmox.com Git - libgit2.git/blame - include/git2/stash.h
stash: ensure a reflog has entries
[libgit2.git] / include / git2 / stash.h
CommitLineData
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"
12
13/**
14 * @file git2/stash.h
15 * @brief Git stash management routines
16 * @ingroup Git
17 * @{
18 */
19GIT_BEGIN_DECL
20
a295bd2d
CMN
21/**
22 * Stash flags
23 */
1d8ec670 24typedef enum {
a295bd2d
CMN
25 /**
26 * No option, default
27 */
590fb68b 28 GIT_STASH_DEFAULT = 0,
29
a295bd2d
CMN
30 /**
31 * All changes already added to the index are left intact in
32 * the working directory
590fb68b 33 */
34 GIT_STASH_KEEP_INDEX = (1 << 0),
35
a295bd2d
CMN
36 /**
37 * All untracked files are also stashed and then cleaned up
38 * from the working directory
590fb68b 39 */
40 GIT_STASH_INCLUDE_UNTRACKED = (1 << 1),
41
a295bd2d
CMN
42 /**
43 * All ignored files are also stashed and then cleaned up from
44 * the working directory
590fb68b 45 */
46 GIT_STASH_INCLUDE_IGNORED = (1 << 2),
1d8ec670 47} git_stash_flags;
590fb68b 48
49/**
50 * Save the local modifications to a new stash.
51 *
52 * @param out Object id of the commit containing the stashed state.
53 * This commit is also the target of the direct reference refs/stash.
54 *
55 * @param repo The owning repository.
56 *
57 * @param stasher The identity of the person performing the stashing.
58 *
59 * @param message Optional description along with the stashed state.
60 *
1d8ec670 61 * @param flags Flags to control the stashing process. (see GIT_STASH_* above)
590fb68b 62 *
63 * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash,
64 * or error code.
65 */
590fb68b 66GIT_EXTERN(int) git_stash_save(
67 git_oid *out,
68 git_repository *repo,
2274993b 69 const git_signature *stasher,
590fb68b 70 const char *message,
1d8ec670 71 unsigned int flags);
590fb68b 72
bf8dd3f5
POL
73typedef 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 */
109GIT_EXTERN(int) git_stash_apply(
110 git_repository *repo,
111 size_t index,
112 unsigned int flags);
113
23388413 114/**
373cf6a9
RB
115 * This is a callback function you can provide to iterate over all the
116 * stashed states that will be invoked per entry.
23388413 117 *
118 * @param index The position within the stash list. 0 points to the
373cf6a9 119 * most recent stashed state.
23388413 120 * @param message The stash message.
1d8ec670 121 * @param stash_id The commit oid of the stashed state.
23388413 122 * @param payload Extra parameter to callback function.
bf8dd3f5 123 * @return 0 to continue iterating or non-zero to stop.
23388413 124 */
1d8ec670 125typedef int (*git_stash_cb)(
23388413 126 size_t index,
127 const char* message,
1d8ec670 128 const git_oid *stash_id,
23388413 129 void *payload);
130
131/**
132 * Loop over all the stashed states and issue a callback for each one.
133 *
134 * If the callback returns a non-zero value, this will stop looping.
135 *
136 * @param repo Repository where to find the stash.
137 *
373cf6a9
RB
138 * @param callback Callback to invoke per found stashed state. The most
139 * recent stash state will be enumerated first.
23388413 140 *
141 * @param payload Extra parameter to callback function.
142 *
bf8dd3f5 143 * @return 0 on success, non-zero callback return value, or error code.
23388413 144 */
145GIT_EXTERN(int) git_stash_foreach(
146 git_repository *repo,
1d8ec670 147 git_stash_cb callback,
23388413 148 void *payload);
149
e4c64cf2 150/**
151 * Remove a single stashed state from the stash list.
152 *
153 * @param repo The owning repository.
154 *
155 * @param index The position within the stash list. 0 points to the
156 * most recent stashed state.
157 *
bf8dd3f5
POL
158 * @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
159 * index, or error code.
e4c64cf2 160 */
e4c64cf2 161GIT_EXTERN(int) git_stash_drop(
162 git_repository *repo,
163 size_t index);
164
bf8dd3f5
POL
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*/
179GIT_EXTERN(int) git_stash_pop(
180 git_repository *repo,
181 size_t index,
182 unsigned int flags);
183
590fb68b 184/** @} */
185GIT_END_DECL
186#endif