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
18 changes: 6 additions & 12 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { DEFAULT_WORKSPACE_ID, useWorkspaces } from './stores/workspaces';
import { useWorkspaceReview } from './stores/workspaceReview';
import { useUpdates } from './stores/updates';
import { UPDATES_MANAGED_BY_STORE } from './lib/distribution';
import { accentHueForColor, groupTabs, pathKey, repoFamilyName, workspaceMemberSet } from './lib/repoIdentity';
import { accentHueForColor, groupTabs, pathKey, pathLeaf, repoFamilyName, workspaceMemberSet } from './lib/repoIdentity';
import { buildContentReportUrl, buildCrashIssueUrl } from './lib/crashReport';
import { pickCodeWorkspaceFile, pickRepoDirectories } from './lib/dialog';
import { editorTemplate, osType, terminalTemplate } from './lib/integrations';
Expand Down Expand Up @@ -213,12 +213,6 @@ interface OpProgress {
error?: string | null;
}

/** Last path segment of a filesystem path (handles `/` and `\`). */
function basename(p: string): string {
const parts = p.split(/[\\/]/).filter(Boolean);
return parts[parts.length - 1] ?? p;
}

const MAIN_SURFACE_BY_VIEW: Partial<Record<View, CustomSurfaceId>> = {
local: BUILT_IN_SURFACE_IDS.localChanges,
review: BUILT_IN_SURFACE_IDS.review,
Expand Down Expand Up @@ -837,7 +831,7 @@ export function App() {
id,
kind: 'open',
title: 'Opening',
subject: basename(path),
subject: pathLeaf(path),
percent: null,
detail: 'Reading repository…',
eta: null,
Expand Down Expand Up @@ -880,7 +874,7 @@ export function App() {
id,
kind: 'clone',
title: 'Cloning',
subject: basename(dest),
subject: pathLeaf(dest),
percent: null,
detail: 'Starting…',
eta: null,
Expand Down Expand Up @@ -924,7 +918,7 @@ export function App() {
// open the freshly cloned repo.
setOpProgress((cur) =>
cur && cur.id === id
? { id, kind: 'open', title: 'Opening', subject: basename(clonedPath!), percent: null, detail: 'Reading repository…', eta: null, startedAt: Date.now() }
? { id, kind: 'open', title: 'Opening', subject: pathLeaf(clonedPath!), percent: null, detail: 'Reading repository…', eta: null, startedAt: Date.now() }
: cur,
);
try {
Expand All @@ -950,7 +944,7 @@ export function App() {
request.createInitialCommit,
);
await useWorkspaces.getState().openRepoInActive(outcome.path);
showToast(`Initialized ${basename(outcome.path)} on ${outcome.initial_branch}`);
showToast(`Initialized ${pathLeaf(outcome.path)} on ${outcome.initial_branch}`);
}, [showToast]);

// Open a batch of repos as tabs, one after another. Sequential (not
Expand Down Expand Up @@ -988,7 +982,7 @@ export function App() {
// rail and the toolbar tab strip (whichever `repoNav` selects).
const openIconDialog = useCallback((path: string) => {
const tab = useRepo.getState().tabs.find((t) => t.path === path);
setIconDialog({ path, name: tab ? repoFamilyName(tab.meta) : basename(path) });
setIconDialog({ path, name: tab ? repoFamilyName(tab.meta) : pathLeaf(path) });
}, []);

// Switch the active repository to the next (+1) / previous (-1) open one,
Expand Down
45 changes: 45 additions & 0 deletions ui/src/lib/repoIdentity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
import {
mainPathFromCommonDir,
pathKey,
pathLeaf,
repoFamilyName,
repoTabLabel,
tabWorktreeName,
Expand Down Expand Up @@ -86,6 +87,50 @@ describe('repo identity labels', () => {
});
});

describe('pathLeaf', () => {
/** Local copies deleted from App/Review/Commits: `split(/[\\/]/).filter(Boolean).pop() ?? p`. */
function legacyBasename(p: string): string {
return p.split(/[\\/]/).filter(Boolean).pop() ?? p;
}

it('returns the last segment of unix and windows paths', () => {
expect(pathLeaf('/src/strand')).toBe('strand');
expect(pathLeaf('C:\\dev\\portal')).toBe('portal');
expect(pathLeaf('C:/dev/portal')).toBe('portal');
expect(pathLeaf('strand')).toBe('strand');
});

it('ignores trailing and repeated separators', () => {
expect(pathLeaf('/src/strand/')).toBe('strand');
expect(pathLeaf('C:\\dev\\portal\\')).toBe('portal');
expect(pathLeaf('/src//strand')).toBe('strand');
});

it('returns the original string when there is no usable segment', () => {
expect(pathLeaf('')).toBe('');
expect(pathLeaf('/')).toBe('/');
expect(pathLeaf('\\\\')).toBe('\\\\');
});

it('matches the deleted split/filter basename copies', () => {
const samples = [
'/src/strand',
'/src/strand/',
'/src//strand',
'C:\\dev\\portal',
'C:\\dev\\portal\\',
'C:/dev/portal',
'strand',
'',
'/',
'\\\\',
];
for (const sample of samples) {
expect(pathLeaf(sample)).toBe(legacyBasename(sample));
}
});
});

describe('path identity', () => {
it('maps every spelling of a directory to one key', () => {
expect(pathKey('D:\\GitSources\\strand')).toBe('D:/GitSources/strand');
Expand Down
6 changes: 3 additions & 3 deletions ui/src/views/Commits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
type LocalGitOp,
} from '../lib/localGitOp';
import { providerMergedBranchNames } from '../lib/branchIntegration';
import { pathKey } from '../lib/repoIdentity';
import { pathKey, pathLeaf } from '../lib/repoIdentity';
import { t } from '../lib/i18n';
import { errMessage, tauri } from '../lib/tauri';
import type { Commit, Refs, Stash } from '../lib/types';
Expand Down Expand Up @@ -961,7 +961,7 @@ export function Commits({ onCreateTag, onInteractiveRebase, onAmendInto, onReset
title={`Back to ${fileReturn}`}
>
<Icon name="chev-left" size={13} />
<span>Back to {fileReturn.split(/[\\/]/).filter(Boolean).pop() ?? fileReturn}</span>
<span>Back to {pathLeaf(fileReturn)}</span>
</button>
)}
<div className="graph-toolbar-spacer" />
Expand Down Expand Up @@ -1038,7 +1038,7 @@ export function Commits({ onCreateTag, onInteractiveRebase, onAmendInto, onReset
title={`Back to ${workFileReturn.path}`}
>
<Icon name="chev-left" size={13} />
<span>Back to {workFileReturn.path.split(/[\\/]/).filter(Boolean).pop() ?? workFileReturn.path}</span>
<span>Back to {pathLeaf(workFileReturn.path)}</span>
</button>
)}
<button
Expand Down
7 changes: 2 additions & 5 deletions ui/src/views/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PaneHeader } from '../components/PaneHeader';
import { ImageDiff } from '../components/ImageDiff';
import { isImagePath } from '../lib/image';
import { emptyDiffMessage } from '../lib/emptyDiff';
import { pathLeaf } from '../lib/repoIdentity';
import {
copyToClipboard,
diffStatusToGit,
Expand Down Expand Up @@ -509,7 +510,7 @@ export function Review({
const files = collectFeedbackFiles(state.baseline ? state.baselineDiffs : state.reviewUnstagedDiffs, state.reviewNotes);
copyToClipboard(
buildReviewFeedback({
repoName: basename(activePath),
repoName: pathLeaf(activePath),
branch: meta?.branch ?? null,
baselineShort: baseline?.short ?? null,
files,
Expand Down Expand Up @@ -1254,10 +1255,6 @@ export function Review({
</div>
);
}
/** Last path segment — the repo's directory name from its absolute path. */
function basename(p: string): string {
return p.split(/[\\/]/).filter(Boolean).pop() ?? p;
}

function currentReviewPoolKey(state: ReturnType<typeof useRepo.getState>): string {
const pool = state.baseline ? state.baselineDiffs : state.reviewUnstagedDiffs;
Expand Down
Loading