Blame include/git2/worktree.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_git_worktree_h__
Packit Service 20376f
#define INCLUDE_git_worktree_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "buffer.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "strarray.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/worktrees.h
Packit Service 20376f
 * @brief Git worktree related functions
Packit Service 20376f
 * @defgroup git_commit Git worktree related functions
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * List names of linked working trees
Packit Service 20376f
 *
Packit Service 20376f
 * The returned list should be released with `git_strarray_free`
Packit Service 20376f
 * when no longer needed.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to the array of working tree names
Packit Service 20376f
 * @param repo the repo to use when listing working trees
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_list(git_strarray *out, git_repository *repo);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Lookup a working tree by its name for a given repository
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output pointer to looked up worktree or `NULL`
Packit Service 20376f
 * @param repo The repository containing worktrees
Packit Service 20376f
 * @param name Name of the working tree to look up
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_lookup(git_worktree **out, git_repository *repo, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Open a worktree of a given repository
Packit Service 20376f
 *
Packit Service 20376f
 * If a repository is not the main tree but a worktree, this
Packit Service 20376f
 * function will look up the worktree inside the parent
Packit Service 20376f
 * repository and create a new `git_worktree` structure.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Out-pointer for the newly allocated worktree
Packit Service 20376f
 * @param repo Repository to look up worktree for
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_open_from_repository(git_worktree **out, git_repository *repo);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free a previously allocated worktree
Packit Service 20376f
 *
Packit Service 20376f
 * @param wt worktree handle to close. If NULL nothing occurs.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_worktree_free(git_worktree *wt);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if worktree is valid
Packit Service 20376f
 *
Packit Service 20376f
 * A valid worktree requires both the git data structures inside
Packit Service 20376f
 * the linked parent repository and the linked working copy to be
Packit Service 20376f
 * present.
Packit Service 20376f
 *
Packit Service 20376f
 * @param wt Worktree to check
Packit Service 20376f
 * @return 0 when worktree is valid, error-code otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_validate(const git_worktree *wt);
Packit Service 20376f
Packit Service 20376f
typedef struct git_worktree_add_options {
Packit Service 20376f
	unsigned int version;
Packit Service 20376f
Packit Service 20376f
	int lock; /**< lock newly created worktree */
Packit Service 20376f
} git_worktree_add_options;
Packit Service 20376f
Packit Service 20376f
#define GIT_WORKTREE_ADD_OPTIONS_VERSION 1
Packit Service 20376f
#define GIT_WORKTREE_ADD_OPTIONS_INIT {GIT_WORKTREE_ADD_OPTIONS_VERSION,0}
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initializes a `git_worktree_add_options` with default vaules.
Packit Service 20376f
 * Equivalent to creating an instance with
Packit Service 20376f
 * GIT_WORKTREE_ADD_OPTIONS_INIT.
Packit Service 20376f
 *
Packit Service 20376f
 * @param opts the struct to initialize
Packit Service 20376f
 * @param version Verison of struct; pass `GIT_WORKTREE_ADD_OPTIONS_VERSION`
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
int git_worktree_add_init_options(git_worktree_add_options *opts,
Packit Service 20376f
	unsigned int version);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add a new working tree
Packit Service 20376f
 *
Packit Service 20376f
 * Add a new working tree for the repository, that is create the
Packit Service 20376f
 * required data structures inside the repository and check out
Packit Service 20376f
 * the current HEAD at `path`
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output pointer containing new working tree
Packit Service 20376f
 * @param repo Repository to create working tree for
Packit Service 20376f
 * @param name Name of the working tree
Packit Service 20376f
 * @param path Path to create working tree at
Packit Service 20376f
 * @param opts Options to modify default behavior. May be NULL
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_add(git_worktree **out, git_repository *repo,
Packit Service 20376f
	const char *name, const char *path,
Packit Service 20376f
	const git_worktree_add_options *opts);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Lock worktree if not already locked
Packit Service 20376f
 *
Packit Service 20376f
 * Lock a worktree, optionally specifying a reason why the linked
Packit Service 20376f
 * working tree is being locked.
Packit Service 20376f
 *
Packit Service 20376f
 * @param wt Worktree to lock
Packit Service 20376f
 * @param reason Reason why the working tree is being locked
Packit Service 20376f
 * @return 0 on success, non-zero otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_lock(git_worktree *wt, char *reason);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Unlock a locked worktree
Packit Service 20376f
 *
Packit Service 20376f
 * @param wt Worktree to unlock
Packit Service 20376f
 * @return 0 on success, 1 if worktree was not locked, error-code
Packit Service 20376f
 *  otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_unlock(git_worktree *wt);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if worktree is locked
Packit Service 20376f
 *
Packit Service 20376f
 * A worktree may be locked if the linked working tree is stored
Packit Service 20376f
 * on a portable device which is not available.
Packit Service 20376f
 *
Packit Service 20376f
 * @param reason Buffer to store reason in. If NULL no reason is stored.
Packit Service 20376f
 * @param wt Worktree to check
Packit Service 20376f
 * @return 0 when the working tree not locked, a value greater
Packit Service 20376f
 *  than zero if it is locked, less than zero if there was an
Packit Service 20376f
 *  error
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_is_locked(git_buf *reason, const git_worktree *wt);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Flags which can be passed to git_worktree_prune to alter its
Packit Service 20376f
 * behavior.
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/* Prune working tree even if working tree is valid */
Packit Service 20376f
	GIT_WORKTREE_PRUNE_VALID = 1u << 0,
Packit Service 20376f
	/* Prune working tree even if it is locked */
Packit Service 20376f
	GIT_WORKTREE_PRUNE_LOCKED = 1u << 1,
Packit Service 20376f
	/* Prune checked out working tree */
Packit Service 20376f
	GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2,
Packit Service 20376f
} git_worktree_prune_t;
Packit Service 20376f
Packit Service 20376f
typedef struct git_worktree_prune_options {
Packit Service 20376f
	unsigned int version;
Packit Service 20376f
Packit Service 20376f
	uint32_t flags;
Packit Service 20376f
} git_worktree_prune_options;
Packit Service 20376f
Packit Service 20376f
#define GIT_WORKTREE_PRUNE_OPTIONS_VERSION 1
Packit Service 20376f
#define GIT_WORKTREE_PRUNE_OPTIONS_INIT {GIT_WORKTREE_PRUNE_OPTIONS_VERSION,0}
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initializes a `git_worktree_prune_options` with default vaules.
Packit Service 20376f
 * Equivalent to creating an instance with
Packit Service 20376f
 * GIT_WORKTREE_PRUNE_OPTIONS_INIT.
Packit Service 20376f
 *
Packit Service 20376f
 * @param opts the struct to initialize
Packit Service 20376f
 * @param version Verison of struct; pass `GIT_WORKTREE_PRUNE_OPTIONS_VERSION`
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_prune_init_options(
Packit Service 20376f
	git_worktree_prune_options *opts,
Packit Service 20376f
	unsigned int version);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Is the worktree prunable with the given options?
Packit Service 20376f
 *
Packit Service 20376f
 * A worktree is not prunable in the following scenarios:
Packit Service 20376f
 *
Packit Service 20376f
 * - the worktree is linking to a valid on-disk worktree. The
Packit Service 20376f
 *   `valid` member will cause this check to be ignored.
Packit Service 20376f
 * - the worktree is locked. The `locked` flag will cause this
Packit Service 20376f
 *   check to be ignored.
Packit Service 20376f
 *
Packit Service 20376f
 * If the worktree is not valid and not locked or if the above
Packit Service 20376f
 * flags have been passed in, this function will return a
Packit Service 20376f
 * positive value.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_is_prunable(git_worktree *wt,
Packit Service 20376f
	git_worktree_prune_options *opts);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Prune working tree
Packit Service 20376f
 *
Packit Service 20376f
 * Prune the working tree, that is remove the git data
Packit Service 20376f
 * structures on disk. The repository will only be pruned of
Packit Service 20376f
 * `git_worktree_is_prunable` succeeds.
Packit Service 20376f
 *
Packit Service 20376f
 * @param wt Worktree to prune
Packit Service 20376f
 * @param opts Specifies which checks to override. See
Packit Service 20376f
 *        `git_worktree_is_prunable`. May be NULL
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_worktree_prune(git_worktree *wt,
Packit Service 20376f
	git_worktree_prune_options *opts);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif