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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "@features/git-interaction/components/GitInteractionDialogs";
import { useGitInteractionStore } from "@features/git-interaction/state/gitInteractionStore";
import type { CreatePrStep } from "@features/git-interaction/types";
import type { DiffStats } from "@features/git-interaction/utils/diffStats";
import {
CheckCircle,
Circle,
Expand Down Expand Up @@ -113,7 +114,7 @@ export interface CreatePrDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
currentBranch: string | null;
diffStats: { filesChanged: number; linesAdded: number; linesRemoved: number };
diffStats: DiffStats;
isSubmitting: boolean;
onSubmit: () => void;
onGenerateCommitMessage: () => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Tooltip } from "@components/ui/Tooltip";
import type { DiffStats } from "@features/git-interaction/utils/diffStats";
import {
CheckCircle,
CloudArrowUp,
Expand Down Expand Up @@ -243,7 +244,7 @@ interface GitCommitDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
branchName: string | null;
diffStats: { filesChanged: number; linesAdded: number; linesRemoved: number };
diffStats: DiffStats;
commitMessage: string;
onCommitMessageChange: (value: string) => void;
nextStep: "commit" | "commit-push";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createBranch,
getBranchNameInputState,
} from "@features/git-interaction/utils/branchCreation";
import type { DiffStats } from "@features/git-interaction/utils/diffStats";
import { invalidateGitBranchQueries } from "@features/git-interaction/utils/gitCacheKeys";
import { updateGitCacheFromSnapshot } from "@features/git-interaction/utils/updateGitCache";
import { trpc, trpcClient } from "@renderer/trpc";
Expand All @@ -38,7 +39,7 @@ interface GitInteractionState {
defaultBranch: string | null;
prBaseBranch: string | null;
prHeadBranch: string | null;
diffStats: { filesChanged: number; linesAdded: number; linesRemoved: number };
diffStats: DiffStats;
prUrl: string | null;
pushDisabledReason: string | null;
isLoading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useTRPC } from "@renderer/trpc";
import { useQuery } from "@tanstack/react-query";

const EMPTY_DIFF_STATS = { filesChanged: 0, linesAdded: 0, linesRemoved: 0 };
const EMPTY_CHANGED_FILES: never[] = [];

const GIT_QUERY_DEFAULTS = {
staleTime: 30_000,
Expand All @@ -20,7 +21,10 @@ export function useGitQueries(repoPath?: string) {

const repoEnabled = enabled && isRepo;

const { data: changedFiles = [], isLoading: changesLoading } = useQuery(
const {
data: changedFiles = EMPTY_CHANGED_FILES,
isLoading: changesLoading,
} = useQuery(
trpc.git.getChangedFilesHead.queryOptions(
{ directoryPath: repoPath as string },
{
Expand Down
17 changes: 17 additions & 0 deletions apps/code/src/renderer/features/git-interaction/utils/diffStats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { ChangedFile } from "@shared/types";

export interface DiffStats {
filesChanged: number;
linesAdded: number;
linesRemoved: number;
}

export function computeDiffStats(files: ChangedFile[]): DiffStats {
let linesAdded = 0;
let linesRemoved = 0;
for (const file of files) {
linesAdded += file.linesAdded ?? 0;
linesRemoved += file.linesRemoved ?? 0;
}
return { filesChanged: files.length, linesAdded, linesRemoved };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { GitFileStatus } from "@shared/types";

export type StatusColor = "green" | "orange" | "red" | "blue" | "gray";
export interface StatusIndicator {
label: string;
fullLabel: string;
color: StatusColor;
}
export function getStatusIndicator(status: GitFileStatus): StatusIndicator {
switch (status) {
case "added":
case "untracked":
return { label: "A", fullLabel: "Added", color: "green" };
case "deleted":
return { label: "D", fullLabel: "Deleted", color: "red" };
case "modified":
return { label: "M", fullLabel: "Modified", color: "orange" };
case "renamed":
return { label: "R", fullLabel: "Renamed", color: "blue" };
default:
return { label: "?", fullLabel: "Unknown", color: "gray" };
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import type { DiffStats } from "@features/git-interaction/utils/diffStats";
import { Flex, Text } from "@radix-ui/themes";
import { useTRPC } from "@renderer/trpc";
import { useQuery } from "@tanstack/react-query";

interface DiffStatsIndicatorProps {
repoPath: string | null | undefined;
overrideStats?: {
filesChanged: number;
linesAdded: number;
linesRemoved: number;
} | null;
overrideStats?: DiffStats | null;
}

export function DiffStatsIndicator({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
useCloudBranchChangedFiles,
useCloudPrChangedFiles,
} from "@features/git-interaction/hooks/useGitQueries";
import { computeDiffStats } from "@features/git-interaction/utils/diffStats";
import { useDraftStore } from "@features/message-editor/stores/draftStore";
import { ProvisioningView } from "@features/provisioning/components/ProvisioningView";
import { useProvisioningStore } from "@features/provisioning/stores/provisioningStore";
Expand Down Expand Up @@ -100,11 +101,7 @@ export function TaskLogsPanel({ taskId, task }: TaskLogsPanelProps) {
if (!isCloud) return null;
const files = prUrl ? prFiles : branchFiles;
if (!files || files.length === 0) return null;
return {
filesChanged: files.length,
linesAdded: files.reduce((sum, f) => sum + (f.linesAdded ?? 0), 0),
linesRemoved: files.reduce((sum, f) => sum + (f.linesRemoved ?? 0), 0),
};
return computeDiffStats(files);
}, [isCloud, prUrl, prFiles, branchFiles]);

useEffect(() => {
Expand Down
5 changes: 5 additions & 0 deletions apps/code/src/renderer/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ export function compactHomePath(text: string): string {
.replace(/\/Users\/[^/\s]+/g, "~")
.replace(/\/home\/[^/\s]+/g, "~");
}

export function getFileExtension(filePath: string): string {
const parts = filePath.split(".");
return parts.length > 1 ? parts[parts.length - 1] : "";
}
Loading