summaryrefslogtreecommitdiff
path: root/src/rebase.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-13 11:20:32 -0500
committerEdward Thomson <ethomson@microsoft.com>2015-02-13 11:20:32 -0500
commit49b8293c75d287f609eebae334519872784cd893 (patch)
treefeadd13968dd546bb01527175285c24d3234a241 /src/rebase.c
parent92e87dd74974ccad8e0dbd8dd212bfc514ba441d (diff)
downloadlibgit2-49b8293c75d287f609eebae334519872784cd893.tar.gz
rebase: allow `NULL` branch to indicate `HEAD`
Don't require the branch to rebase, if given `NULL`, simply look up `HEAD`.
Diffstat (limited to 'src/rebase.c')
-rw-r--r--src/rebase.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/rebase.c b/src/rebase.c
index 229b18a38..a1c72e8a3 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -608,11 +608,21 @@ static int rebase_init(
const git_annotated_commit *onto,
const git_rebase_options *opts)
{
+ git_reference *head_ref = NULL;
+ git_annotated_commit *head_branch = NULL;
git_buf state_path = GIT_BUF_INIT;
int error;
if ((error = git_buf_joinpath(&state_path, repo->path_repository, REBASE_MERGE_DIR)) < 0)
- return error;
+ goto done;
+
+ if (!branch) {
+ if ((error = git_repository_head(&head_ref, repo)) < 0 ||
+ (error = git_annotated_commit_from_ref(&head_branch, repo, head_ref)) < 0)
+ goto done;
+
+ branch = head_branch;
+ }
rebase->repo = repo;
rebase->type = GIT_REBASE_TYPE_MERGE;
@@ -630,6 +640,10 @@ static int rebase_init(
git_buf_free(&state_path);
+done:
+ git_reference_free(head_ref);
+ git_annotated_commit_free(head_branch);
+
return error;
}
@@ -649,7 +663,7 @@ int git_rebase_init(
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
int error;
- assert(repo && branch && (upstream || onto));
+ assert(repo && (upstream || onto));
*out = NULL;