Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/code/src/main/services/git/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ export const getFileAtHeadInput = z.object({
});
export const getFileAtHeadOutput = z.string().nullable();

// getDiffHead schemas
export const getDiffHeadInput = z.object({
directoryPath: z.string(),
ignoreWhitespace: z.boolean().optional(),
});
export const getDiffHeadOutput = z.string();

// getDiffStats schemas
export const getDiffStatsInput = directoryPathInput;
export const getDiffStatsOutput = diffStatsSchema;
Expand Down
8 changes: 8 additions & 0 deletions apps/code/src/main/services/git/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getCurrentBranch,
getDefaultBranch,
getDiffAgainstRemote,
getDiffHead,
getDiffStats,
getFileAtHead,
getLatestCommit,
Expand Down Expand Up @@ -275,6 +276,13 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
return getFileAtHead(directoryPath, filePath);
}

public async getDiffHead(
directoryPath: string,
ignoreWhitespace?: boolean,
): Promise<string> {
return getDiffHead(directoryPath, { ignoreWhitespace });
}

public async getDiffStats(directoryPath: string): Promise<DiffStats> {
const stats = await getDiffStats(directoryPath, {
excludePatterns: [".claude", "CLAUDE.local.md"],
Expand Down
9 changes: 9 additions & 0 deletions apps/code/src/main/trpc/routers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
getCommitConventionsOutput,
getCurrentBranchInput,
getCurrentBranchOutput,
getDiffHeadInput,
getDiffHeadOutput,
getDiffStatsInput,
getDiffStatsOutput,
getFileAtHeadInput,
Expand Down Expand Up @@ -136,6 +138,13 @@ export const gitRouter = router({
getService().getFileAtHead(input.directoryPath, input.filePath),
),

getDiffHead: publicProcedure
.input(getDiffHeadInput)
.output(getDiffHeadOutput)
.query(({ input }) =>
getService().getDiffHead(input.directoryPath, input.ignoreWhitespace),
),

getDiffStats: publicProcedure
.input(getDiffStatsInput)
.output(getDiffStatsOutput)
Expand Down
12 changes: 12 additions & 0 deletions packages/git/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,18 @@ export async function getUnstagedDiff(
});
}

export async function getDiffHead(
baseDir: string,
options?: CreateGitClientOptions & { ignoreWhitespace?: boolean },
): Promise<string> {
const manager = getGitOperationManager();
const args = ["HEAD"];
if (options?.ignoreWhitespace) args.push("--ignore-all-space");
return manager.executeRead(baseDir, (git) => git.diff(args), {
signal: options?.abortSignal,
});
}

export async function getDiffAgainstRemote(
baseDir: string,
baseBranch: string,
Expand Down
Loading