Blame include/git2/rebase.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_rebase_h__
Packit Service 20376f
#define INCLUDE_git_rebase_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "oid.h"
Packit Service 20376f
#include "annotated_commit.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/rebase.h
Packit Service 20376f
 * @brief Git rebase routines
Packit Service 20376f
 * @defgroup git_rebase Git merge 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
 * Rebase options
Packit Service 20376f
 *
Packit Service 20376f
 * Use to tell the rebase machinery how to operate.
Packit Service 20376f
 */
Packit Service 20376f
typedef struct {
Packit Service 20376f
	unsigned int version;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Used by `git_rebase_init`, this will instruct other clients working
Packit Service 20376f
	 * on this rebase that you want a quiet rebase experience, which they
Packit Service 20376f
	 * may choose to provide in an application-specific manner.  This has no
Packit Service 20376f
	 * effect upon libgit2 directly, but is provided for interoperability
Packit Service 20376f
	 * between Git tools.
Packit Service 20376f
	 */
Packit Service 20376f
	int quiet;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Used by `git_rebase_init`, this will begin an in-memory rebase,
Packit Service 20376f
	 * which will allow callers to step through the rebase operations and
Packit Service 20376f
	 * commit the rebased changes, but will not rewind HEAD or update the
Packit Service 20376f
	 * repository to be in a rebasing state.  This will not interfere with
Packit Service 20376f
	 * the working directory (if there is one).
Packit Service 20376f
	 */
Packit Service 20376f
	int inmemory;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Used by `git_rebase_finish`, this is the name of the notes reference
Packit Service 20376f
	 * used to rewrite notes for rebased commits when finishing the rebase;
Packit Service 20376f
	 * if NULL, the contents of the configuration option `notes.rewriteRef`
Packit Service 20376f
	 * is examined, unless the configuration option `notes.rewrite.rebase`
Packit Service 20376f
	 * is set to false.  If `notes.rewriteRef` is also NULL, notes will
Packit Service 20376f
	 * not be rewritten.
Packit Service 20376f
	 */
Packit Service 20376f
	const char *rewrite_notes_ref;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Options to control how trees are merged during `git_rebase_next`.
Packit Service 20376f
	 */
Packit Service 20376f
	git_merge_options merge_options;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Options to control how files are written during `git_rebase_init`,
Packit Service 20376f
	 * `git_rebase_next` and `git_rebase_abort`.  Note that a minimum
Packit Service 20376f
	 * strategy of `GIT_CHECKOUT_SAFE` is defaulted in `init` and `next`,
Packit Service 20376f
	 * and a minimum strategy of `GIT_CHECKOUT_FORCE` is defaulted in
Packit Service 20376f
	 * `abort` to match git semantics.
Packit Service 20376f
	 */
Packit Service 20376f
	git_checkout_options checkout_options;
Packit Service 20376f
} git_rebase_options;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Type of rebase operation in-progress after calling `git_rebase_next`.
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/**
Packit Service 20376f
	 * The given commit is to be cherry-picked.  The client should commit
Packit Service 20376f
	 * the changes and continue if there are no conflicts.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_REBASE_OPERATION_PICK = 0,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * The given commit is to be cherry-picked, but the client should prompt
Packit Service 20376f
	 * the user to provide an updated commit message.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_REBASE_OPERATION_REWORD,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * The given commit is to be cherry-picked, but the client should stop
Packit Service 20376f
	 * to allow the user to edit the changes before committing them.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_REBASE_OPERATION_EDIT,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * The given commit is to be squashed into the previous commit.  The
Packit Service 20376f
	 * commit message will be merged with the previous message.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_REBASE_OPERATION_SQUASH,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * The given commit is to be squashed into the previous commit.  The
Packit Service 20376f
	 * commit message from this commit will be discarded.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_REBASE_OPERATION_FIXUP,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * No commit will be cherry-picked.  The client should run the given
Packit Service 20376f
	 * command and (if successful) continue.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_REBASE_OPERATION_EXEC,
Packit Service 20376f
} git_rebase_operation_t;
Packit Service 20376f
Packit Service 20376f
#define GIT_REBASE_OPTIONS_VERSION 1
Packit Service 20376f
#define GIT_REBASE_OPTIONS_INIT \
Packit Service 20376f
	{ GIT_REBASE_OPTIONS_VERSION, 0, 0, NULL, GIT_MERGE_OPTIONS_INIT, \
Packit Service 20376f
	  GIT_CHECKOUT_OPTIONS_INIT}
Packit Service 20376f
Packit Service 20376f
/** Indicates that a rebase operation is not (yet) in progress. */
Packit Service 20376f
#define GIT_REBASE_NO_OPERATION SIZE_MAX
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * A rebase operation
Packit Service 20376f
 *
Packit Service 20376f
 * Describes a single instruction/operation to be performed during the
Packit Service 20376f
 * rebase.
Packit Service 20376f
 */
Packit Service 20376f
typedef struct {
Packit Service 20376f
	/** The type of rebase operation. */
Packit Service 20376f
	git_rebase_operation_t type;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * The commit ID being cherry-picked.  This will be populated for
Packit Service 20376f
	 * all operations except those of type `GIT_REBASE_OPERATION_EXEC`.
Packit Service 20376f
	 */
Packit Service 20376f
	const git_oid id;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * The executable the user has requested be run.  This will only
Packit Service 20376f
	 * be populated for operations of type `GIT_REBASE_OPERATION_EXEC`.
Packit Service 20376f
	 */
Packit Service 20376f
	const char *exec;
Packit Service 20376f
} git_rebase_operation;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initializes a `git_rebase_options` with default values. Equivalent to
Packit Service 20376f
 * creating an instance with GIT_REBASE_OPTIONS_INIT.
Packit Service 20376f
 *
Packit Service 20376f
 * @param opts the `git_rebase_options` instance to initialize.
Packit Service 20376f
 * @param version the version of the struct; you should pass
Packit Service 20376f
 *        `GIT_REBASE_OPTIONS_VERSION` here.
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_rebase_init_options(
Packit Service 20376f
	git_rebase_options *opts,
Packit Service 20376f
	unsigned int version);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initializes a rebase operation to rebase the changes in `branch`
Packit Service 20376f
 * relative to `upstream` onto another branch.  To begin the rebase
Packit Service 20376f
 * process, call `git_rebase_next`.  When you have finished with this
Packit Service 20376f
 * object, call `git_rebase_free`.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to store the rebase object
Packit Service 20376f
 * @param repo The repository to perform the rebase
Packit Service 20376f
 * @param branch The terminal commit to rebase, or NULL to rebase the
Packit Service 20376f
 *               current branch
Packit Service 20376f
 * @param upstream The commit to begin rebasing from, or NULL to rebase all
Packit Service 20376f
 *                 reachable commits
Packit Service 20376f
 * @param onto The branch to rebase onto, or NULL to rebase onto the given
Packit Service 20376f
 *             upstream
Packit Service 20376f
 * @param opts Options to specify how rebase is performed, or NULL
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_rebase_init(
Packit Service 20376f
	git_rebase **out,
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const git_annotated_commit *branch,
Packit Service 20376f
	const git_annotated_commit *upstream,
Packit Service 20376f
	const git_annotated_commit *onto,
Packit Service 20376f
	const git_rebase_options *opts);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Opens an existing rebase that was previously started by either an
Packit Service 20376f
 * invocation of `git_rebase_init` or by another client.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to store the rebase object
Packit Service 20376f
 * @param repo The repository that has a rebase in-progress
Packit Service 20376f
 * @param opts Options to specify how rebase is performed
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_rebase_open(
Packit Service 20376f
	git_rebase **out,
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const git_rebase_options *opts);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Gets the count of rebase operations that are to be applied.
Packit Service 20376f
 *
Packit Service 20376f
 * @param rebase The in-progress rebase
Packit Service 20376f
 * @return The number of rebase operations in total
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(size_t) git_rebase_operation_entrycount(git_rebase *rebase);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Gets the index of the rebase operation that is currently being applied.
Packit Service 20376f
 * If the first operation has not yet been applied (because you have
Packit Service 20376f
 * called `init` but not yet `next`) then this returns
Packit Service 20376f
 * `GIT_REBASE_NO_OPERATION`.
Packit Service 20376f
 *
Packit Service 20376f
 * @param rebase The in-progress rebase
Packit Service 20376f
 * @return The index of the rebase operation currently being applied.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(size_t) git_rebase_operation_current(git_rebase *rebase);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Gets the rebase operation specified by the given index.
Packit Service 20376f
 *
Packit Service 20376f
 * @param rebase The in-progress rebase
Packit Service 20376f
 * @param idx The index of the rebase operation to retrieve
Packit Service 20376f
 * @return The rebase operation or NULL if `idx` was out of bounds
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_rebase_operation *) git_rebase_operation_byindex(
Packit Service 20376f
	git_rebase *rebase,
Packit Service 20376f
	size_t idx);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Performs the next rebase operation and returns the information about it.
Packit Service 20376f
 * If the operation is one that applies a patch (which is any operation except
Packit Service 20376f
 * GIT_REBASE_OPERATION_EXEC) then the patch will be applied and the index and
Packit Service 20376f
 * working directory will be updated with the changes.  If there are conflicts,
Packit Service 20376f
 * you will need to address those before committing the changes.
Packit Service 20376f
 *
Packit Service 20376f
 * @param operation Pointer to store the rebase operation that is to be performed next
Packit Service 20376f
 * @param rebase The rebase in progress
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_rebase_next(
Packit Service 20376f
	git_rebase_operation **operation,
Packit Service 20376f
	git_rebase *rebase);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Gets the index produced by the last operation, which is the result
Packit Service 20376f
 * of `git_rebase_next` and which will be committed by the next
Packit Service 20376f
 * invocation of `git_rebase_commit`.  This is useful for resolving
Packit Service 20376f
 * conflicts in an in-memory rebase before committing them.  You must
Packit Service 20376f
 * call `git_index_free` when you are finished with this.
Packit Service 20376f
 *
Packit Service 20376f
 * This is only applicable for in-memory rebases; for rebases within
Packit Service 20376f
 * a working directory, the changes were applied to the repository's
Packit Service 20376f
 * index.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_rebase_inmemory_index(
Packit Service 20376f
	git_index **index,
Packit Service 20376f
	git_rebase *rebase);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Commits the current patch.  You must have resolved any conflicts that
Packit Service 20376f
 * were introduced during the patch application from the `git_rebase_next`
Packit Service 20376f
 * invocation.
Packit Service 20376f
 *
Packit Service 20376f
 * @param id Pointer in which to store the OID of the newly created commit
Packit Service 20376f
 * @param rebase The rebase that is in-progress
Packit Service 20376f
 * @param author The author of the updated commit, or NULL to keep the
Packit Service 20376f
 *        author from the original commit
Packit Service 20376f
 * @param committer The committer of the rebase
Packit Service 20376f
 * @param message_encoding The encoding for the message in the commit,
Packit Service 20376f
 *        represented with a standard encoding name.  If message is NULL,
Packit Service 20376f
 *        this should also be NULL, and the encoding from the original
Packit Service 20376f
 *        commit will be maintained.  If message is specified, this may be
Packit Service 20376f
 *        NULL to indicate that "UTF-8" is to be used.
Packit Service 20376f
 * @param message The message for this commit, or NULL to use the message
Packit Service 20376f
 *        from the original commit.
Packit Service 20376f
 * @return Zero on success, GIT_EUNMERGED if there are unmerged changes in
Packit Service 20376f
 *        the index, GIT_EAPPLIED if the current commit has already
Packit Service 20376f
 *        been applied to the upstream and there is nothing to commit,
Packit Service 20376f
 *        -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_rebase_commit(
Packit Service 20376f
	git_oid *id,
Packit Service 20376f
	git_rebase *rebase,
Packit Service 20376f
	const git_signature *author,
Packit Service 20376f
	const git_signature *committer,
Packit Service 20376f
	const char *message_encoding,
Packit Service 20376f
	const char *message);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Aborts a rebase that is currently in progress, resetting the repository
Packit Service 20376f
 * and working directory to their state before rebase began.
Packit Service 20376f
 *
Packit Service 20376f
 * @param rebase The rebase that is in-progress
Packit Service 20376f
 * @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress,
Packit Service 20376f
 *         -1 on other errors.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_rebase_abort(git_rebase *rebase);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Finishes a rebase that is currently in progress once all patches have
Packit Service 20376f
 * been applied.
Packit Service 20376f
 *
Packit Service 20376f
 * @param rebase The rebase that is in-progress
Packit Service 20376f
 * @param signature The identity that is finishing the rebase (optional)
Packit Service 20376f
 * @return Zero on success; -1 on error
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_rebase_finish(
Packit Service 20376f
	git_rebase *rebase,
Packit Service 20376f
	const git_signature *signature);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Frees the `git_rebase` object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param rebase The rebase object
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_rebase_free(git_rebase *rebase);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif