-
Notifications
You must be signed in to change notification settings - Fork 0
task/switch-working-directory-after-clone #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||
| import * as vscode from "vscode"; | ||||||||||||||||||||||||||
| import * as path from "path"; | ||||||||||||||||||||||||||
| import simpleGit, { GitConfigScope } from "simple-git"; | ||||||||||||||||||||||||||
| import { hostname } from "os"; | ||||||||||||||||||||||||||
| import { cloneByGivenURL } from "../participation/cloning.service"; | ||||||||||||||||||||||||||
|
|
@@ -32,15 +33,20 @@ export async function initTheia() { | |||||||||||||||||||||||||
| vscode.commands.executeCommand("setContext", "scorpio.theia.givenExercise", true); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // clone repository | ||||||||||||||||||||||||||
| // clone repository and set it as the workspace folder | ||||||||||||||||||||||||||
| if (theiaEnv.GIT_URI) { | ||||||||||||||||||||||||||
| const workspaceFolderUri = getWorkspaceFolder(); | ||||||||||||||||||||||||||
| if (!workspaceFolderUri) { | ||||||||||||||||||||||||||
| vscode.window.showErrorMessage("No workspace folder available to clone repository"); | ||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| cloneByGivenURL(theiaEnv.GIT_URI, workspaceFolderUri.fsPath); | ||||||||||||||||||||||||||
| // Skip if the workspace is already the cloned repo (window reloads after openFolder) | ||||||||||||||||||||||||||
| const repoName = path.basename(theiaEnv.GIT_URI.pathname, ".git"); | ||||||||||||||||||||||||||
| if (path.basename(workspaceFolderUri.fsPath) !== repoName) { | ||||||||||||||||||||||||||
|
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basename-only guard can skip cloning in valid first-run scenarios. At Line 45-46, clone is skipped when folder name matches the repo name, even if the folder is not actually the cloned repo (e.g., empty workspace named the same as repo). This can leave users in an empty/non-repo workspace. Suggested hardening- const repoName = path.basename(theiaEnv.GIT_URI.pathname, ".git");
- if (path.basename(workspaceFolderUri.fsPath) !== repoName) {
+ const repoName = path.basename(theiaEnv.GIT_URI.pathname, ".git");
+ const sameFolderName = path.basename(workspaceFolderUri.fsPath) === repoName;
+ const hasGitDir = await vscode.workspace.fs
+ .stat(vscode.Uri.file(path.join(workspaceFolderUri.fsPath, ".git")))
+ .then(() => true)
+ .catch(() => false);
+
+ if (!(sameFolderName && hasGitDir)) {
const clonePath = await cloneByGivenURL(theiaEnv.GIT_URI, workspaceFolderUri.fsPath);
await vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(clonePath));
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| const clonePath = await cloneByGivenURL(theiaEnv.GIT_URI, workspaceFolderUri.fsPath); | ||||||||||||||||||||||||||
|
Comment on lines
+44
to
+47
|
||||||||||||||||||||||||||
| await vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(clonePath)); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+47
to
+49
|
||||||||||||||||||||||||||
| const clonePath = await cloneByGivenURL(theiaEnv.GIT_URI, workspaceFolderUri.fsPath); | |
| await vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(clonePath)); | |
| } | |
| try { | |
| const clonePath = await cloneByGivenURL(theiaEnv.GIT_URI, workspaceFolderUri.fsPath); | |
| await vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(clonePath)); | |
| } catch (e: any) { | |
| vscode.window.showErrorMessage(`Failed to clone repository: ${e?.message ?? "Unknown error"}`); | |
| return; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/theia/theia.ts` around lines 47 - 49, The caller assumes cloneByGivenURL
throws on failure but cloning.service.ts swallows errors and still returns a
path, so vscode.commands.executeCommand("vscode.openFolder", ...) can run after
a failed clone; update the caller in theia.ts to defensively verify the clone
succeeded before calling openFolder: check the result from cloneByGivenURL
(e.g., validate the returned clonePath exists and/or have cloneByGivenURL return
an explicit success flag), and only call
vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(clonePath))
when that verification passes; use the existing function names cloneByGivenURL
and vscode.commands.executeCommand("vscode.openFolder") to locate and change the
logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.basename(theiaEnv.GIT_URI.pathname, ".git")will return an empty string ifGIT_URIends with a trailing slash (e.g.,.../repo.git/). Consider normalizing the pathname first (trim trailing/) before derivingrepoName, otherwise the guard and clone path computation can break.