From: Omar Polo Subject: "no commits to rebase" when rebasing on the initial commit To: gameoftrees@openbsd.org Date: Tue, 31 Jan 2023 12:01:00 +0100 apparently 'got rebase' fails when rebasing directly on top of the initial repository. Test below simulates it, uncomment the un-indented lines to make it pass. this seems due to this bit --- got/got.c +++ got/got.c @@ -11226,11 +11226,8 @@ cmd_rebase(int argc, char *argv[]) parent_ids = got_object_commit_get_parent_ids(commit); pid = STAILQ_FIRST(parent_ids); - if (pid == NULL) { - error = got_error(GOT_ERR_EMPTY_REBASE); - goto done; - } - error = collect_commits(&commits, commit_id, &pid->id, + error = collect_commits(&commits, commit_id, + pid ? &pid->id : commit_id, yca_id, got_worktree_get_path_prefix(worktree), GOT_ERR_REBASE_PATH, repo); got_object_commit_close(commit); and that change makes the test pass, but makes test_rebase_no_commits_to_rebase pass too which is not good. My testcase is fundamentally the opposite of no_commits_to_rebase. no idea how to go from here :( Thanks! Omar Polo diff /home/op/w/gotd commit - 0d98195bc8c97f44f5635b97b8020dd934f677f0 path + /home/op/w/gotd blob - f87f1d9e51fc63c6ebf7cc957f15ec52ddd15420 file + regress/cmdline/rebase.sh --- regress/cmdline/rebase.sh +++ regress/cmdline/rebase.sh @@ -1885,6 +1885,42 @@ test_parseargs "$@" test_done "$testroot" "$ret" } +test_rebase_one_commit() { + local testroot=`test_init rebase_one_commit` + + if ! got checkout $testroot/repo $testroot/wt >/dev/null; then + test_done "$testroot" 1 + return 1 + fi + +# decomment to make it work: +#echo "modified alpha" >$testroot/wt/alpha +#(cd $testroot/wt && got commit -m 'edit alpha on master') >/dev/null + + (cd $testroot/wt && got branch newbranch) >/dev/null + + echo "modified alpha on newbranch" >$testroot/wt/alpha + (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null + (cd $testroot/wt && got update) >/dev/null + local commit=`git_show_branch_head $testroot/repo newbranch` + + (cd $testroot/wt && got rebase master) >$testroot/stderr \ + 2> /dev/null + + echo "Forwarding refs/heads/master to commit $commit" \ + >$testroot/stderr.expected + echo "Switching work tree to refs/heads/master" \ + >> $testroot/stderr.expected + + if ! cmp -s $testroot/stderr.expected $testroot/stderr; then + diff -u $testroot/stderr.expected $testroot/stderr + test_done "$testroot" 1 + return 1 + fi + + test_done "$testroot" 0 +} + test_parseargs "$@" run_test test_rebase_basic run_test test_rebase_ancestry_check @@ -1906,3 +1942,4 @@ run_test test_rebase_out_of_date2 run_test test_rebase_nonbranch run_test test_rebase_umask run_test test_rebase_out_of_date2 +run_test test_rebase_one_commit