Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix getGitPath to handle nested GitLab group paths (#13006)

John-Mason P. Shackelfordc7ff56046554
diff --git a/frontend/__tests__/utils/get-git-path.test.ts b/frontend/__tests__/utils/get-git-path.test.ts
new file mode 100644
index 0000000000..d1507228fc
--- /dev/null
+++ b/frontend/__tests__/utils/get-git-path.test.ts
@@ -0,0 +1,28 @@
+import { describe, it, expect } from "vitest";
+import { getGitPath } from "#/utils/get-git-path";
+
+describe("getGitPath", () => {
+ it("should return /workspace/project when no repository is selected", () => {
+ expect(getGitPath(null)).toBe("/workspace/project");
+ expect(getGitPath(undefined)).toBe("/workspace/project");
+ });
+
+ it("should handle standard owner/repo format (GitHub)", () => {
+ expect(getGitPath("OpenHands/OpenHands")).toBe("/workspace/project/OpenHands");
+ expect(getGitPath("facebook/react")).toBe("/workspace/project/react");
+ });
+
+ it("should handle nested group paths (GitLab)", () => {
+ expect(getGitPath("modernhealth/frontend-guild/pan")).toBe("/workspace/project/pan");
+ expect(getGitPath("group/subgroup/repo")).toBe("/workspace/project/repo");
+ expect(getGitPath("a/b/c/d/repo")).toBe("/workspace/project/repo");
+ });
+
+ it("should handle single segment paths", () => {
+ expect(getGitPath("repo")).toBe("/workspace/project/repo");
+ });
+
+ it("should handle empty string", () => {
+ expect(getGitPath("")).toBe("/workspace/project");
+ });
+});
diff --git a/frontend/src/utils/get-git-path.ts b/frontend/src/utils/get-git-path.ts
index 157dbeb271..15c8ff947e 100644
--- a/frontend/src/utils/get-git-path.ts
+++ b/frontend/src/utils/get-git-path.ts
@@ -3,7 +3,7 @@
* If a repository is selected, returns /workspace/project/{repo-name}
* Otherwise, returns /workspace/project
*
- * @param selectedRepository The selected repository (e.g., "OpenHands/OpenHands" or "owner/repo")
+ * @param selectedRepository The selected repository (e.g., "OpenHands/OpenHands", "owner/repo", or "group/subgroup/repo")
* @returns The git path to use
*/
export function getGitPath(
@@ -13,10 +13,10 @@ export function getGitPath(
return "/workspace/project";
}
- // Extract the repository name from "owner/repo" format
- // The folder name is the second part after "/"
+ // Extract the repository name from the path
+ // The folder name is always the last part (handles both "owner/repo" and "group/subgroup/repo" formats)
const parts = selectedRepository.split("/");
- const repoName = parts.length > 1 ? parts[1] : parts[0];
+ const repoName = parts[parts.length - 1];
return `/workspace/project/${repoName}`;
}