Skip to content

Commit 7f562f2

Browse files
authored
Merge pull request libgit2#5057 from eaigner/merge-rebase-onto-name
rebase: orig_head and onto accessors
2 parents 604e281 + e215f47 commit 7f562f2

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

include/git2/rebase.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,34 @@ GIT_EXTERN(int) git_rebase_open(
199199
git_repository *repo,
200200
const git_rebase_options *opts);
201201

202+
/**
203+
* Gets the original `HEAD` ref name for merge rebases.
204+
*
205+
* @return The original `HEAD` ref name
206+
*/
207+
GIT_EXTERN(const char *) git_rebase_orig_head_name(git_rebase *rebase);
208+
209+
/**
210+
* Gets the original `HEAD` id for merge rebases.
211+
*
212+
* @return The original `HEAD` id
213+
*/
214+
GIT_EXTERN(const git_oid *) git_rebase_orig_head_id(git_rebase *rebase);
215+
216+
/**
217+
* Gets the `onto` ref name for merge rebases.
218+
*
219+
* @return The `onto` ref name
220+
*/
221+
GIT_EXTERN(const char *) git_rebase_onto_name(git_rebase *rebase);
222+
223+
/**
224+
* Gets the `onto` id for merge rebases.
225+
*
226+
* @return The `onto` id
227+
*/
228+
GIT_EXTERN(const git_oid *) git_rebase_onto_id(git_rebase *rebase);
229+
202230
/**
203231
* Gets the count of rebase operations that are to be applied.
204232
*

src/rebase.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,22 @@ int git_rebase_finish(
13271327
return error;
13281328
}
13291329

1330+
const char *git_rebase_orig_head_name(git_rebase *rebase) {
1331+
return rebase->orig_head_name;
1332+
}
1333+
1334+
const git_oid *git_rebase_orig_head_id(git_rebase *rebase) {
1335+
return &rebase->orig_head_id;
1336+
}
1337+
1338+
const char *git_rebase_onto_name(git_rebase *rebase) {
1339+
return rebase->onto_name;
1340+
}
1341+
1342+
const git_oid *git_rebase_onto_id(git_rebase *rebase) {
1343+
return &rebase->onto_id;
1344+
}
1345+
13301346
size_t git_rebase_operation_entrycount(git_rebase *rebase)
13311347
{
13321348
assert(rebase);

tests/rebase/merge.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ void test_rebase_merge__next(void)
4444
git_status_list *status_list;
4545
const git_status_entry *status_entry;
4646
git_oid pick_id, file1_id;
47+
git_oid master_id, beef_id;
48+
49+
git_oid_fromstr(&master_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
50+
git_oid_fromstr(&beef_id, "b146bd7608eac53d9bf9e1a6963543588b555c64");
4751

4852
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
4953
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
@@ -53,6 +57,12 @@ void test_rebase_merge__next(void)
5357

5458
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
5559

60+
cl_assert_equal_s("refs/heads/beef", git_rebase_orig_head_name(rebase));
61+
cl_assert_equal_oid(&beef_id, git_rebase_orig_head_id(rebase));
62+
63+
cl_assert_equal_s("master", git_rebase_onto_name(rebase));
64+
cl_assert_equal_oid(&master_id, git_rebase_onto_id(rebase));
65+
5666
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
5767

5868
git_oid_fromstr(&pick_id, "da9c51a23d02d931a486f45ad18cda05cf5d2b94");

0 commit comments

Comments
 (0)