commit - e82b1d8119d413101f11883e43119759a433edc4
commit + a51a74b38b5e1f44f2967ff4e43e5a4485a13c7a
blob - 753ca9619c5da15ec234ca5a547777313d01b65c
blob + 45c7c6859a192c630ef60545b6c8be15088e8716
--- got/got.c
+++ got/got.c
static const struct got_error *
check_same_branch(struct got_object_id *commit_id,
- struct got_reference *head_ref, struct got_repository *repo)
+ struct got_reference *head_ref, struct got_object_id *yca_id,
+ struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_commit_graph *graph = NULL;
err = got_ref_resolve(&head_commit_id, repo, head_ref);
if (err)
+ goto done;
+
+ if (got_object_id_cmp(head_commit_id, commit_id) == 0) {
+ is_same_branch = 1;
+ goto done;
+ }
+ if (yca_id && got_object_id_cmp(commit_id, yca_id) == 0) {
+ is_same_branch = 1;
goto done;
+ }
err = got_commit_graph_open(&graph, head_commit_id, "/", 1, repo);
if (err)
}
if (id) {
+ if (yca_id && got_object_id_cmp(id, yca_id) == 0)
+ break;
if (got_object_id_cmp(id, commit_id) == 0) {
is_same_branch = 1;
break;
free(commit_id);
goto done;
}
- error = check_same_branch(commit_id, head_ref, repo);
+ error = check_same_branch(commit_id, head_ref, NULL, repo);
if (error)
goto done;
error = got_worktree_set_base_commit_id(worktree, repo,
free(head_commit_id);
if (error != NULL)
goto done;
- error = check_same_branch(commit_id, head_ref, repo);
+ error = check_same_branch(commit_id, head_ref, NULL, repo);
if (error)
goto done;
error = switch_head_ref(head_ref, commit_id, worktree, repo);
error = got_error(GOT_ERR_BRANCH_MOVED);
goto done;
}
- error = check_same_branch(commit_id, head_ref, repo);
+ error = check_same_branch(commit_id, head_ref, NULL, repo);
if (error)
goto done;
}
if (error != NULL)
goto done;
- error = check_same_branch(commit_id, head_ref, repo);
+ error = check_same_branch(commit_id, head_ref, NULL, repo);
if (error) {
if (error->code != GOT_ERR_ANCESTRY)
goto done;
if (error != NULL)
goto done;
- error = check_same_branch(commit_id, head_ref, repo);
+ error = check_same_branch(commit_id, head_ref, NULL, repo);
if (error)
goto done;
} else {
error = got_ref_open(&branch, repo, argv[0], 0);
if (error != NULL)
- goto done;
-
- error = check_same_branch(
- got_worktree_get_base_commit_id(worktree), branch, repo);
- if (error) {
- if (error->code != GOT_ERR_ANCESTRY)
- goto done;
- error = NULL;
- } else {
- error = got_error_msg(GOT_ERR_SAME_BRANCH,
- "specified branch resolves to a commit which "
- "is already contained in work tree's branch");
goto done;
- }
}
error = got_ref_resolve(&branch_head_commit_id, repo, branch);
goto done;
if (!continue_rebase) {
+ struct got_object_id *base_commit_id;
+
+ base_commit_id = got_worktree_get_base_commit_id(worktree);
error = got_commit_graph_find_youngest_common_ancestor(&yca_id,
- got_worktree_get_base_commit_id(worktree),
- branch_head_commit_id, repo);
+ base_commit_id, branch_head_commit_id, repo);
if (error)
goto done;
if (yca_id == NULL) {
goto done;
}
+ error = check_same_branch(base_commit_id, branch, yca_id, repo);
+ if (error) {
+ if (error->code != GOT_ERR_ANCESTRY)
+ goto done;
+ error = NULL;
+ } else {
+ error = got_error_msg(GOT_ERR_SAME_BRANCH,
+ "specified branch resolves to a commit which "
+ "is already contained in work tree's branch");
+ goto done;
+ }
error = got_worktree_rebase_prepare(&new_base_branch,
&tmp_branch, &fileindex, worktree, branch, repo);
if (error)