From 9d04e04bc0e2b3342d9d82efbaf8dba0160790d5 Mon Sep 17 00:00:00 2001 From: "Anas H. Sulaiman" Date: Fri, 13 Jun 2025 12:45:07 -0400 Subject: [PATCH] remove redundant `isGitRepository` helper` (#1012) --- packages/core/src/tools/grep.ts | 44 ++------------------------------- 1 file 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 --- @@ -262,47 +263,6 @@ export class GrepTool extends BaseTool { }); } - /** - * Checks if a directory or its parent directories contain a .git folder. - * @param {string} dirPath Absolute path to the directory to check. - * @returns {Promise} True if it's a Git repository, false otherwise. - */ - private async isGitRepository(dirPath: string): Promise { - 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 @@ -390,7 +350,7 @@ export class GrepTool extends BaseTool { try { // --- Strategy 1: git grep --- - const isGit = await this.isGitRepository(absolutePath); + const isGit = isGitRepository(absolutePath); const gitAvailable = isGit && (await this.isCommandAvailable('git')); if (gitAvailable) {