feat: enhance git operations with unpublished commits detection and upstream setup on first push
This commit is contained in:
@@ -23,7 +23,7 @@ import {
|
||||
mapWorktreeToMetadata,
|
||||
removeWorktree,
|
||||
} from '@/lib/git/worktreeService';
|
||||
import { checkIsGitRepository, ensureOpenChamberIgnored, gitPush } from '@/lib/gitApi';
|
||||
import { checkIsGitRepository, ensureOpenChamberIgnored } from '@/lib/gitApi';
|
||||
import { useSessionStore } from '@/stores/useSessionStore';
|
||||
import { useDirectoryStore } from '@/stores/useDirectoryStore';
|
||||
import { useConfigStore } from '@/stores/useConfigStore';
|
||||
@@ -428,22 +428,7 @@ export const SessionDialogs: React.FC = () => {
|
||||
createBranch: true,
|
||||
});
|
||||
cleanupMetadata = metadata;
|
||||
let status = await getWorktreeStatus(metadata.path).catch(() => undefined);
|
||||
try {
|
||||
await gitPush(metadata.path, {
|
||||
remote: 'origin',
|
||||
branch: normalizedBranch,
|
||||
options: ['--set-upstream'],
|
||||
});
|
||||
status = await getWorktreeStatus(metadata.path).catch(() => status);
|
||||
toast.success(`Configured upstream for ${normalizedBranch}`);
|
||||
} catch (pushError) {
|
||||
const message =
|
||||
pushError instanceof Error ? pushError.message : 'Unable to push new worktree branch.';
|
||||
toast.warning('Worktree created locally', {
|
||||
description: renderToastDescription(`Upstream setup failed: ${message}`),
|
||||
});
|
||||
}
|
||||
const status = await getWorktreeStatus(metadata.path).catch(() => undefined);
|
||||
const createdMetadata = status ? { ...metadata, status } : metadata;
|
||||
|
||||
const session = await createSession(undefined, metadata.path);
|
||||
|
||||
@@ -210,17 +210,28 @@ export const GitHeader: React.FC<GitHeaderProps> = ({
|
||||
/>
|
||||
)}
|
||||
|
||||
{status.tracking && (
|
||||
<div className="flex items-center gap-2 px-1.5 typography-meta text-muted-foreground">
|
||||
<span className="flex items-center gap-0.5">
|
||||
<RiArrowUpLine className="size-3.5 text-primary/70" />
|
||||
<span className="font-semibold text-foreground">{status.ahead}</span>
|
||||
</span>
|
||||
<span className="flex items-center gap-0.5">
|
||||
<RiArrowDownLine className="size-3.5 text-primary/70" />
|
||||
<span className="font-semibold text-foreground">{status.behind}</span>
|
||||
</span>
|
||||
</div>
|
||||
{(Boolean(status.tracking) || status.ahead > 0 || status.behind > 0) && (
|
||||
<Tooltip delayDuration={800}>
|
||||
<TooltipTrigger asChild>
|
||||
<div className="flex items-center gap-2 px-1.5 typography-meta text-muted-foreground">
|
||||
<span className="flex items-center gap-0.5">
|
||||
<RiArrowUpLine className="size-3.5 text-primary/70" />
|
||||
<span className="font-semibold text-foreground">{status.ahead}</span>
|
||||
</span>
|
||||
{Boolean(status.tracking) && (
|
||||
<span className="flex items-center gap-0.5">
|
||||
<RiArrowDownLine className="size-3.5 text-primary/70" />
|
||||
<span className="font-semibold text-foreground">{status.behind}</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent sideOffset={8}>
|
||||
{status.tracking
|
||||
? `Upstream: ${status.tracking}`
|
||||
: 'Unpublished commits (no upstream set yet)'}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
<SyncActions
|
||||
|
||||
Reference in New Issue
Block a user