commit 60db6857a08abeed5f82dd212d63734a5685ab94 from: Stefan Sperling via: Thomas Adam date: Sun Jan 08 18:36:45 2023 UTC fix 'got rebase' not detecting an out-of-date work tree in some cases ok jamsek, op commit - 8bcebf69377a87cb57378dd59d494c7338b0d399 commit + 60db6857a08abeed5f82dd212d63734a5685ab94 blob - 3332095a8811454d53d12e13a07aceca025d3d7a blob + 40f0d1eb9a4a6d1d4ce983b1941373d908e879f4 --- got/got.c +++ got/got.c @@ -10154,6 +10154,8 @@ cmd_rebase(int argc, char *argv[]) struct got_object_id *commit_id = NULL, *parent_id = NULL; struct got_object_id *resume_commit_id = NULL; struct got_object_id *branch_head_commit_id = NULL, *yca_id = NULL; + struct got_object_id *head_commit_id = NULL; + struct got_reference *head_ref = NULL; struct got_commit_object *commit = NULL; int ch, rebase_in_progress = 0, abort_rebase = 0, continue_rebase = 0; int histedit_in_progress = 0, merge_in_progress = 0; @@ -10356,7 +10358,19 @@ cmd_rebase(int argc, char *argv[]) if (!continue_rebase) { struct got_object_id *base_commit_id; + error = got_ref_open(&head_ref, repo, + got_worktree_get_head_ref_name(worktree), 0); + if (error) + goto done; + error = got_ref_resolve(&head_commit_id, repo, head_ref); + if (error) + goto done; base_commit_id = got_worktree_get_base_commit_id(worktree); + if (got_object_id_cmp(base_commit_id, head_commit_id) != 0) { + error = got_error(GOT_ERR_REBASE_OUT_OF_DATE); + goto done; + } + error = got_commit_graph_find_youngest_common_ancestor(&yca_id, base_commit_id, branch_head_commit_id, 1, repo, check_cancelled, NULL); @@ -10537,6 +10551,7 @@ done: got_object_id_queue_free(&commits); free(branch_head_commit_id); free(resume_commit_id); + free(head_commit_id); free(yca_id); if (commit) got_object_commit_close(commit); @@ -10546,6 +10561,8 @@ done: got_ref_close(new_base_branch); if (tmp_branch) got_ref_close(tmp_branch); + if (head_ref) + got_ref_close(head_ref); if (worktree) got_worktree_close(worktree); if (repo) { blob - be35f77809d804c49d6d9222b8479d500a1df7a8 blob + 4692840131f7a20f520b5f57a637d5fcf715a4f9 --- regress/cmdline/rebase.sh +++ regress/cmdline/rebase.sh @@ -1835,6 +1835,57 @@ test_rebase_umask() { fi test_done "$testroot" 0 +} + +test_rebase_out_of_date2() { + local testroot=`test_init rebase_out_of_date2` + local commit0=`git_show_head $testroot/repo` + local commit0_author_time=`git_show_author_time $testroot/repo` + + (cd $testroot/repo && git checkout -q -b newbranch) + echo "modified delta on branch" > $testroot/repo/gamma/delta + git_commit $testroot/repo -m "committing to delta on newbranch" + + local orig_commit1=`git_show_parent_commit $testroot/repo` + local orig_commit2=`git_show_head $testroot/repo` + local orig_author_time2=`git_show_author_time $testroot/repo` + + (cd $testroot/repo && git checkout -q master) + echo "modified zeta on master" > $testroot/repo/epsilon/zeta + git_commit $testroot/repo -m "committing to zeta on master" + local master_commit=`git_show_head $testroot/repo` + + got checkout $testroot/repo $testroot/wt > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + test_done "$testroot" "$ret" + return 1 + fi + + # Backdate the file alpha to an earlier version. + # This sets the work tree's base commit ID back to $commit0, + # which is out-of-date with respect to the master branch. + (cd $testroot/wt && got update -c $commit0 alpha > /dev/null) + + # Rebase into an out-of-date work tree should be refused. + (cd $testroot/wt && got rebase newbranch > $testroot/stdout \ + 2> $testroot/stderr) + ret=$? + if [ $ret -eq 0 ]; then + echo "rebase succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + echo -n > $testroot/stdout.expected + echo -n "got: work tree must be updated before it can be used to " \ + > $testroot/stderr.expected + echo "rebase a branch" >> $testroot/stderr.expected + cmp -s $testroot/stderr.expected $testroot/stderr + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stderr.expected $testroot/stderr + fi + test_done "$testroot" "$ret" } test_parseargs "$@" @@ -1857,3 +1908,4 @@ run_test test_rebase_resets_committer run_test test_rebase_no_author_info run_test test_rebase_nonbranch run_test test_rebase_umask +run_test test_rebase_out_of_date2