Commit Diff


commit - 8eef427678ef08e2fe74a9a4c98f0a1190df5d73
commit + f4a34a6642e41574ef08b632dcd005bfb35d02dd
blob - 6a3561fd9a97335e82546809332e4456c2726802
blob + 60b728087babd46e2f9a0783a6419cac467c8bac
--- 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 - 98916ccd702956265435b4c7e6746ee08c9feec6
blob + b1247aebc0eae9d0eb1206fbf89ef9da12318288
--- regress/cmdline/rebase.sh
+++ regress/cmdline/rebase.sh
@@ -791,7 +791,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"
 }
 
@@ -881,8 +934,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