leave work tree in a usable state after 'got rebase' fails path-prefix checks reported by naddy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
diff --git a/got/got.c b/got/got.c
index d75debc..c317c15 100644
--- a/got/got.c
+++ b/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;
}
@@ -9489,6 +9475,13 @@ cmd_rebase(int argc, char *argv[])
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) {
error = rebase_complete(worktree, fileindex,
diff --git a/regress/cmdline/rebase.sh b/regress/cmdline/rebase.sh
index 5e74b95..350e19c 100755
--- a/regress/cmdline/rebase.sh
+++ b/regress/cmdline/rebase.sh
@@ -788,6 +788,59 @@ 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