Commit Diff


commit - 5d7e2cd05a57bd094a600963db2c19da60278dae
commit + 82d979c595ed3516ee1dbff4500ccd8cf84848ce
blob - 02099e4c91aac5a1e9d1803898d1c74c33234d0d
blob + 389f9d08088c16749e26653373e02b47dbea55f0
--- got/got.c
+++ got/got.c
@@ -9147,12 +9147,41 @@ cmd_rebase(int argc, char *argv[])
 				goto done;
 			error = NULL;
 		} else {
-			static char msg[128];
-			snprintf(msg, sizeof(msg),
-			    "%s is already based on %s",
+			struct got_pathlist_head paths;
+			printf("%s is already based on %s\n",
 			    got_ref_get_name(branch),
 			    got_worktree_get_head_ref_name(worktree));
-			error = got_error_msg(GOT_ERR_SAME_BRANCH, msg);
+			error = switch_head_ref(branch, branch_head_commit_id,
+			    worktree, repo);
+			if (error)
+				goto done;
+			error = got_worktree_set_base_commit_id(worktree, repo,
+			    branch_head_commit_id);
+			if (error)
+				goto done;
+			TAILQ_INIT(&paths);
+			error = got_pathlist_append(&paths, "", NULL);
+			if (error)
+				goto done;
+			error = got_worktree_checkout_files(worktree,
+			    &paths, repo, update_progress, &upa,
+			    check_cancelled, NULL);
+			got_pathlist_free(&paths);
+			if (error)
+				goto done;
+			if (upa.did_something) {
+				char *id_str;
+				error = got_object_id_str(&id_str,
+				    branch_head_commit_id);
+				if (error)
+					goto done;
+				printf("Updated to %s: %s\n",
+				    got_worktree_get_head_ref_name(worktree),
+				    id_str);
+				free(id_str);
+			} else
+				printf("Already up-to-date\n");
+			print_update_progress_stats(&upa);
 			goto done;
 		}
 		error = got_worktree_rebase_prepare(&new_base_branch,
blob - 0531881d4d4855f22d5d2acb605d1575c537a94d
blob + d37274f3b583e7a546109ca74441188e9e6ee40f
--- regress/cmdline/rebase.sh
+++ regress/cmdline/rebase.sh
@@ -246,11 +246,18 @@ test_rebase_ancestry_check() {
 	(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 newbranch_id=`git_show_head $testroot/repo`
 
 	(cd $testroot/wt && got rebase newbranch > $testroot/stdout \
 		2> $testroot/stderr)
 
-	echo -n > $testroot/stdout.expected
+	echo "refs/heads/newbranch is already based on refs/heads/master" \
+		> $testroot/stdout.expected
+	echo "Switching work tree from refs/heads/master to refs/heads/newbranch" \
+		>> $testroot/stdout.expected
+	echo "U  gamma/delta" >> $testroot/stdout.expected
+	echo "Updated to refs/heads/newbranch: ${newbranch_id}" \
+		>> $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then
@@ -259,8 +266,7 @@ test_rebase_ancestry_check() {
 		return 1
 	fi
 
-	echo "got: refs/heads/newbranch is already based on refs/heads/master" \
-		> $testroot/stderr.expected
+	echo -n > $testroot/stderr.expected
 	cmp -s $testroot/stderr.expected $testroot/stderr
 	ret="$?"
 	if [ "$ret" != "0" ]; then