commit 67ba61612157092fbe0f8c4a02b60faf31967061 from: Stefan Sperling date: Fri Apr 08 09:14:02 2022 UTC leave work tree in a usable state after 'got rebase' fails path-prefix checks reported by naddy commit - 9d34261edbfb3574a41b29233fdc722b526ea226 commit + 67ba61612157092fbe0f8c4a02b60faf31967061 blob - d75debc645426b7976fa18ab9a53d9d7e3391ba8 blob + c317c15e1db828dea457cd13aa02cfba0c723b80 --- got/got.c +++ got/got.c @@ -9454,10 +9454,6 @@ cmd_rebase(int argc, char *argv[]) print_update_progress_stats(&upa); goto done; } - error = got_worktree_rebase_prepare(&new_base_branch, - &tmp_branch, &fileindex, worktree, branch, repo); - if (error) - goto done; } commit_id = branch_head_commit_id; @@ -9468,16 +9464,6 @@ cmd_rebase(int argc, char *argv[]) parent_ids = got_object_commit_get_parent_ids(commit); pid = STAILQ_FIRST(parent_ids); if (pid == NULL) { - if (!continue_rebase) { - error = got_worktree_rebase_abort(worktree, fileindex, - repo, new_base_branch, abort_progress, &upa); - if (error) - goto done; - printf("Rebase of %s aborted\n", - got_ref_get_name(branch)); - print_merge_progress_stats(&upa); - - } error = got_error(GOT_ERR_EMPTY_REBASE); goto done; } @@ -9488,6 +9474,13 @@ cmd_rebase(int argc, char *argv[]) commit = NULL; if (error) goto done; + + if (!continue_rebase) { + error = got_worktree_rebase_prepare(&new_base_branch, + &tmp_branch, &fileindex, worktree, branch, repo); + if (error) + goto done; + } if (STAILQ_EMPTY(&commits)) { if (continue_rebase) { blob - 5e74b959165a7294b2db81a0c1423f2573dd875f blob + 350e19ca9e343605f4497444e665c380a5212b8a --- regress/cmdline/rebase.sh +++ regress/cmdline/rebase.sh @@ -788,7 +788,60 @@ test_rebase_path_prefix() { ret=$? if [ $ret -ne 0 ]; then diff -u $testroot/stderr.expected $testroot/stderr + test_done "$testroot" "$ret" + return 1 + fi + + # rebase should succeed when using a complete work tree + got checkout $testroot/repo $testroot/wt2 > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + test_done "$testroot" "$ret" + return 1 + fi + + (cd $testroot/wt2 && got rebase newbranch \ + > $testroot/stdout 2> $testroot/stderr) + + (cd $testroot/repo && git checkout -q newbranch) + local new_commit1=`git_show_parent_commit $testroot/repo` + local new_commit2=`git_show_head $testroot/repo` + + local short_orig_commit2=`trim_obj_id 28 $orig_commit2` + local short_new_commit2=`trim_obj_id 28 $new_commit2` + + echo "G gamma/delta" > $testroot/stdout.expected + echo -n "$short_orig_commit2 -> $short_new_commit2" \ + >> $testroot/stdout.expected + echo ": committing to delta on newbranch" \ + >> $testroot/stdout.expected + echo "Switching work tree to refs/heads/newbranch" \ + >> $testroot/stdout.expected + + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 fi + + # the first work tree should remain usable + (cd $testroot/wt && got update -b master \ + > $testroot/stdout 2> $testroot/stderr) + ret=$? + if [ $ret -ne 0 ]; then + echo "update failed unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + + echo 'Already up-to-date' > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi test_done "$testroot" "$ret" } @@ -878,8 +931,7 @@ test_rebase_no_commits_to_rebase() { return 1 fi - echo "Rebase of refs/heads/newbranch aborted" \ - > $testroot/stdout.expected + echo -n > $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout ret=$? if [ $ret -ne 0 ]; then