commit 49a1ae4b7fbd435b06a58d71186f4675d399e2c7 from: Stefan Sperling date: Sun Jan 08 12:27:04 2023 UTC fix 'got rebase' not detecting an out-of-date work tree in some cases ok jamsek, op commit - dae92a245f6e4d18c4c75048d6ca667d78083cc4 commit + 49a1ae4b7fbd435b06a58d71186f4675d399e2c7 blob - 4e1c7e548dd68228986b5949d2af99e7e032a6ba blob + 9a89d5b62f1635fb4b385534abdd217ee4a06611 --- 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 - f809879812d293f5b44a4ad0e1a299f1384dc027 blob + f87f1d9e51fc63c6ebf7cc957f15ec52ddd15420 --- regress/cmdline/rebase.sh +++ regress/cmdline/rebase.sh @@ -1832,6 +1832,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 "$@" @@ -1854,3 +1905,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