Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: show folder name in repo button for non-git workspaces (#415)

Hiep Le1097c46139b4
diff --git a/__tests__/components/features/chat/git-control-bar-repo-button.test.tsx b/__tests__/components/features/chat/git-control-bar-repo-button.test.tsx
index 5a6d15e84b..05484205c8 100644
--- a/__tests__/components/features/chat/git-control-bar-repo-button.test.tsx
+++ b/__tests__/components/features/chat/git-control-bar-repo-button.test.tsx
@@ -92,6 +92,20 @@ describe("GitControlBarRepoButton", () => {
});
});
+ describe("when only a workspace name is provided", () => {
+ it("should display the workspace name as the button text", () => {
+ render(
+ <GitControlBarRepoButton
+ selectedRepository={null}
+ gitProvider={null}
+ workspaceName="test"
+ />,
+ );
+
+ expect(screen.getByText("test")).toBeInTheDocument();
+ });
+ });
+
describe("when no repository is connected", () => {
it("should render as a button with 'No Repo Connected' text", () => {
render(
diff --git a/src/components/features/chat/git-control-bar-repo-button.tsx b/src/components/features/chat/git-control-bar-repo-button.tsx
index 81a0343b2b..22632d763e 100644
--- a/src/components/features/chat/git-control-bar-repo-button.tsx
+++ b/src/components/features/chat/git-control-bar-repo-button.tsx
@@ -10,6 +10,7 @@ import { useSettings } from "#/hooks/query/use-settings";
interface GitControlBarRepoButtonProps {
selectedRepository: string | null | undefined;
gitProvider: Provider | null | undefined;
+ workspaceName?: string | null;
onClick?: () => void;
disabled?: boolean;
}
@@ -17,6 +18,7 @@ interface GitControlBarRepoButtonProps {
export function GitControlBarRepoButton({
selectedRepository,
gitProvider,
+ workspaceName,
onClick,
disabled,
}: GitControlBarRepoButtonProps) {
@@ -38,7 +40,8 @@ export function GitControlBarRepoButton({
? constructRepositoryUrl(gitProvider, selectedRepository, providerHost)
: undefined;
- const buttonText = selectedRepository || t(I18nKey.COMMON$NO_REPO_CONNECTED);
+ const buttonText =
+ selectedRepository || workspaceName || t(I18nKey.COMMON$NO_REPO_CONNECTED);
if (hasLinkableRepo) {
return (
@@ -74,7 +77,7 @@ export function GitControlBarRepoButton({
onClick={onClick}
disabled={disabled}
className={cn(
- "group flex flex-row items-center justify-between gap-2 pl-2.5 pr-2.5 py-1 rounded-[100px] flex-1 truncate relative min-w-[170px]",
+ "group flex flex-row items-center justify-between gap-2 pl-2.5 pr-2.5 py-1 rounded-[100px] truncate relative",
"border border-[rgba(71,74,84,0.50)] bg-transparent",
disabled
? "cursor-not-allowed opacity-50"
diff --git a/src/components/features/chat/git-control-bar.tsx b/src/components/features/chat/git-control-bar.tsx
index 4bb4912982..0a3a15d682 100644
--- a/src/components/features/chat/git-control-bar.tsx
+++ b/src/components/features/chat/git-control-bar.tsx
@@ -20,6 +20,7 @@ import { useConversationId } from "#/hooks/use-conversation-id";
import { displayErrorToast } from "#/utils/custom-toast-handlers";
import { useHomeStore } from "#/stores/home-store";
import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";
+import { getStoredConversationMetadata } from "#/api/conversation-metadata-store";
interface GitControlBarProps {
onSuggestionsClick: (value: string) => void;
@@ -70,6 +71,19 @@ export function GitControlBar({ onSuggestionsClick }: GitControlBarProps) {
const selectedBranch =
conversationBranch || localGitInfo?.branch || undefined;
+ // For folder-only conversations (no remote repo), surface the basename of
+ // the originally attached workspace path so the button reads e.g. "test"
+ // rather than "No Repo Connected". `selected_workspace` is recorded at
+ // conversation creation; we prefer it over `workspace.working_dir` because
+ // the latter may point at a worktree subdir.
+ const storedMetadata = conversation?.id
+ ? getStoredConversationMetadata(conversation.id)
+ : null;
+ const workspacePath = storedMetadata?.selected_workspace ?? null;
+ const workspaceName = workspacePath
+ ? workspacePath.replace(/\/+$/, "").split("/").pop() || null
+ : null;
+
// Keep git actions (pull/push/PR) gated on the conversation actually being
// associated with a known git provider β€” local-only repos shouldn't enable
// those flows, so we only flip `hasRepository` for conversation/task data.
@@ -148,6 +162,7 @@ export function GitControlBar({ onSuggestionsClick }: GitControlBarProps) {
<GitControlBarRepoButton
selectedRepository={selectedRepository}
gitProvider={gitProvider}
+ workspaceName={workspaceName}
onClick={() => setIsOpenRepoModalOpen(true)}
disabled={!isConversationReady}
/>