summaryrefslogtreecommitdiff
path: root/packages/core/src
diff options
context:
space:
mode:
authorAnas H. Sulaiman <[email protected]>2025-06-13 12:45:07 -0400
committerGitHub <[email protected]>2025-06-13 12:45:07 -0400
commit9d04e04bc0e2b3342d9d82efbaf8dba0160790d5 (patch)
tree307c16bfd15f5f0282f5eafb0f4eec917a3670c6 /packages/core/src
parent2a1ad1f5d961b9f9593a6016eea7dd398bdeed0b (diff)
remove redundant `isGitRepository` helper` (#1012)
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/tools/grep.ts44
1 files changed, 2 insertions, 42 deletions
diff --git a/packages/core/src/tools/grep.ts b/packages/core/src/tools/grep.ts
index 43ec579a..f7de190b 100644
--- a/packages/core/src/tools/grep.ts
+++ b/packages/core/src/tools/grep.ts
@@ -14,6 +14,7 @@ import { BaseTool, ToolResult } from './tools.js';
import { SchemaValidator } from '../utils/schemaValidator.js';
import { makeRelative, shortenPath } from '../utils/paths.js';
import { getErrorMessage, isNodeError } from '../utils/errors.js';
+import { isGitRepository } from '../utils/gitUtils.js';
// --- Interfaces ---
@@ -263,47 +264,6 @@ export class GrepTool extends BaseTool<GrepToolParams, ToolResult> {
}
/**
- * Checks if a directory or its parent directories contain a .git folder.
- * @param {string} dirPath Absolute path to the directory to check.
- * @returns {Promise<boolean>} True if it's a Git repository, false otherwise.
- */
- private async isGitRepository(dirPath: string): Promise<boolean> {
- let currentPath = path.resolve(dirPath);
- const root = path.parse(currentPath).root;
-
- try {
- while (true) {
- const gitPath = path.join(currentPath, '.git');
- try {
- const stats = await fsPromises.stat(gitPath);
- if (stats.isDirectory() || stats.isFile()) {
- return true;
- }
- // If .git exists but isn't a file/dir, something is weird, return false
- return false;
- } catch (error: unknown) {
- if (!isNodeError(error) || error.code !== 'ENOENT') {
- console.debug(
- `Error checking for .git in ${currentPath}: ${error}`,
- );
- return false;
- }
- }
-
- if (currentPath === root) {
- break;
- }
- currentPath = path.dirname(currentPath);
- }
- } catch (error: unknown) {
- console.debug(
- `Error traversing directory structure upwards from ${dirPath}: ${getErrorMessage(error)}`,
- );
- }
- return false;
- }
-
- /**
* Parses the standard output of grep-like commands (git grep, system grep).
* Expects format: filePath:lineNumber:lineContent
* Handles colons within file paths and line content correctly.
@@ -390,7 +350,7 @@ export class GrepTool extends BaseTool<GrepToolParams, ToolResult> {
try {
// --- Strategy 1: git grep ---
- const isGit = await this.isGitRepository(absolutePath);
+ const isGit = isGitRepository(absolutePath);
const gitAvailable = isGit && (await this.isCommandAvailable('git'));
if (gitAvailable) {