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