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.worktree; 8 9 10 private static import libgit2_d.buffer; 11 private static import libgit2_d.strarray; 12 private static import libgit2_d.types; 13 14 /** 15 * @file git2/worktrees.h 16 * @brief Git worktree related functions 17 * @defgroup git_commit Git worktree related functions 18 * @ingroup Git 19 * @{ 20 */ 21 extern (C): 22 nothrow @nogc: 23 public: 24 25 /** 26 * List names of linked working trees 27 * 28 * The returned list should be released with `git_strarray_free` 29 * when no longer needed. 30 * 31 * Params: 32 * out_ = pointer to the array of working tree names 33 * repo = the repo to use when listing working trees 34 * 35 * Returns: 0 or an error code 36 */ 37 //GIT_EXTERN 38 int git_worktree_list(libgit2_d.strarray.git_strarray* out_, libgit2_d.types.git_repository* repo); 39 40 /** 41 * Lookup a working tree by its name for a given repository 42 * 43 * Params: 44 * out_ = Output pointer to looked up worktree or `null` 45 * repo = The repository containing worktrees 46 * name = Name of the working tree to look up 47 * 48 * Returns: 0 or an error code 49 */ 50 //GIT_EXTERN 51 int git_worktree_lookup(libgit2_d.types.git_worktree** out_, libgit2_d.types.git_repository* repo, const (char)* name); 52 53 /** 54 * Open a worktree of a given repository 55 * 56 * If a repository is not the main tree but a worktree, this 57 * function will look up the worktree inside the parent 58 * repository and create a new `git_worktree` structure. 59 * 60 * Params: 61 * out_ = Out-pointer for the newly allocated worktree 62 * repo = Repository to look up worktree for 63 */ 64 //GIT_EXTERN 65 int git_worktree_open_from_repository(libgit2_d.types.git_worktree** out_, libgit2_d.types.git_repository* repo); 66 67 /** 68 * Free a previously allocated worktree 69 * 70 * Params: 71 * wt = worktree handle to close. If null nothing occurs. 72 */ 73 //GIT_EXTERN 74 void git_worktree_free(libgit2_d.types.git_worktree* wt); 75 76 /** 77 * Check if worktree is valid 78 * 79 * A valid worktree requires both the git data structures inside 80 * the linked parent repository and the linked working copy to be 81 * present. 82 * 83 * Params: 84 * wt = Worktree to check 85 * 86 * Returns: 0 when worktree is valid, error-code otherwise 87 */ 88 //GIT_EXTERN 89 int git_worktree_validate(const (libgit2_d.types.git_worktree)* wt); 90 91 /** 92 * Worktree add options structure 93 * 94 * Initialize with `GIT_WORKTREE_ADD_OPTIONS_INIT`. Alternatively, you can 95 * use `git_worktree_add_options_init`. 96 */ 97 struct git_worktree_add_options 98 { 99 uint version_; 100 101 /** 102 * lock newly created worktree 103 */ 104 int lock; 105 106 /** 107 * reference to use for the new worktree HEAD 108 */ 109 libgit2_d.types.git_reference* ref_; 110 } 111 112 enum GIT_WORKTREE_ADD_OPTIONS_VERSION = 1; 113 114 pragma(inline, true) 115 pure nothrow @safe @nogc 116 .git_worktree_add_options GIT_WORKTREE_ADD_OPTIONS_INIT() 117 118 do 119 { 120 .git_worktree_add_options OUTPUT = 121 { 122 version_: .GIT_WORKTREE_ADD_OPTIONS_VERSION, 123 lock: 0, 124 ref_: null, 125 }; 126 127 return OUTPUT; 128 } 129 130 /** 131 * Initialize git_worktree_add_options structure 132 * 133 * Initializes a `git_worktree_add_options` with default values. Equivalent to 134 * creating an instance with `GIT_WORKTREE_ADD_OPTIONS_INIT`. 135 * 136 * Params: 137 * opts = The `git_worktree_add_options` struct to initialize. 138 * version = The struct version; pass `GIT_WORKTREE_ADD_OPTIONS_VERSION`. 139 * 140 * Returns: Zero on success; -1 on failure. 141 */ 142 //GIT_EXTERN 143 int git_worktree_add_options_init(.git_worktree_add_options* opts, uint version_); 144 145 /** 146 * Add a new working tree 147 * 148 * Add a new working tree for the repository, that is create the 149 * required data structures inside the repository and check out 150 * the current HEAD at `path` 151 * 152 * Params: 153 * out_ = Output pointer containing new working tree 154 * repo = Repository to create working tree for 155 * name = Name of the working tree 156 * path = Path to create working tree at 157 * opts = Options to modify default behavior. May be null 158 * 159 * Returns: 0 or an error code 160 */ 161 //GIT_EXTERN 162 int git_worktree_add(libgit2_d.types.git_worktree** out_, libgit2_d.types.git_repository* repo, const (char)* name, const (char)* path, const (.git_worktree_add_options)* opts); 163 164 /** 165 * Lock worktree if not already locked 166 * 167 * Lock a worktree, optionally specifying a reason why the linked 168 * working tree is being locked. 169 * 170 * Params: 171 * wt = Worktree to lock 172 * reason = Reason why the working tree is being locked 173 * 174 * Returns: 0 on success, non-zero otherwise 175 */ 176 //GIT_EXTERN 177 int git_worktree_lock(libgit2_d.types.git_worktree* wt, const (char)* reason); 178 179 /** 180 * Unlock a locked worktree 181 * 182 * Params: 183 * wt = Worktree to unlock 184 * 185 * Returns: 0 on success, 1 if worktree was not locked, error-code otherwise 186 */ 187 //GIT_EXTERN 188 int git_worktree_unlock(libgit2_d.types.git_worktree* wt); 189 190 /** 191 * Check if worktree is locked 192 * 193 * A worktree may be locked if the linked working tree is stored 194 * on a portable device which is not available. 195 * 196 * Params: 197 * reason = Buffer to store reason in. If null no reason is stored. 198 * wt = Worktree to check 199 * 200 * Returns: 0 when the working tree not locked, a value greater than zero if it is locked, less than zero if there was an error 201 */ 202 //GIT_EXTERN 203 int git_worktree_is_locked(libgit2_d.buffer.git_buf* reason, const (libgit2_d.types.git_worktree)* wt); 204 205 /** 206 * Retrieve the name of the worktree 207 * 208 * Params: 209 * wt = Worktree to get the name for 210 * 211 * Returns: The worktree's name. The pointer returned is valid for the lifetime of the git_worktree 212 */ 213 //GIT_EXTERN 214 const (char)* git_worktree_name(const (libgit2_d.types.git_worktree)* wt); 215 216 /** 217 * Retrieve the filesystem path for the worktree 218 * 219 * Params: 220 * wt = Worktree to get the path for 221 * 222 * Returns: The worktree's filesystem path. The pointer returned is valid for the lifetime of the git_worktree. 223 */ 224 //GIT_EXTERN 225 const (char)* git_worktree_path(const (libgit2_d.types.git_worktree)* wt); 226 227 /** 228 * Flags which can be passed to git_worktree_prune to alter its 229 * behavior. 230 */ 231 enum git_worktree_prune_t 232 { 233 /** 234 * Prune working tree even if working tree is valid 235 */ 236 GIT_WORKTREE_PRUNE_VALID = 1u << 0, 237 238 /** 239 * Prune working tree even if it is locked 240 */ 241 GIT_WORKTREE_PRUNE_LOCKED = 1u << 1, 242 243 /** 244 * Prune checked out working tree 245 */ 246 GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2, 247 } 248 249 //Declaration name in C language 250 enum 251 { 252 GIT_WORKTREE_PRUNE_VALID = .git_worktree_prune_t.GIT_WORKTREE_PRUNE_VALID, 253 GIT_WORKTREE_PRUNE_LOCKED = .git_worktree_prune_t.GIT_WORKTREE_PRUNE_LOCKED, 254 GIT_WORKTREE_PRUNE_WORKING_TREE = .git_worktree_prune_t.GIT_WORKTREE_PRUNE_WORKING_TREE, 255 } 256 257 /** 258 * Worktree prune options structure 259 * 260 * Initialize with `GIT_WORKTREE_PRUNE_OPTIONS_INIT`. Alternatively, you can 261 * use `git_worktree_prune_options_init`. 262 */ 263 struct git_worktree_prune_options 264 { 265 uint version_; 266 267 uint flags; 268 } 269 270 enum GIT_WORKTREE_PRUNE_OPTIONS_VERSION = 1; 271 272 pragma(inline, true) 273 pure nothrow @safe @nogc 274 .git_worktree_prune_options GIT_WORKTREE_PRUNE_OPTIONS_INIT() 275 276 do 277 { 278 .git_worktree_prune_options OUTPUT = 279 { 280 version_: .GIT_WORKTREE_PRUNE_OPTIONS_VERSION, 281 flags: 0, 282 }; 283 284 return OUTPUT; 285 } 286 287 /** 288 * Initialize git_worktree_prune_options structure 289 * 290 * Initializes a `git_worktree_prune_options` with default values. Equivalent to 291 * creating an instance with `GIT_WORKTREE_PRUNE_OPTIONS_INIT`. 292 * 293 * Params: 294 * opts = The `git_worktree_prune_options` struct to initialize. 295 * version = The struct version; pass `GIT_WORKTREE_PRUNE_OPTIONS_VERSION`. 296 * 297 * Returns: Zero on success; -1 on failure. 298 */ 299 //GIT_EXTERN 300 int git_worktree_prune_options_init(.git_worktree_prune_options* opts, uint version_); 301 302 /** 303 * Is the worktree prunable with the given options? 304 * 305 * A worktree is not prunable in the following scenarios: 306 * 307 * - the worktree is linking to a valid on-disk worktree. The 308 * `valid` member will cause this check to be ignored. 309 * - the worktree is locked. The `locked` flag will cause this 310 * check to be ignored. 311 * 312 * If the worktree is not valid and not locked or if the above 313 * flags have been passed in, this function will return a 314 * positive value. 315 */ 316 //GIT_EXTERN 317 int git_worktree_is_prunable(libgit2_d.types.git_worktree* wt, .git_worktree_prune_options* opts); 318 319 /** 320 * Prune working tree 321 * 322 * Prune the working tree, that is remove the git data 323 * structures on disk. The repository will only be pruned of 324 * `git_worktree_is_prunable` succeeds. 325 * 326 * Params: 327 * wt = Worktree to prune 328 * opts = Specifies which checks to override. See `git_worktree_is_prunable`. May be null 329 * 330 * Returns: 0 or an error code 331 */ 332 //GIT_EXTERN 333 int git_worktree_prune(libgit2_d.types.git_worktree* wt, .git_worktree_prune_options* opts); 334 335 /** @} */