mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2025-12-22 15:54:20 +01:00
Merge pull request #26 from d-kimuson/fix/git-diff-view-subdirectory
This commit is contained in:
@@ -367,6 +367,44 @@ index abc123..abc123 100644`;
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("エッジケース", () => {
|
describe("エッジケース", () => {
|
||||||
|
it("サブディレクトリから実行しても動作する", async () => {
|
||||||
|
const mockCwd = "/test/repo/subdirectory";
|
||||||
|
const fromRef = "base:main";
|
||||||
|
const toRef = "compare:feature";
|
||||||
|
|
||||||
|
const mockNumstatOutput = `3\t1\tsrc/file.ts`;
|
||||||
|
const mockDiffOutput = `diff --git a/src/file.ts b/src/file.ts
|
||||||
|
index abc123..def456 100644
|
||||||
|
--- a/src/file.ts
|
||||||
|
+++ b/src/file.ts
|
||||||
|
@@ -1,2 +1,3 @@
|
||||||
|
content`;
|
||||||
|
|
||||||
|
vi.mocked(utils.executeGitCommand)
|
||||||
|
.mockResolvedValueOnce({
|
||||||
|
success: true,
|
||||||
|
data: mockNumstatOutput,
|
||||||
|
})
|
||||||
|
.mockResolvedValueOnce({
|
||||||
|
success: true,
|
||||||
|
data: mockDiffOutput,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await getDiff(mockCwd, fromRef, toRef);
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.data.files).toHaveLength(1);
|
||||||
|
expect(result.data.files[0]?.filePath).toBe("src/file.ts");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that git commands are executed in the subdirectory
|
||||||
|
expect(utils.executeGitCommand).toHaveBeenCalledWith(
|
||||||
|
["diff", "--numstat", "main", "feature"],
|
||||||
|
mockCwd,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("特殊文字を含むファイル名を処理できる", async () => {
|
it("特殊文字を含むファイル名を処理できる", async () => {
|
||||||
const mockCwd = "/test/repo";
|
const mockCwd = "/test/repo";
|
||||||
const fromRef = "base:main";
|
const fromRef = "base:main";
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export async function executeGitCommand(
|
|||||||
cwd: string,
|
cwd: string,
|
||||||
): Promise<GitResult<string>> {
|
): Promise<GitResult<string>> {
|
||||||
try {
|
try {
|
||||||
// Check if the directory exists and contains a git repository
|
// Check if the directory exists
|
||||||
if (!existsSync(cwd)) {
|
if (!existsSync(cwd)) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -27,16 +27,7 @@ export async function executeGitCommand(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!existsSync(resolve(cwd, ".git"))) {
|
// Git will search parent directories for .git, so we don't need to check explicitly
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: {
|
|
||||||
code: "NOT_A_REPOSITORY",
|
|
||||||
message: `Not a git repository: ${cwd}`,
|
|
||||||
command: `git ${args.join(" ")}`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const { stdout } = await execFileAsync("git", args, {
|
const { stdout } = await execFileAsync("git", args, {
|
||||||
cwd,
|
cwd,
|
||||||
|
|||||||
@@ -33,11 +33,7 @@ const LayerImpl = Effect.gen(function* () {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(yield* fs.exists(path.resolve(absoluteCwd, ".git")))) {
|
// Git will search parent directories for .git, so we don't need to check explicitly
|
||||||
return yield* Effect.fail(
|
|
||||||
new NotARepositoryError({ cwd: absoluteCwd }),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const command = Command.make("git", ...args).pipe(
|
const command = Command.make("git", ...args).pipe(
|
||||||
Command.workingDirectory(absoluteCwd),
|
Command.workingDirectory(absoluteCwd),
|
||||||
|
|||||||
Reference in New Issue
Block a user