π OpenHands: AI-Driven Development
fix: show folder name for local-only repos in git control bar (#322)
Vasco Schiavo9106bc30daca
diff --git a/__tests__/api/agent-server-adapter.test.ts b/__tests__/api/agent-server-adapter.test.tsindex e61cf5b878..ec1a445998 100644--- a/__tests__/api/agent-server-adapter.test.ts+++ b/__tests__/api/agent-server-adapter.test.ts@@ -197,7 +197,7 @@ describe("buildStartConversationRequest", () => {expect(payload.workspace.working_dir).toBe(workingDir);});- it("always requests a git worktree for new conversations", () => {+ it("requests a git worktree by default for new conversations", () => {const payload = buildStartConversationRequest({settings: {...DEFAULT_SETTINGS,@@ -211,6 +211,21 @@ describe("buildStartConversationRequest", () => {expect(payload.worktree).toBe(true);});+ it("skips the worktree when the caller opts out (non-git workspace)", () => {+ const payload = buildStartConversationRequest({+ settings: {+ ...DEFAULT_SETTINGS,+ agent_settings: {+ ...DEFAULT_SETTINGS.agent_settings,+ llm: { model: "nested-model" },+ },+ },+ worktree: false,+ }) as { worktree: boolean };++ expect(payload.worktree).toBe(false);+ });+it("forwards supported conversation runtime fields from nested settings", () => {const payload = buildStartConversationRequest({settings: {diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.tsindex 5429a40de1..16e5b2d32b 100644--- a/src/api/agent-server-adapter.ts+++ b/src/api/agent-server-adapter.ts@@ -377,6 +377,13 @@ export interface StartConversationOptions {* The actual values are fetched at runtime via LookupSecret.*/customSecrets?: Array<{ name: string; description?: string }>;+ /**+ * Whether to request a dedicated git worktree for the conversation.+ * Defaults to true. Set to false for local-only workspaces that aren't+ * git repos (or have no commits), where `git worktree add HEAD` would+ * fail and prevent the conversation from starting.+ */+ worktree?: boolean;}export function buildStartConversationRequest(@@ -416,7 +423,7 @@ export function buildStartConversationRequest(: 500,stuck_detection: true,autotitle: true,- worktree: true,+ worktree: options.worktree ?? true,};// Add secrets_encrypted flag if secrets are encrypted@@ -498,6 +505,7 @@ export async function buildStartConversationRequestWithEncryptedSettings(optionsplugins?: PluginSpec[];conversationId?: string;workingDir?: string;+ worktree?: boolean;}): Promise<Record<string, unknown>> {// Import SecretsService dynamically to avoid circular dependenciesconst { SecretsService } = await import("./secrets-service");diff --git a/src/api/conversation-service/agent-server-conversation-service.api.ts b/src/api/conversation-service/agent-server-conversation-service.api.tsindex fd3c28b43c..e702aa856c 100644--- a/src/api/conversation-service/agent-server-conversation-service.api.ts+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts@@ -119,6 +119,12 @@ class AgentServerConversationService {plugins,conversationId,workingDir,+ // Only request a per-conversation git worktree when the user has+ // attached a real repository. Local-only workspaces (no+ // `selected_repository`) may not be git checkouts, in which case+ // `git worktree add HEAD` on the server fails and the conversation+ // never starts.+ worktree: !!metadata?.selected_repository,});const response = await createHttpClient().post<DirectConversationInfo>(diff --git a/src/hooks/query/use-local-git-info.ts b/src/hooks/query/use-local-git-info.tsindex 1b91fdd776..7fe440aab9 100644--- a/src/hooks/query/use-local-git-info.ts+++ b/src/hooks/query/use-local-git-info.ts@@ -13,21 +13,12 @@ export interface LocalGitInfo {remoteUrl: string | null;}-const EMPTY_LOCAL_GIT_INFO: LocalGitInfo = {- repository: null,- branch: null,- provider: null,- remoteUrl: null,-};-/*** For local-workspace conversations (no `selected_repository` recorded on the* conversation), shell out via the agent server's bash-execute endpoint to* read `git remote get-url origin` and the current branch from the- * conversation's working directory.- *- * Returns `null` fields when the working dir is not a git checkout β callers- * should treat that the same as "no repo detected".+ * conversation's working directory. Falls back to the working-dir basename+ * when the dir is not a git checkout.*/export const useLocalGitInfo = () => {const { data: conversation } = useActiveConversation();@@ -68,11 +59,12 @@ export const useLocalGitInfo = () => {branchResult.exit_code === 0 ? branchResult.stdout.trim() : "";const branch = rawBranch && rawBranch !== "HEAD" ? rawBranch : null;- if (!remoteUrl && !branch) return EMPTY_LOCAL_GIT_INFO;-const parsedRemote = parseGitRemoteUrl(remoteUrl);+ // Fall back to the working-dir basename so the repo button shows a+ // name even when there's no `origin` remote or no git at all.+ const folderName = workingDir?.split("/").filter(Boolean).pop() ?? null;return {- repository: parsedRemote?.repository ?? null,+ repository: parsedRemote?.repository ?? folderName,provider: parsedRemote?.provider ?? null,remoteUrl: remoteUrl || null,branch,