Commit b07db1eb by Edward Thomson

Merge pull request #2482 from libgit2/ed/rebase

Rebase (merge)
parents 9e44289c 67917281
......@@ -90,3 +90,17 @@ v0.21 + 1
* Introduce git_merge_bases_many() to expose all merge bases between
multiple commits.
* git_merge_head is now git_annotated_commit, to better reflect its usage
for multiple functions (including rebase)
* Introduce rebase functionality (using the merge algorithm only).
Introduce git_rebase_init() to begin a new rebase session,
git_rebase_open() to open an in-progress rebase session,
git_rebase_commit() to commit the current rebase operation,
git_rebase_next() to apply the next rebase operation,
git_rebase_abort() to abort an in-progress rebase and git_rebase_finish()
to complete a rebase operation.
* Introduce git_note_author() and git_note_committer() to get the author
and committer information on a git_note, respectively.
......@@ -8,6 +8,7 @@
#ifndef INCLUDE_git_git_h__
#define INCLUDE_git_git_h__
#include "git2/annotated_commit.h"
#include "git2/attr.h"
#include "git2/blob.h"
#include "git2/blame.h"
......@@ -39,6 +40,7 @@
#include "git2/patch.h"
#include "git2/pathspec.h"
#include "git2/push.h"
#include "git2/rebase.h"
#include "git2/refdb.h"
#include "git2/reflog.h"
#include "git2/refs.h"
......
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_annotated_commit_h__
#define INCLUDE_git_annotated_commit_h__
#include "common.h"
#include "repository.h"
#include "types.h"
/**
* @file git2/annotated_commit.h
* @brief Git annotated commit routines
* @defgroup git_annotated_commit Git annotated commit routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Creates a `git_annotated_commit` from the given reference.
* The resulting git_annotated_commit must be freed with
* `git_annotated_commit_free`.
*
* @param out pointer to store the git_annotated_commit result in
* @param repo repository that contains the given reference
* @param ref reference to use to lookup the git_annotated_commit
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_annotated_commit_from_ref(
git_annotated_commit **out,
git_repository *repo,
const git_reference *ref);
/**
* Creates a `git_annotated_commit` from the given fetch head data.
* The resulting git_annotated_commit must be freed with
* `git_annotated_commit_free`.
*
* @param out pointer to store the git_annotated_commit result in
* @param repo repository that contains the given commit
* @param branch_name name of the (remote) branch
* @param remote_url url of the remote
* @param oid the commit object id of the remote branch
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_annotated_commit_from_fetchhead(
git_annotated_commit **out,
git_repository *repo,
const char *branch_name,
const char *remote_url,
const git_oid *id);
/**
* Creates a `git_annotated_commit` from the given commit id.
* The resulting git_annotated_commit must be freed with
* `git_annotated_commit_free`.
*
* An annotated commit contains information about how it was
* looked up, which may be useful for functions like merge or
* rebase to provide context to the operation. For example,
* conflict files will include the name of the source or target
* branches being merged. It is therefore preferable to use the
* most specific function (eg `git_annotated_commit_from_ref`)
* instead of this one when that data is known.
*
* @param out pointer to store the git_annotated_commit result in
* @param repo repository that contains the given commit
* @param id the commit object id to lookup
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_annotated_commit_lookup(
git_annotated_commit **out,
git_repository *repo,
const git_oid *id);
/**
* Gets the commit ID that the given `git_annotated_commit` refers to.
*
* @param head the given annotated commit
* @return commit id
*/
GIT_EXTERN(const git_oid *) git_annotated_commit_id(
const git_annotated_commit *commit);
/**
* Frees a `git_annotated_commit`.
*
* @param annotated_commit annotated commit to free
*/
GIT_EXTERN(void) git_annotated_commit_free(
git_annotated_commit *commit);
/** @} */
GIT_END_DECL
#endif
......@@ -43,6 +43,7 @@ typedef enum {
GIT_EMODIFIED = -15, /**< Reference value does not match expected */
GIT_EAUTH = -16, /**< Authentication error */
GIT_ECERTIFICATE = -17, /**< Server certificate is invalid */
GIT_EAPPLIED = -18, /**< Patch/merge has already been applied */
GIT_PASSTHROUGH = -30, /**< Internal only */
GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */
......@@ -90,6 +91,7 @@ typedef enum {
GITERR_CALLBACK,
GITERR_CHERRYPICK,
GITERR_DESCRIBE,
GITERR_REBASE,
} git_error_t;
/**
......
......@@ -13,6 +13,7 @@
#include "oidarray.h"
#include "checkout.h"
#include "index.h"
#include "annotated_commit.h"
/**
* @file git2/merge.h
......@@ -303,7 +304,7 @@ GIT_EXTERN(int) git_merge_analysis(
git_merge_analysis_t *analysis_out,
git_merge_preference_t *preference_out,
git_repository *repo,
const git_merge_head **their_heads,
const git_annotated_commit **their_heads,
size_t their_heads_len);
/**
......@@ -382,69 +383,6 @@ GIT_EXTERN(int) git_merge_base_octopus(
const git_oid input_array[]);
/**
* Creates a `git_merge_head` from the given reference. The resulting
* git_merge_head must be freed with `git_merge_head_free`.
*
* @param out pointer to store the git_merge_head result in
* @param repo repository that contains the given reference
* @param ref reference to use as a merge input
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge_head_from_ref(
git_merge_head **out,
git_repository *repo,
const git_reference *ref);
/**
* Creates a `git_merge_head` from the given fetch head data. The resulting
* git_merge_head must be freed with `git_merge_head_free`.
*
* @param out pointer to store the git_merge_head result in
* @param repo repository that contains the given commit
* @param branch_name name of the (remote) branch
* @param remote_url url of the remote
* @param oid the commit object id to use as a merge input
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge_head_from_fetchhead(
git_merge_head **out,
git_repository *repo,
const char *branch_name,
const char *remote_url,
const git_oid *oid);
/**
* Creates a `git_merge_head` from the given commit id. The resulting
* git_merge_head must be freed with `git_merge_head_free`.
*
* @param out pointer to store the git_merge_head result in
* @param repo repository that contains the given commit
* @param id the commit object id to use as a merge input
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge_head_from_id(
git_merge_head **out,
git_repository *repo,
const git_oid *id);
/**
* Gets the commit ID that the given `git_merge_head` refers to.
*
* @param head the given merge head
* @return commit id
*/
GIT_EXTERN(const git_oid *) git_merge_head_id(
const git_merge_head *head);
/**
* Frees a `git_merge_head`.
*
* @param head merge head to free
*/
GIT_EXTERN(void) git_merge_head_free(
git_merge_head *head);
/**
* Merge two files as they exist in the in-memory data structures, using
* the given common ancestor as the baseline, producing a
* `git_merge_file_result` that reflects the merge result. The
......@@ -557,7 +495,7 @@ GIT_EXTERN(int) git_merge_commits(
*/
GIT_EXTERN(int) git_merge(
git_repository *repo,
const git_merge_head **their_heads,
const git_annotated_commit **their_heads,
size_t their_heads_len,
const git_merge_options *merge_opts,
const git_checkout_options *checkout_opts);
......
......@@ -97,6 +97,23 @@ GIT_EXTERN(int) git_note_read(
const git_oid *oid);
/**
* Get the note author
*
* @param note the note
* @return the author
*/
GIT_EXTERN(const git_signature *) git_note_author(const git_note *note);
/**
* Get the note committer
*
* @param note the note
* @return the committer
*/
GIT_EXTERN(const git_signature *) git_note_committer(const git_note *note);
/**
* Get the note message
*
* @param note the note
......
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_rebase_h__
#define INCLUDE_git_rebase_h__
#include "common.h"
#include "types.h"
#include "oid.h"
#include "annotated_commit.h"
/**
* @file git2/rebase.h
* @brief Git rebase routines
* @defgroup git_rebase Git merge routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
typedef struct {
unsigned int version;
/**
* Provide a quiet rebase experience; unused by libgit2 but provided for
* interoperability with other clients.
*/
int quiet;
/**
* Canonical name of the notes reference used to rewrite notes for
* rebased commits when finishing the rebase; if NULL, the contents of
* the coniguration option `notes.rewriteRef` is examined, unless the
* configuration option `notes.rewrite.rebase` is set to false. If
* `notes.rewriteRef` is NULL, notes will not be rewritten.
*/
const char *rewrite_notes_ref;
} git_rebase_options;
/** Type of rebase operation in-progress after calling `git_rebase_next`. */
typedef enum {
/**
* The given commit is to be cherry-picked. The client should commit
* the changes and continue if there are no conflicts.
*/
GIT_REBASE_OPERATION_PICK = 0,
/**
* The given commit is to be cherry-picked, but the client should prompt
* the user to provide an updated commit message.
*/
GIT_REBASE_OPERATION_REWORD,
/**
* The given commit is to be cherry-picked, but the client should stop
* to allow the user to edit the changes before committing them.
*/
GIT_REBASE_OPERATION_EDIT,
/**
* The given commit is to be squashed into the previous commit. The
* commit message will be merged with the previous message.
*/
GIT_REBASE_OPERATION_SQUASH,
/**
* The given commit is to be squashed into the previous commit. The
* commit message from this commit will be discarded.
*/
GIT_REBASE_OPERATION_FIXUP,
/**
* No commit will be cherry-picked. The client should run the given
* command and (if successful) continue.
*/
GIT_REBASE_OPERATION_EXEC,
} git_rebase_operation_t;
#define GIT_REBASE_OPTIONS_VERSION 1
#define GIT_REBASE_OPTIONS_INIT {GIT_REBASE_OPTIONS_VERSION}
typedef struct {
/** The type of rebase operation. */
git_rebase_operation_t type;
/**
* The commit ID being cherry-picked. This will be populated for
* all operations except those of type `GIT_REBASE_OPERATION_EXEC`.
*/
const git_oid id;
/**
* The executable the user has requested be run. This will only
* be populated for operations of type `GIT_REBASE_OPERATION_EXEC`.
*/
const char *exec;
} git_rebase_operation;
/**
* Initializes a `git_rebase_options` with default values. Equivalent to
* creating an instance with GIT_REBASE_OPTIONS_INIT.
*
* @param opts the `git_rebase_options` instance to initialize.
* @param version the version of the struct; you should pass
* `GIT_REBASE_OPTIONS_VERSION` here.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_init_options(
git_rebase_options *opts,
unsigned int version);
/**
* Initializes a rebase operation to rebase the changes in `branch`
* relative to `upstream` onto another branch. To begin the rebase
* process, call `git_rebase_next`. When you have finished with this
* object, call `git_rebase_free`.
*
* @param out Pointer to store the rebase object
* @param repo The repository to perform the rebase
* @param branch The terminal commit to rebase
* @param upstream The commit to begin rebasing from, or NULL to rebase all
* reachable commits
* @param onto The branch to rebase onto, or NULL to rebase onto the given
* upstream
* @param signature The signature of the rebaser (optional)
* @param opts Options to specify how rebase is performed
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_init(
git_rebase **out,
git_repository *repo,
const git_annotated_commit *branch,
const git_annotated_commit *upstream,
const git_annotated_commit *onto,
const git_signature *signature,
const git_rebase_options *opts);
/**
* Opens an existing rebase that was previously started by either an
* invocation of `git_rebase_init` or by another client.
*
* @param out Pointer to store the rebase object
* @param reop The repository that has a rebase in-progress
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_open(git_rebase **out, git_repository *repo);
/**
* Gets the count of rebase operations that are to be applied.
*
* @param rebase The in-progress rebase
* @return The number of rebase operations in total
*/
GIT_EXTERN(size_t) git_rebase_operation_entrycount(git_rebase *rebase);
/**
* Gets the index of the rebase operation that is currently being applied.
*
* @param rebase The in-progress rebase
* @return The index of the rebase operation currently being applied.
*/
GIT_EXTERN(size_t) git_rebase_operation_current(git_rebase *rebase);
/**
* Gets the rebase operation specified by the given index.
*
* @param rebase The in-progress rebase
* @param idx The index of the rebase operation to retrieve
* @return The rebase operation or NULL if `idx` was out of bounds
*/
GIT_EXTERN(git_rebase_operation *) git_rebase_operation_byindex(
git_rebase *rebase,
size_t idx);
/**
* Performs the next rebase operation and returns the information about it.
* If the operation is one that applies a patch (which is any operation except
* GIT_REBASE_OPERATION_EXEC) then the patch will be applied and the index and
* working directory will be updated with the changes. If there are conflicts,
* you will need to address those before committing the changes.
*
* @param out Pointer to store the rebase operation that is to be performed next
* @param repo The rebase in progress
* @param checkout_opts Options to specify how the patch should be checked out
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_next(
git_rebase_operation **operation,
git_rebase *rebase,
git_checkout_options *checkout_opts);
/**
* Commits the current patch. You must have resolved any conflicts that
* were introduced during the patch application from the `git_rebase_next`
* invocation.
*
* @param id Pointer in which to store the OID of the newly created commit
* @param repo The rebase that is in-progress
* @param author The author of the updated commit, or NULL to keep the
* author from the original commit
* @param committer The committer of the rebase
* @param message_encoding The encoding for the message in the commit,
* represented with a standard encoding name. If message is NULL,
* this should also be NULL, and the encoding from the original
* commit will be maintained. If message is specified, this may be
* NULL to indicate that "UTF-8" is to be used.
* @param message The message for this commit, or NULL to use the message
* from the original commit.
* @return Zero on success, GIT_EUNMERGED if there are unmerged changes in
* the index, GIT_EAPPLIED if the current commit has already
* been applied to the upstream and there is nothing to commit,
* -1 on failure.
*/
GIT_EXTERN(int) git_rebase_commit(
git_oid *id,
git_rebase *rebase,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message);
/**
* Aborts a rebase that is currently in progress, resetting the repository
* and working directory to their state before rebase began.
*
* @param rebase The rebase that is in-progress
* @param signature The identity that is aborting the rebase
* @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress,
* -1 on other errors.
*/
GIT_EXTERN(int) git_rebase_abort(
git_rebase *rebase,
const git_signature *signature);
/**
* Finishes a rebase that is currently in progress once all patches have
* been applied.
*
* @param rebase The rebase that is in-progress
* @param signature The identity that is finishing the rebase (optional)
* @param opts Options to specify how rebase is finished
* @param Zero on success; -1 on error
*/
GIT_EXTERN(int) git_rebase_finish(
git_rebase *rebase,
const git_signature *signature,
const git_rebase_options *opts);
/**
* Frees the `git_rebase` object.
*
* @param rebase The rebase object
*/
GIT_EXTERN(void) git_rebase_free(git_rebase *rebase);
/** @} */
GIT_END_DECL
#endif
......@@ -70,7 +70,7 @@ GIT_EXTERN(int) git_reset(
git_object *target,
git_reset_t reset_type,
git_checkout_options *checkout_opts,
git_signature *signature,
const git_signature *signature,
const char *log_message);
/**
......
......@@ -174,8 +174,8 @@ typedef struct git_reference_iterator git_reference_iterator;
/** Transactional interface to references */
typedef struct git_transaction git_transaction;
/** Merge heads, the input to merge */
typedef struct git_merge_head git_merge_head;
/** Annotated commits, the input to merge and rebase. */
typedef struct git_annotated_commit git_annotated_commit;
/** Merge result */
typedef struct git_merge_result git_merge_result;
......@@ -183,6 +183,8 @@ typedef struct git_merge_result git_merge_result;
/** Representation of a status collection */
typedef struct git_status_list git_status_list;
/** Representation of a rebase */
typedef struct git_rebase git_rebase;
/** Basic type of any Git reference. */
typedef enum {
......
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
#include "annotated_commit.h"
#include "git2/commit.h"
#include "git2/refs.h"
#include "git2/repository.h"
#include "git2/annotated_commit.h"
static int annotated_commit_init(
git_annotated_commit **out,
git_repository *repo,
const git_oid *id,
const char *ref_name,
const char *remote_url)
{
git_annotated_commit *annotated_commit;
int error = 0;
assert(out && id);
*out = NULL;
annotated_commit = git__calloc(1, sizeof(git_annotated_commit));
GITERR_CHECK_ALLOC(annotated_commit);
if (ref_name) {
annotated_commit->ref_name = git__strdup(ref_name);
GITERR_CHECK_ALLOC(annotated_commit->ref_name);
}
if (remote_url) {
annotated_commit->remote_url = git__strdup(remote_url);
GITERR_CHECK_ALLOC(annotated_commit->remote_url);
}
git_oid_fmt(annotated_commit->id_str, id);
annotated_commit->id_str[GIT_OID_HEXSZ] = '\0';
if ((error = git_commit_lookup(&annotated_commit->commit, repo, id)) < 0) {
git_annotated_commit_free(annotated_commit);
return error;
}
*out = annotated_commit;
return error;
}
int git_annotated_commit_from_ref(
git_annotated_commit **out,
git_repository *repo,
const git_reference *ref)
{
git_reference *resolved;
int error = 0;
assert(out && repo && ref);
*out = NULL;
if ((error = git_reference_resolve(&resolved, ref)) < 0)
return error;
error = annotated_commit_init(out, repo, git_reference_target(resolved),
git_reference_name(ref), NULL);
git_reference_free(resolved);
return error;
}
int git_annotated_commit_lookup(
git_annotated_commit **out,
git_repository *repo,
const git_oid *id)
{
assert(out && repo && id);
return annotated_commit_init(out, repo, id, NULL, NULL);
}
int git_annotated_commit_from_fetchhead(
git_annotated_commit **out,
git_repository *repo,
const char *branch_name,
const char *remote_url,
const git_oid *id)
{
assert(repo && id && branch_name && remote_url);
return annotated_commit_init(out, repo, id, branch_name, remote_url);
}
const git_oid *git_annotated_commit_id(
const git_annotated_commit *annotated_commit)
{
assert(annotated_commit);
return git_commit_id(annotated_commit->commit);
}
void git_annotated_commit_free(git_annotated_commit *annotated_commit)
{
if (annotated_commit == NULL)
return;
if (annotated_commit->commit != NULL)
git_commit_free(annotated_commit->commit);
if (annotated_commit->ref_name != NULL)
git__free(annotated_commit->ref_name);
if (annotated_commit->remote_url != NULL)
git__free(annotated_commit->remote_url);
git__free(annotated_commit);
}
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_annotated_commit_h__
#define INCLUDE_annotated_commit_h__
#include "git2/oid.h"
/** Internal structure for merge inputs */
struct git_annotated_commit {
git_commit *commit;
char *ref_name;
char *remote_url;
char id_str[GIT_OID_HEXSZ+1];
};
#endif
......@@ -16,6 +16,7 @@
#include "commit.h"
#include "signature.h"
#include "message.h"
#include "refs.h"
void git_commit__free(void *_commit)
{
......@@ -34,35 +35,6 @@ void git_commit__free(void *_commit)
git__free(commit);
}
static int update_ref_for_commit(git_repository *repo, git_reference *ref, const char *update_ref, const git_oid *id, const git_signature *committer)
{
git_reference *ref2 = NULL;
int error;
git_commit *c;
const char *shortmsg;
git_buf reflog_msg = GIT_BUF_INIT;
if ((error = git_commit_lookup(&c, repo, id)) < 0) {
return error;
}
shortmsg = git_commit_summary(c);
git_buf_printf(&reflog_msg, "commit%s: %s",
git_commit_parentcount(c) == 0 ? " (initial)" : "",
shortmsg);
git_commit_free(c);
if (ref) {
error = git_reference_set_target(&ref2, ref, id, committer, git_buf_cstr(&reflog_msg));
git_reference_free(ref2);
} else {
error = git_reference__update_terminal(repo, update_ref, id, committer, git_buf_cstr(&reflog_msg));
}
git_buf_free(&reflog_msg);
return error;
}
int git_commit_create_from_callback(
git_oid *id,
git_repository *repo,
......@@ -131,7 +103,8 @@ int git_commit_create_from_callback(
git_buf_free(&commit);
if (update_ref != NULL) {
error = update_ref_for_commit(repo, ref, update_ref, id, committer);
error = git_reference__update_for_commit(
repo, ref, update_ref, id, committer, "commit");
git_reference_free(ref);
return error;
}
......@@ -321,7 +294,8 @@ int git_commit_amend(
&tree_id, commit_parent_for_amend, (void *)commit_to_amend);
if (!error && update_ref) {
error = update_ref_for_commit(repo, ref, NULL, id, committer);
error = git_reference__update_for_commit(
repo, ref, NULL, id, committer, "commit");
git_reference_free(ref);
}
......
......@@ -110,16 +110,6 @@ typedef struct {
int binary:1;
} git_merge_diff;
/** Internal structure for merge inputs */
struct git_merge_head {
char *ref_name;
char *remote_url;
git_oid oid;
char oid_str[GIT_OID_HEXSZ+1];
git_commit *commit;
};
int git_merge__bases_many(
git_commit_list **out,
git_revwalk *walk,
......@@ -145,8 +135,8 @@ void git_merge_diff_list__free(git_merge_diff_list *diff_list);
int git_merge__setup(
git_repository *repo,
const git_merge_head *our_head,
const git_merge_head *heads[],
const git_annotated_commit *our_head,
const git_annotated_commit *heads[],
size_t heads_len);
int git_merge__check_result(git_repository *repo, git_index *index_new);
......
......@@ -306,7 +306,11 @@ cleanup:
return error;
}
static int note_new(git_note **out, git_oid *note_oid, git_blob *blob)
static int note_new(
git_note **out,
git_oid *note_oid,
git_commit *commit,
git_blob *blob)
{
git_note *note = NULL;
......@@ -314,6 +318,11 @@ static int note_new(git_note **out, git_oid *note_oid, git_blob *blob)
GITERR_CHECK_ALLOC(note);
git_oid_cpy(&note->id, note_oid);
if (git_signature_dup(&note->author, git_commit_author(commit)) < 0 ||
git_signature_dup(&note->committer, git_commit_committer(commit)) < 0)
return -1;
note->message = git__strdup((char *)git_blob_rawcontent(blob));
GITERR_CHECK_ALLOC(note->message);
......@@ -323,7 +332,11 @@ static int note_new(git_note **out, git_oid *note_oid, git_blob *blob)
}
static int note_lookup(
git_note **out, git_repository *repo, git_tree *tree, const char *target)
git_note **out,
git_repository *repo,
git_commit *commit,
git_tree *tree,
const char *target)
{
int error, fanout = 0;
git_oid oid;
......@@ -340,7 +353,7 @@ static int note_lookup(
if ((error = git_blob_lookup(&blob, repo, &oid)) < 0)
goto cleanup;
if ((error = note_new(&note, &oid, blob)) < 0)
if ((error = note_new(&note, &oid, commit, blob)) < 0)
goto cleanup;
*out = note;
......@@ -432,7 +445,7 @@ int git_note_read(git_note **out, git_repository *repo,
if (!(error = retrieve_note_tree_and_commit(
&tree, &commit, repo, &notes_ref)))
error = note_lookup(out, repo, tree, target);
error = note_lookup(out, repo, commit, tree, target);
git__free(target);
git_tree_free(tree);
......@@ -502,6 +515,18 @@ int git_note_default_ref(const char **out, git_repository *repo)
return note_get_default_ref(out, repo);
}
const git_signature *git_note_committer(const git_note *note)
{
assert(note);
return note->committer;
}
const git_signature *git_note_author(const git_note *note)
{
assert(note);
return note->author;
}
const char * git_note_message(const git_note *note)
{
assert(note);
......@@ -519,6 +544,8 @@ void git_note_free(git_note *note)
if (note == NULL)
return;
git_signature_free(note->committer);
git_signature_free(note->author);
git__free(note->message);
git__free(note);
}
......
......@@ -23,6 +23,9 @@
struct git_note {
git_oid id;
git_signature *author;
git_signature *committer;
char *message;
};
......
This diff is collapsed. Click to expand it.
......@@ -22,6 +22,7 @@
#include <git2/refdb.h>
#include <git2/sys/refs.h>
#include <git2/signature.h>
#include <git2/commit.h>
GIT__USE_STRMAP;
......@@ -1090,6 +1091,40 @@ int git_reference__update_terminal(
return reference__update_terminal(repo, ref_name, oid, 0, signature, log_message);
}
int git_reference__update_for_commit(
git_repository *repo,
git_reference *ref,
const char *ref_name,
const git_oid *id,
const git_signature *committer,
const char *operation)
{
git_reference *ref_new = NULL;
git_commit *commit = NULL;
git_buf reflog_msg = GIT_BUF_INIT;
int error;
if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
(error = git_buf_printf(&reflog_msg, "%s%s: %s",
operation ? operation : "commit",
git_commit_parentcount(commit) == 0 ? " (initial)" : "",
git_commit_summary(commit))) < 0)
goto done;
if (ref)
error = git_reference_set_target(
&ref_new, ref, id, committer, git_buf_cstr(&reflog_msg));
else
error = git_reference__update_terminal(
repo, ref_name, id, committer, git_buf_cstr(&reflog_msg));
done:
git_reference_free(ref_new);
git_buf_free(&reflog_msg);
git_commit_free(commit);
return error;
}
int git_reference_has_log(git_repository *repo, const char *refname)
{
int error;
......
......@@ -100,4 +100,13 @@ int git_reference_lookup_resolved(
int git_reference__log_signature(git_signature **out, git_repository *repo);
/** Update a reference after a commit. */
int git_reference__update_for_commit(
git_repository *repo,
git_reference *ref,
const char *ref_name,
const git_oid *id,
const git_signature *committer,
const char *operation);
#endif
......@@ -1728,6 +1728,28 @@ cleanup:
return error;
}
int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
{
git_filebuf file = GIT_FILEBUF_INIT;
git_buf file_path = GIT_BUF_INIT;
char orig_head_str[GIT_OID_HEXSZ];
int error = 0;
git_oid_fmt(orig_head_str, orig_head);
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_ORIG_HEAD_FILE)) == 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) == 0 &&
(error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
error = git_filebuf_commit(&file);
if (error < 0)
git_filebuf_cleanup(&file);
git_buf_free(&file_path);
return error;
}
int git_repository_message(git_buf *out, git_repository *repo)
{
git_buf path = GIT_BUF_INIT;
......
......@@ -170,6 +170,8 @@ GIT_INLINE(int) git_repository__ensure_not_bare(
return GIT_EBAREREPO;
}
int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head);
int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len);
#endif
......@@ -101,7 +101,7 @@ int git_reset(
git_object *target,
git_reset_t reset_type,
git_checkout_options *checkout_opts,
git_signature *signature,
const git_signature *signature,
const char *log_message)
{
git_object *commit = NULL;
......
......@@ -270,3 +270,14 @@ void git_signature__writebuf(git_buf *buf, const char *header, const git_signatu
(unsigned)sig->when.time, sign, hours, mins);
}
bool git_signature__equal(const git_signature *one, const git_signature *two)
{
assert(one && two);
return
git__strcmp(one->name, two->name) == 0 &&
git__strcmp(one->email, two->email) == 0 &&
one->when.time == two->when.time &&
one->when.offset == two->when.offset;
}
......@@ -14,6 +14,7 @@
int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header, char ender);
void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig);
bool git_signature__equal(const git_signature *one, const git_signature *two);
int git_signature__pdup(git_signature **dest, const git_signature *source, git_pool *pool);
......
......@@ -6,6 +6,7 @@
#include "merge.h"
#include "git2/merge.h"
#include "git2/sys/index.h"
#include "git2/annotated_commit.h"
int merge_trees_from_branches(
git_index **index, git_repository *repo,
......@@ -84,7 +85,7 @@ int merge_branches(git_repository *repo,
git_merge_options *merge_opts, git_checkout_options *checkout_opts)
{
git_reference *head_ref, *theirs_ref;
git_merge_head *theirs_head;
git_annotated_commit *theirs_head;
git_checkout_options head_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
head_checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
......@@ -93,13 +94,13 @@ int merge_branches(git_repository *repo,
cl_git_pass(git_checkout_head(repo, &head_checkout_opts));
cl_git_pass(git_reference_lookup(&theirs_ref, repo, theirs_branch));
cl_git_pass(git_merge_head_from_ref(&theirs_head, repo, theirs_ref));
cl_git_pass(git_annotated_commit_from_ref(&theirs_head, repo, theirs_ref));
cl_git_pass(git_merge(repo, (const git_merge_head **)&theirs_head, 1, merge_opts, checkout_opts));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&theirs_head, 1, merge_opts, checkout_opts));
git_reference_free(head_ref);
git_reference_free(theirs_ref);
git_merge_head_free(theirs_head);
git_annotated_commit_free(theirs_head);
return 0;
}
......
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "git2/annotated_commit.h"
#include "git2/sys/index.h"
#include "merge.h"
#include "../merge_helpers.h"
......@@ -43,17 +44,17 @@ static void analysis_from_branch(
{
git_buf refname = GIT_BUF_INIT;
git_reference *their_ref;
git_merge_head *their_head;
git_annotated_commit *their_head;
git_buf_printf(&refname, "%s%s", GIT_REFS_HEADS_DIR, branchname);
cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&refname)));
cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge_analysis(merge_analysis, merge_pref, repo, (const git_merge_head **)&their_head, 1));
cl_git_pass(git_merge_analysis(merge_analysis, merge_pref, repo, (const git_annotated_commit **)&their_head, 1));
git_buf_free(&refname);
git_merge_head_free(their_head);
git_annotated_commit_free(their_head);
git_reference_free(their_ref);
}
......
......@@ -89,18 +89,18 @@ static void set_core_autocrlf_to(git_repository *repo, bool value)
static int merge_branch(void)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
git_annotated_commit *their_head;
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
int error;
cl_git_pass(git_oid_fromstr(&their_oids[0], MERGE_BRANCH_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_oids[0]));
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
error = git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, &checkout_opts);
error = git_merge(repo, (const git_annotated_commit **)&their_head, 1, &merge_opts, &checkout_opts);
git_merge_head_free(their_heads[0]);
git_annotated_commit_free(their_head);
return error;
}
......
......@@ -95,20 +95,20 @@ void test_merge_workdir_simple__cleanup(void)
static void merge_simple_branch(int merge_file_favor, int addl_checkout_strategy)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
git_annotated_commit *their_heads[1];
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_SIMPLE_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
merge_opts.file_favor = merge_file_favor;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS |
addl_checkout_strategy;
cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, &checkout_opts));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, &merge_opts, &checkout_opts));
git_merge_head_free(their_heads[0]);
git_annotated_commit_free(their_heads[0]);
}
static void set_core_autocrlf_to(git_repository *repo, bool value)
......@@ -486,7 +486,7 @@ void test_merge_workdir_simple__directory_file(void)
{
git_reference *head;
git_oid their_oids[1], head_commit_id;
git_merge_head *their_heads[1];
git_annotated_commit *their_heads[1];
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_commit *head_commit;
......@@ -519,22 +519,22 @@ void test_merge_workdir_simple__directory_file(void)
cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL, NULL, NULL));
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_DIRECTORY_FILE));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
merge_opts.file_favor = 0;
cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, NULL));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 20));
git_reference_free(head);
git_commit_free(head_commit);
git_merge_head_free(their_heads[0]);
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_simple__unrelated(void)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
git_annotated_commit *their_heads[1];
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
......@@ -550,20 +550,20 @@ void test_merge_workdir_simple__unrelated(void)
};
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_UNRELATED_PARENT));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
merge_opts.file_favor = 0;
cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, NULL));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 9));
git_merge_head_free(their_heads[0]);
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_simple__unrelated_with_conflicts(void)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
git_annotated_commit *their_heads[1];
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
......@@ -581,21 +581,21 @@ void test_merge_workdir_simple__unrelated_with_conflicts(void)
};
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_UNRELATED_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
merge_opts.file_favor = 0;
cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, NULL));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 11));
git_merge_head_free(their_heads[0]);
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_simple__binary(void)
{
git_oid our_oid, their_oid, our_file_oid;
git_commit *our_commit;
git_merge_head *their_head;
git_annotated_commit *their_head;
const git_index_entry *binary_entry;
struct merge_index_entry merge_index_entries[] = {
......@@ -610,9 +610,9 @@ void test_merge_workdir_simple__binary(void)
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL, NULL, NULL));
cl_git_pass(git_merge_head_from_id(&their_head, repo, &their_oid));
cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_oid));
cl_git_pass(git_merge(repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, 1, NULL, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
......@@ -622,6 +622,6 @@ void test_merge_workdir_simple__binary(void)
cl_git_pass(git_oid_fromstr(&our_file_oid, "23ed141a6ae1e798b2f721afedbe947c119111ba"));
cl_assert(git_oid_cmp(&binary_entry->id, &our_file_oid) == 0);
git_merge_head_free(their_head);
git_annotated_commit_free(their_head);
git_commit_free(our_commit);
}
......@@ -30,7 +30,7 @@ void test_merge_workdir_submodules__automerge(void)
{
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_merge_head *their_head;
git_annotated_commit *their_head;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
......@@ -47,15 +47,15 @@ void test_merge_workdir_submodules__automerge(void)
cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL, NULL, NULL));
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge(repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
git_merge_head_free(their_head);
git_annotated_commit_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
git_reference_free(our_ref);
......@@ -65,7 +65,7 @@ void test_merge_workdir_submodules__take_changed(void)
{
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_merge_head *their_head;
git_annotated_commit *their_head;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
......@@ -80,15 +80,15 @@ void test_merge_workdir_submodules__take_changed(void)
cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL, NULL, NULL));
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER2_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge(repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 4));
git_index_free(index);
git_merge_head_free(their_head);
git_annotated_commit_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
git_reference_free(our_ref);
......
......@@ -33,7 +33,7 @@ static int merge_trivial(const char *ours, const char *theirs)
git_buf branch_buf = GIT_BUF_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_reference *our_ref, *their_ref;
git_merge_head *their_heads[1];
git_annotated_commit *their_heads[1];
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
......@@ -45,14 +45,14 @@ static int merge_trivial(const char *ours, const char *theirs)
git_buf_clear(&branch_buf);
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
cl_git_pass(git_reference_lookup(&their_ref, repo, branch_buf.ptr));
cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, their_ref));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, their_ref));
cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, NULL, NULL));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, NULL, NULL));
git_buf_free(&branch_buf);
git_reference_free(our_ref);
git_reference_free(their_ref);
git_merge_head_free(their_heads[0]);
git_annotated_commit_free(their_heads[0]);
return 0;
}
......
#include "clar_libgit2.h"
#include "git2/rebase.h"
#include "merge.h"
#include "posix.h"
#include "annotated_commit.h"
#include <fcntl.h>
static git_repository *repo;
// Fixture setup and teardown
void test_rebase_abort__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
}
void test_rebase_abort__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
{
git_rebase *rebase;
git_reference *head_ref, *branch_ref = NULL;
git_signature *signature;
git_status_list *statuslist;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
cl_git_pass(git_rebase_open(&rebase, repo));
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
cl_git_pass(git_rebase_abort(rebase, signature));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
/* Make sure the refs are updated appropriately */
cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD"));
if (branch->ref_name == NULL)
cl_assert_equal_oid(git_annotated_commit_id(branch), git_reference_target(head_ref));
else {
cl_assert_equal_s("refs/heads/beef", git_reference_symbolic_target(head_ref));
cl_git_pass(git_reference_lookup(&branch_ref, repo, git_reference_symbolic_target(head_ref)));
cl_assert_equal_oid(git_annotated_commit_id(branch), git_reference_target(branch_ref));
}
git_status_list_new(&statuslist, repo, NULL);
cl_assert_equal_i(0, git_status_list_entrycount(statuslist));
git_status_list_free(statuslist);
/* Make sure the reflogs are updated appropriately */
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(git_annotated_commit_id(onto), git_reflog_entry_id_old(reflog_entry));
cl_assert_equal_oid(git_annotated_commit_id(branch), git_reflog_entry_id_new(reflog_entry));
cl_assert_equal_s("rebase: aborting", git_reflog_entry_message(reflog_entry));
git_reflog_free(reflog);
git_reference_free(head_ref);
git_reference_free(branch_ref);
git_signature_free(signature);
git_rebase_free(rebase);
}
void test_rebase_abort__merge(void)
{
git_rebase *rebase;
git_reference *branch_ref, *onto_ref;
git_signature *signature;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
git_signature_free(signature);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
void test_rebase_abort__detached_head(void)
{
git_rebase *rebase;
git_oid branch_id;
git_reference *onto_ref;
git_signature *signature;
git_annotated_commit *branch_head, *onto_head;
git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64");
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
git_signature_free(signature);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
void test_rebase_abort__old_style_head_file(void)
{
git_rebase *rebase;
git_reference *branch_ref, *onto_ref;
git_signature *signature;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
p_rename("rebase-merge/.git/rebase-merge/orig-head",
"rebase-merge/.git/rebase-merge/head");
test_abort(branch_head, onto_head);
git_signature_free(signature);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
#include "clar_libgit2.h"
#include "git2/rebase.h"
#include "posix.h"
#include <fcntl.h>
static git_repository *repo;
static git_index *_index;
static git_signature *signature;
// Fixture setup and teardown
void test_rebase_iterator__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
cl_git_pass(git_repository_index(&_index, repo));
cl_git_pass(git_signature_now(&signature, "Rebaser", "rebaser@rebaser.rb"));
}
void test_rebase_iterator__cleanup(void)
{
git_signature_free(signature);
git_index_free(_index);
cl_git_sandbox_cleanup();
}
static void test_operations(git_rebase *rebase, size_t expected_current)
{
size_t i, expected_count = 5;
git_oid expected_oid[5];
git_rebase_operation *operation;
git_oid_fromstr(&expected_oid[0], "da9c51a23d02d931a486f45ad18cda05cf5d2b94");
git_oid_fromstr(&expected_oid[1], "8d1f13f93c4995760ac07d129246ac1ff64c0be9");
git_oid_fromstr(&expected_oid[2], "3069cc907e6294623e5917ef6de663928c1febfb");
git_oid_fromstr(&expected_oid[3], "588e5d2f04d49707fe4aab865e1deacaf7ef6787");
git_oid_fromstr(&expected_oid[4], "b146bd7608eac53d9bf9e1a6963543588b555c64");
cl_assert_equal_i(expected_count, git_rebase_operation_entrycount(rebase));
cl_assert_equal_i(expected_current, git_rebase_operation_current(rebase));
for (i = 0; i < expected_count; i++) {
operation = git_rebase_operation_byindex(rebase, i);
cl_assert_equal_i(GIT_REBASE_OPERATION_PICK, operation->type);
cl_assert_equal_oid(&expected_oid[i], &operation->id);
}
}
void test_rebase_iterator__iterates(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_oid commit_id;
int error;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
test_operations(rebase, 0);
git_rebase_free(rebase);
cl_git_pass(git_rebase_open(&rebase, repo));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 0);
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 1);
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 2);
git_rebase_free(rebase);
cl_git_pass(git_rebase_open(&rebase, repo));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 3);
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 4);
cl_git_fail(error = git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_assert_equal_i(GIT_ITEROVER, error);
test_operations(rebase, 4);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
[core]
repositoryformatversion = 0
bare = false
logallrefupdates = true
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
efad0b11c47cb2f0220cbd6f5b0f93bb99064b00 efad0b11c47cb2f0220cbd6f5b0f93bb99064b00 Edward Thomson <ethomson@edwardthomson.com> 1405623541 -0400 checkout: moving from master to master
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment