Skip to content

Commit f08132f

Browse files
committed
rebase: --fork-point regression fix
"git rebase --fork-point master" used to work OK, as it internally called "git merge-base --fork-point" that knew how to handle short refname and dwim it to the full refname before calling the underlying get_fork_point() function. This is no longer true after the command was rewritten in C, as its internall call made directly to get_fork_point() does not dwim a short ref. Move the "dwim the refname argument to the full refname" logic that is used in "git merge-base" to the underlying get_fork_point() function, so that the other caller of the function in the implementation of "git rebase" behaves the same way to fix this regression. Signed-off-by: Alex Torok <[email protected]> [jc: revamped the fix and used Alex's tests] Signed-off-by: Junio C Hamano <[email protected]>
1 parent da72936 commit f08132f

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

builtin/merge-base.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,16 @@ static int handle_is_ancestor(int argc, const char **argv)
114114
static int handle_fork_point(int argc, const char **argv)
115115
{
116116
struct object_id oid;
117-
char *refname;
118117
struct commit *derived, *fork_point;
119118
const char *commitname;
120119

121-
switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
122-
case 0:
123-
die("No such ref: '%s'", argv[0]);
124-
case 1:
125-
break; /* good */
126-
default:
127-
die("Ambiguous refname: '%s'", argv[0]);
128-
}
129-
130120
commitname = (argc == 2) ? argv[1] : "HEAD";
131121
if (get_oid(commitname, &oid))
132122
die("Not a valid object name: '%s'", commitname);
133123

134124
derived = lookup_commit_reference(the_repository, &oid);
135125

136-
fork_point = get_fork_point(refname, derived);
126+
fork_point = get_fork_point(argv[0], derived);
137127

138128
if (!fork_point)
139129
return 1;

commit.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,12 +903,22 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
903903
struct commit_list *bases;
904904
int i;
905905
struct commit *ret = NULL;
906+
char *full_refname;
907+
908+
switch (dwim_ref(refname, strlen(refname), &oid, &full_refname)) {
909+
case 0:
910+
die("No such ref: '%s'", refname);
911+
case 1:
912+
break; /* good */
913+
default:
914+
die("Ambiguous refname: '%s'", refname);
915+
}
906916

907917
memset(&revs, 0, sizeof(revs));
908918
revs.initial = 1;
909-
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
919+
for_each_reflog_ent(full_refname, collect_one_reflog_ent, &revs);
910920

911-
if (!revs.nr && !get_oid(refname, &oid))
921+
if (!revs.nr)
912922
add_one_commit(&oid, &revs);
913923

914924
for (i = 0; i < revs.nr; i++)
@@ -934,6 +944,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
934944

935945
cleanup_return:
936946
free_commit_list(bases);
947+
free(full_refname);
937948
return ret;
938949
}
939950

t/t3431-rebase-fork-point.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,31 @@ test_rebase 'G F B A' --keep-base
4747
test_rebase 'G F C E D B A' --no-fork-point
4848
test_rebase 'G F C D B A' --no-fork-point --onto D
4949
test_rebase 'G F C B A' --no-fork-point --keep-base
50+
5051
test_rebase 'G F E D B A' --fork-point refs/heads/master
52+
test_rebase 'G F E D B A' --fork-point master
53+
5154
test_rebase 'G F D B A' --fork-point --onto D refs/heads/master
55+
test_rebase 'G F D B A' --fork-point --onto D master
56+
5257
test_rebase 'G F B A' --fork-point --keep-base refs/heads/master
58+
test_rebase 'G F B A' --fork-point --keep-base master
59+
5360
test_rebase 'G F C E D B A' refs/heads/master
61+
test_rebase 'G F C E D B A' master
62+
5463
test_rebase 'G F C D B A' --onto D refs/heads/master
64+
test_rebase 'G F C D B A' --onto D master
65+
5566
test_rebase 'G F C B A' --keep-base refs/heads/master
67+
test_rebase 'G F C B A' --keep-base master
68+
69+
test_expect_success 'git rebase --fork-point with ambigous refname' '
70+
git checkout master &&
71+
git checkout -b one &&
72+
git checkout side &&
73+
git tag one &&
74+
test_must_fail git rebase --fork-point --onto D one
75+
'
5676

5777
test_done

0 commit comments

Comments
 (0)