Skip to content
Closed
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
12 changes: 9 additions & 3 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ const App: React.FC = () => {
const [addCommandValue, setAddCommandValue] = useState('');
const [showEditedFiles, setShowEditedFiles] = useState(false);
const [cwdCopied, setCwdCopied] = useState(false);
const [isWorktreeSession, setIsWorktreeSession] = useState(false);
const [filePreviewPath, setFilePreviewPath] = useState<string | null>(null);
const [isGitRepo, setIsGitRepo] = useState<boolean>(true);
const [showCommitModal, setShowCommitModal] = useState(false);
Expand Down Expand Up @@ -4861,9 +4862,13 @@ Only when ALL the above are verified complete, output exactly: ${RALPH_COMPLETIO
{/* Git Branch */}
<div className="px-4 py-3 border-b border-copilot-border">
<div className="text-xs text-copilot-text-muted uppercase tracking-wide mb-2">
Git Branch
Git Branch{isWorktreeSession && ' (worktree)'}
</div>
<GitBranchWidget cwd={activeTab?.cwd} refreshKey={activeTab?.gitBranchRefresh} />
<GitBranchWidget
cwd={activeTab?.cwd}
refreshKey={activeTab?.gitBranchRefresh}
onWorktreeChange={setIsWorktreeSession}
/>
</div>

{/* Edited Files Count */}
Expand Down Expand Up @@ -6913,12 +6918,13 @@ Only when ALL the above are verified complete, output exactly: ${RALPH_COMPLETIO
<div className="px-3 py-2 border-b border-copilot-surface">
<div className="flex items-center justify-between gap-2 mb-1">
<div className="text-[10px] text-copilot-text-muted uppercase tracking-wide">
Git Branch
Git Branch{isWorktreeSession && ' (worktree)'}
</div>
</div>
<GitBranchWidget
cwd={activeTab?.cwd}
refreshKey={activeTab?.gitBranchRefresh}
onWorktreeChange={setIsWorktreeSession}
/>
</div>

Expand Down
38 changes: 29 additions & 9 deletions src/renderer/components/GitBranchWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import React, { useState, useEffect } from 'react';
import { CopyIcon, CheckIcon } from './Icons';

interface GitBranchWidgetProps {
cwd?: string;
refreshKey?: number;
onWorktreeChange?: (isWorktree: boolean) => void;
}

export const GitBranchWidget: React.FC<GitBranchWidgetProps> = ({ cwd, refreshKey }) => {
export const GitBranchWidget: React.FC<GitBranchWidgetProps> = ({
cwd,
refreshKey,
onWorktreeChange,
}) => {
const [branch, setBranch] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [isWorktree, setIsWorktree] = useState(false);
const [copied, setCopied] = useState(false);

useEffect(() => {
if (!cwd) {
Expand Down Expand Up @@ -42,6 +49,7 @@ export const GitBranchWidget: React.FC<GitBranchWidgetProps> = ({ cwd, refreshKe
// Also check if cwd itself is a worktree path
const isWorktreePath = cwd.includes('.copilot-sessions');
setIsWorktree(!!worktreeSession || isWorktreePath);
onWorktreeChange?.(!!worktreeSession || isWorktreePath);
} catch (err) {
console.error('Failed to get git branch:', err);
setError('Failed to get branch');
Expand Down Expand Up @@ -83,6 +91,18 @@ export const GitBranchWidget: React.FC<GitBranchWidgetProps> = ({ cwd, refreshKe
);
}

const handleCopy = () => {
if (branch) {
navigator.clipboard
.writeText(branch)
.then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
})
.catch(() => {});
}
};

return (
<div className="flex items-center gap-1.5 text-xs min-w-0" data-testid="git-branch-widget">
<svg
Expand All @@ -102,14 +122,14 @@ export const GitBranchWidget: React.FC<GitBranchWidgetProps> = ({ cwd, refreshKe
<span className="text-copilot-text font-mono truncate" title={branch}>
{branch}
</span>
{isWorktree && (
<span
className="px-1.5 py-0.5 bg-copilot-accent/20 text-copilot-accent rounded text-[10px] font-medium shrink-0"
title="This session is running in an isolated worktree"
>
worktree
</span>
)}
<button
className="shrink-0 p-0.5 rounded hover:bg-copilot-surface text-copilot-text-muted hover:text-copilot-text transition-colors"
title={copied ? 'Copied!' : 'Copy branch'}
aria-label={copied ? 'Copied!' : 'Copy branch'}
onClick={handleCopy}
>
{copied ? <CheckIcon size={12} className="text-copilot-success" /> : <CopyIcon size={12} />}
</button>
</div>
);
};