Skip to content

Commit bb56039

Browse files
fix(web): polish PathHeader rendering for SHAs and empty paths
- Lift `truncateSha` (was a private helper in getDiffToolComponent) to `lib/utils` so PathHeader can reuse it. The branch/ref display now renders a 40-char SHA as `abc1234`, preserving any `^` / `~N` suffix. - Hide the `·` separator and the path's CopyIconButton when there's no path (repo root). Previously a dangling `·` and copy button rendered with nothing between them. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d20ab10 commit bb56039

3 files changed

Lines changed: 25 additions & 15 deletions

File tree

packages/web/src/app/(app)/components/pathHeader.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { cn, getCodeHostInfoForRepo } from "@/lib/utils";
3+
import { cn, getCodeHostInfoForRepo, truncateSha } from "@/lib/utils";
44
import Image from "next/image";
55
import { getBrowsePath } from "../browse/hooks/utils";
66
import { ChevronRight, MoreHorizontal } from "lucide-react";
@@ -233,10 +233,12 @@ export const PathHeader = ({
233233
}}
234234
>
235235
<span className="mr-0.5">@</span>
236-
{`${branchDisplayName.replace(/^refs\/(heads|tags)\//, '')}`}
236+
{truncateSha(branchDisplayName.replace(/^refs\/(heads|tags)\//, ''))}
237237
</p>
238238
)}
239-
<span>·</span>
239+
{breadcrumbSegments.length > 0 && (
240+
<span>·</span>
241+
)}
240242
<div ref={containerRef} className="flex-1 flex items-center overflow-hidden mt-0.5">
241243
<div ref={breadcrumbsRef} className="flex items-center overflow-hidden">
242244
{hiddenSegments.length > 0 && (
@@ -296,10 +298,12 @@ export const PathHeader = ({
296298
</div>
297299
))}
298300
</div>
299-
<CopyIconButton
300-
onCopy={onCopyPath}
301-
className="ml-2"
302-
/>
301+
{breadcrumbSegments.length > 0 && (
302+
<CopyIconButton
303+
onCopy={onCopyPath}
304+
className="ml-2"
305+
/>
306+
)}
303307
</div>
304308
</div>
305309
)

packages/web/src/features/chat/components/chatThread/tools/getDiffToolComponent.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@
22

33
import { Separator } from '@/components/ui/separator';
44
import { GetDiffMetadata, ToolResult } from '@/features/tools';
5+
import { truncateSha } from '@/lib/utils';
56
import { GitCommitHorizontalIcon } from 'lucide-react';
67
import { RepoBadge } from './repoBadge';
78

8-
function truncateSha(ref: string): string {
9-
const match = ref.match(/^([0-9a-f]{40})(.*)$/i);
10-
if (match) {
11-
return match[1].substring(0, 7) + match[2];
12-
}
13-
return ref;
14-
}
15-
169
export const GetDiffToolComponent = ({ metadata }: ToolResult<GetDiffMetadata>) => {
1710
const fileCount = metadata.files.length;
1811

packages/web/src/lib/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ export function cn(...inputs: ClassValue[]) {
2222
return twMerge(clsx(inputs))
2323
}
2424

25+
/**
26+
* If `ref` starts with a 40-character hex SHA, truncate the SHA portion to
27+
* 7 characters and preserve any trailing operator suffix (e.g. `^`, `~1`).
28+
* Returns the input unchanged for symbolic refs (branches, tags, etc.).
29+
*/
30+
export function truncateSha(ref: string): string {
31+
const match = ref.match(/^([0-9a-f]{40})(.*)$/i);
32+
if (match) {
33+
return match[1].slice(0, 7) + match[2];
34+
}
35+
return ref;
36+
}
37+
2538
/**
2639
* Creates an invite link URL from the base URL and invite ID
2740
* @param baseUrl The base URL of the application

0 commit comments

Comments
 (0)