|
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_stash_h__
|
|
Packit Service |
20376f |
#define INCLUDE_git_stash_h__
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#include "common.h"
|
|
Packit Service |
20376f |
#include "types.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* @file git2/stash.h
|
|
Packit Service |
20376f |
* @brief Git stash management routines
|
|
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 |
* Stash flags
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
typedef enum {
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* No option, default
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_STASH_DEFAULT = 0,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* All changes already added to the index are left intact in
|
|
Packit Service |
20376f |
* the working directory
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_STASH_KEEP_INDEX = (1 << 0),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* All untracked files are also stashed and then cleaned up
|
|
Packit Service |
20376f |
* from the working directory
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_STASH_INCLUDE_UNTRACKED = (1 << 1),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* All ignored files are also stashed and then cleaned up from
|
|
Packit Service |
20376f |
* the working directory
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_STASH_INCLUDE_IGNORED = (1 << 2),
|
|
Packit Service |
20376f |
} git_stash_flags;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Save the local modifications to a new stash.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param out Object id of the commit containing the stashed state.
|
|
Packit Service |
20376f |
* This commit is also the target of the direct reference refs/stash.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param repo The owning repository.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param stasher The identity of the person performing the stashing.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param message Optional description along with the stashed state.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param flags Flags to control the stashing process. (see GIT_STASH_* above)
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @return 0 on success, GIT_ENOTFOUND where there's nothing to stash,
|
|
Packit Service |
20376f |
* or error code.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_EXTERN(int) git_stash_save(
|
|
Packit Service |
20376f |
git_oid *out,
|
|
Packit Service |
20376f |
git_repository *repo,
|
|
Packit Service |
20376f |
const git_signature *stasher,
|
|
Packit Service |
20376f |
const char *message,
|
|
Packit Service |
20376f |
uint32_t flags);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** Stash application flags. */
|
|
Packit Service |
20376f |
typedef enum {
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_DEFAULT = 0,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Try to reinstate not only the working tree's changes,
|
|
Packit Service |
20376f |
* but also the index's changes.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0),
|
|
Packit Service |
20376f |
} git_stash_apply_flags;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
typedef enum {
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_PROGRESS_NONE = 0,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** Loading the stashed data from the object database. */
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_PROGRESS_LOADING_STASH,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** The stored index is being analyzed. */
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** The modified files are being analyzed. */
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** The untracked and ignored files are being analyzed. */
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** The untracked files are being written to disk. */
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** The modified files are being written to disk. */
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** The stash was applied successfully. */
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_PROGRESS_DONE,
|
|
Packit Service |
20376f |
} git_stash_apply_progress_t;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Stash application progress notification function.
|
|
Packit Service |
20376f |
* Return 0 to continue processing, or a negative value to
|
|
Packit Service |
20376f |
* abort the stash application.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
typedef int (*git_stash_apply_progress_cb)(
|
|
Packit Service |
20376f |
git_stash_apply_progress_t progress,
|
|
Packit Service |
20376f |
void *payload);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** Stash application options structure.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* Initialize with the `GIT_STASH_APPLY_OPTIONS_INIT` macro to set
|
|
Packit Service |
20376f |
* sensible defaults; for example:
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
typedef struct git_stash_apply_options {
|
|
Packit Service |
20376f |
unsigned int version;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** See `git_stash_apply_flags_t`, above. */
|
|
Packit Service |
20376f |
git_stash_apply_flags flags;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** Options to use when writing files to the working directory. */
|
|
Packit Service |
20376f |
git_checkout_options checkout_options;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** Optional callback to notify the consumer of application progress. */
|
|
Packit Service |
20376f |
git_stash_apply_progress_cb progress_cb;
|
|
Packit Service |
20376f |
void *progress_payload;
|
|
Packit Service |
20376f |
} git_stash_apply_options;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#define GIT_STASH_APPLY_OPTIONS_VERSION 1
|
|
Packit Service |
20376f |
#define GIT_STASH_APPLY_OPTIONS_INIT { \
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_OPTIONS_VERSION, \
|
|
Packit Service |
20376f |
GIT_STASH_APPLY_DEFAULT, \
|
|
Packit Service |
20376f |
GIT_CHECKOUT_OPTIONS_INIT }
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Initializes a `git_stash_apply_options` with default values. Equivalent to
|
|
Packit Service |
20376f |
* creating an instance with GIT_STASH_APPLY_OPTIONS_INIT.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param opts the `git_stash_apply_options` instance to initialize.
|
|
Packit Service |
20376f |
* @param version the version of the struct; you should pass
|
|
Packit Service |
20376f |
* `GIT_STASH_APPLY_OPTIONS_INIT` here.
|
|
Packit Service |
20376f |
* @return Zero on success; -1 on failure.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_EXTERN(int) git_stash_apply_init_options(
|
|
Packit Service |
20376f |
git_stash_apply_options *opts, unsigned int version);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Apply a single stashed state from the stash list.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* If local changes in the working directory conflict with changes in the
|
|
Packit Service |
20376f |
* stash then GIT_EMERGECONFLICT will be returned. In this case, the index
|
|
Packit Service |
20376f |
* will always remain unmodified and all files in the working directory will
|
|
Packit Service |
20376f |
* remain unmodified. However, if you are restoring untracked files or
|
|
Packit Service |
20376f |
* ignored files and there is a conflict when applying the modified files,
|
|
Packit Service |
20376f |
* then those files will remain in the working directory.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* If passing the GIT_STASH_APPLY_REINSTATE_INDEX flag and there would be
|
|
Packit Service |
20376f |
* conflicts when reinstating the index, the function will return
|
|
Packit Service |
20376f |
* GIT_EMERGECONFLICT and both the working directory and index will be left
|
|
Packit Service |
20376f |
* unmodified.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* Note that a minimum checkout strategy of `GIT_CHECKOUT_SAFE` is implied.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param repo The owning repository.
|
|
Packit Service |
20376f |
* @param index The position within the stash list. 0 points to the
|
|
Packit Service |
20376f |
* most recent stashed state.
|
|
Packit Service |
20376f |
* @param options Optional options to control how stashes are applied.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the
|
|
Packit Service |
20376f |
* given index, GIT_EMERGECONFLICT if changes exist in the working
|
|
Packit Service |
20376f |
* directory, or an error code
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_EXTERN(int) git_stash_apply(
|
|
Packit Service |
20376f |
git_repository *repo,
|
|
Packit Service |
20376f |
size_t index,
|
|
Packit Service |
20376f |
const git_stash_apply_options *options);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* This is a callback function you can provide to iterate over all the
|
|
Packit Service |
20376f |
* stashed states that will be invoked per entry.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param index The position within the stash list. 0 points to the
|
|
Packit Service |
20376f |
* most recent stashed state.
|
|
Packit Service |
20376f |
* @param message The stash message.
|
|
Packit Service |
20376f |
* @param stash_id The commit oid of the stashed state.
|
|
Packit Service |
20376f |
* @param payload Extra parameter to callback function.
|
|
Packit Service |
20376f |
* @return 0 to continue iterating or non-zero to stop.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
typedef int (*git_stash_cb)(
|
|
Packit Service |
20376f |
size_t index,
|
|
Packit Service |
20376f |
const char* message,
|
|
Packit Service |
20376f |
const git_oid *stash_id,
|
|
Packit Service |
20376f |
void *payload);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Loop over all the stashed states and issue a callback for each one.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* If the callback returns a non-zero value, this will stop looping.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param repo Repository where to find the stash.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param callback Callback to invoke per found stashed state. The most
|
|
Packit Service |
20376f |
* recent stash state will be enumerated first.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param payload Extra parameter to callback function.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @return 0 on success, non-zero callback return value, or error code.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_EXTERN(int) git_stash_foreach(
|
|
Packit Service |
20376f |
git_repository *repo,
|
|
Packit Service |
20376f |
git_stash_cb callback,
|
|
Packit Service |
20376f |
void *payload);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Remove a single stashed state from the stash list.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param repo The owning repository.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param index The position within the stash list. 0 points to the
|
|
Packit Service |
20376f |
* most recent stashed state.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
|
|
Packit Service |
20376f |
* index, or error code.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_EXTERN(int) git_stash_drop(
|
|
Packit Service |
20376f |
git_repository *repo,
|
|
Packit Service |
20376f |
size_t index);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Apply a single stashed state from the stash list and remove it from the list
|
|
Packit Service |
20376f |
* if successful.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param repo The owning repository.
|
|
Packit Service |
20376f |
* @param index The position within the stash list. 0 points to the
|
|
Packit Service |
20376f |
* most recent stashed state.
|
|
Packit Service |
20376f |
* @param options Optional options to control how stashes are applied.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @return 0 on success, GIT_ENOTFOUND if there's no stashed state for the given
|
|
Packit Service |
20376f |
* index, or error code. (see git_stash_apply() above for details)
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_EXTERN(int) git_stash_pop(
|
|
Packit Service |
20376f |
git_repository *repo,
|
|
Packit Service |
20376f |
size_t index,
|
|
Packit Service |
20376f |
const git_stash_apply_options *options);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** @} */
|
|
Packit Service |
20376f |
GIT_END_DECL
|
|
Packit Service |
20376f |
#endif
|