mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-16 00:51:25 -07:00
Use consistent param names (#12517)
This commit is contained in:
committed by
GitHub
parent
5f1208ad81
commit
f05d937f39
@@ -233,7 +233,7 @@ export function shortenPath(filePath: string, maxLen: number = 35): string {
|
||||
|
||||
/**
|
||||
* Calculates the relative path from a root directory to a target path.
|
||||
* Ensures both paths are resolved before calculating.
|
||||
* If targetPath is relative, it is returned as-is.
|
||||
* Returns '.' if the target path is the same as the root directory.
|
||||
*
|
||||
* @param targetPath The absolute or relative path to make relative.
|
||||
@@ -244,10 +244,11 @@ export function makeRelative(
|
||||
targetPath: string,
|
||||
rootDirectory: string,
|
||||
): string {
|
||||
const resolvedTargetPath = path.resolve(targetPath);
|
||||
if (!path.isAbsolute(targetPath)) {
|
||||
return targetPath;
|
||||
}
|
||||
const resolvedRootDirectory = path.resolve(rootDirectory);
|
||||
|
||||
const relativePath = path.relative(resolvedRootDirectory, resolvedTargetPath);
|
||||
const relativePath = path.relative(resolvedRootDirectory, targetPath);
|
||||
|
||||
// If the paths are the same, path.relative returns '', return '.' instead
|
||||
return relativePath || '.';
|
||||
|
||||
@@ -68,7 +68,7 @@ describe('WorkspaceContext with real filesystem', () => {
|
||||
it('should resolve relative paths to absolute', () => {
|
||||
const workspaceContext = new WorkspaceContext(cwd);
|
||||
const relativePath = path.relative(cwd, otherDir);
|
||||
workspaceContext.addDirectory(relativePath, cwd);
|
||||
workspaceContext.addDirectory(relativePath);
|
||||
const directories = workspaceContext.getDirectories();
|
||||
|
||||
expect(directories).toEqual([cwd, otherDir]);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
import { isNodeError } from '../utils/errors.js';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import * as process from 'node:process';
|
||||
import { debugLogger } from './debugLogger.js';
|
||||
|
||||
export type Unsubscribe = () => void;
|
||||
@@ -24,11 +23,14 @@ export class WorkspaceContext {
|
||||
|
||||
/**
|
||||
* Creates a new WorkspaceContext with the given initial directory and optional additional directories.
|
||||
* @param directory The initial working directory (usually cwd)
|
||||
* @param targetDir The initial working directory (usually cwd)
|
||||
* @param additionalDirectories Optional array of additional directories to include
|
||||
*/
|
||||
constructor(directory: string, additionalDirectories: string[] = []) {
|
||||
this.addDirectory(directory);
|
||||
constructor(
|
||||
readonly targetDir: string,
|
||||
additionalDirectories: string[] = [],
|
||||
) {
|
||||
this.addDirectory(targetDir);
|
||||
for (const additionalDirectory of additionalDirectories) {
|
||||
this.addDirectory(additionalDirectory);
|
||||
}
|
||||
@@ -66,9 +68,9 @@ export class WorkspaceContext {
|
||||
* @param directory The directory path to add (can be relative or absolute)
|
||||
* @param basePath Optional base path for resolving relative paths (defaults to cwd)
|
||||
*/
|
||||
addDirectory(directory: string, basePath: string = process.cwd()): void {
|
||||
addDirectory(directory: string): void {
|
||||
try {
|
||||
const resolved = this.resolveAndValidateDir(directory, basePath);
|
||||
const resolved = this.resolveAndValidateDir(directory);
|
||||
if (this.directories.has(resolved)) {
|
||||
return;
|
||||
}
|
||||
@@ -81,13 +83,8 @@ export class WorkspaceContext {
|
||||
}
|
||||
}
|
||||
|
||||
private resolveAndValidateDir(
|
||||
directory: string,
|
||||
basePath: string = process.cwd(),
|
||||
): string {
|
||||
const absolutePath = path.isAbsolute(directory)
|
||||
? directory
|
||||
: path.resolve(basePath, directory);
|
||||
private resolveAndValidateDir(directory: string): string {
|
||||
const absolutePath = path.resolve(this.targetDir, directory);
|
||||
|
||||
if (!fs.existsSync(absolutePath)) {
|
||||
throw new Error(`Directory does not exist: ${absolutePath}`);
|
||||
@@ -154,7 +151,7 @@ export class WorkspaceContext {
|
||||
*/
|
||||
private fullyResolvedPath(pathToCheck: string): string {
|
||||
try {
|
||||
return fs.realpathSync(pathToCheck);
|
||||
return fs.realpathSync(path.resolve(this.targetDir, pathToCheck));
|
||||
} catch (e: unknown) {
|
||||
if (
|
||||
isNodeError(e) &&
|
||||
|
||||
Reference in New Issue
Block a user