fix: added gitignore handling
This commit is contained in:
@@ -13,6 +13,7 @@ export const GitSidebar: React.FC = () => {
|
||||
const [currentBranch, setCurrentBranch] = useState<string | null>(null);
|
||||
const [initProgress, setInitProgress] = useState<GitInitProgress | null>(null);
|
||||
const [initTranscript, setInitTranscript] = useState<GitInitProgress[]>([]);
|
||||
const [isTranscriptExpanded, setIsTranscriptExpanded] = useState(false);
|
||||
const remoteUrlInputRef = useRef<HTMLInputElement | null>(null);
|
||||
|
||||
const resolveProjectPath = useCallback(async (): Promise<string | null> => {
|
||||
@@ -48,6 +49,8 @@ export const GitSidebar: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
await window.electronAPI.git.ensureGitignore(resolvedProjectPath);
|
||||
|
||||
const repoState = await window.electronAPI.git.getRepoState(resolvedProjectPath);
|
||||
setIsRepo(repoState.isRepo);
|
||||
setCurrentBranch(repoState.currentBranch || null);
|
||||
@@ -67,6 +70,9 @@ export const GitSidebar: React.FC = () => {
|
||||
const unsubscribe = window.electronAPI.git.onInitProgress((progress) => {
|
||||
setInitProgress(progress);
|
||||
setInitTranscript((previous) => [...previous, progress].slice(-12));
|
||||
if (progress.phase === 'failed') {
|
||||
setIsTranscriptExpanded(true);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
@@ -117,15 +123,24 @@ export const GitSidebar: React.FC = () => {
|
||||
|
||||
const transcriptSection = initTranscript.length > 0 ? (
|
||||
<div className="git-sidebar-transcript">
|
||||
<p className="git-sidebar-transcript-title">Initialization transcript</p>
|
||||
<ul className="git-sidebar-transcript-list">
|
||||
{initTranscript.map((entry, index) => (
|
||||
<li key={`${entry.phase}-${entry.progress}-${index}`}>
|
||||
{entry.progress}% — {entry.message.toLowerCase().replace(/\.+$/, '')}
|
||||
{entry.detail ? ` (${entry.detail})` : ''}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<button
|
||||
type="button"
|
||||
className="git-sidebar-transcript-toggle"
|
||||
onClick={() => setIsTranscriptExpanded((previous) => !previous)}
|
||||
aria-expanded={isTranscriptExpanded}
|
||||
>
|
||||
Initialization transcript
|
||||
</button>
|
||||
{isTranscriptExpanded && (
|
||||
<ul className="git-sidebar-transcript-list">
|
||||
{initTranscript.map((entry, index) => (
|
||||
<li key={`${entry.phase}-${entry.progress}-${index}`}>
|
||||
{entry.progress}% — {entry.message.toLowerCase().replace(/\.+$/, '')}
|
||||
{entry.detail ? ` (${entry.detail})` : ''}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
@@ -134,8 +149,10 @@ export const GitSidebar: React.FC = () => {
|
||||
<div className="git-sidebar">
|
||||
<div className="git-sidebar-header">SOURCE CONTROL</div>
|
||||
<div className="git-sidebar-empty">
|
||||
<p>Git repository ready</p>
|
||||
{currentBranch && <p>Branch: {currentBranch}</p>}
|
||||
<div className="git-sidebar-main">
|
||||
<p>Git repository ready</p>
|
||||
{currentBranch && <p>Branch: {currentBranch}</p>}
|
||||
</div>
|
||||
{transcriptSection}
|
||||
</div>
|
||||
</div>
|
||||
@@ -146,29 +163,31 @@ export const GitSidebar: React.FC = () => {
|
||||
<div className="git-sidebar">
|
||||
<div className="git-sidebar-header">SOURCE CONTROL</div>
|
||||
<div className="git-sidebar-empty">
|
||||
<p>This project is not a git repository.</p>
|
||||
<input
|
||||
ref={remoteUrlInputRef}
|
||||
className="git-sidebar-input"
|
||||
type="text"
|
||||
placeholder="Optional remote repository URL"
|
||||
disabled={initializing}
|
||||
/>
|
||||
{initializing && (
|
||||
<p className="git-sidebar-progress">
|
||||
{initProgress?.message || 'Initializing repository...'}
|
||||
{typeof initProgress?.progress === 'number' ? ` (${initProgress.progress}%)` : ''}
|
||||
{initProgress?.detail ? ` — ${initProgress.detail}` : ''}
|
||||
</p>
|
||||
)}
|
||||
{error && <p className="git-sidebar-error">{error}</p>}
|
||||
<button
|
||||
className="git-sidebar-button"
|
||||
onClick={handleInitialize}
|
||||
disabled={initializing || !projectPath}
|
||||
>
|
||||
{initializing ? 'Initializing...' : 'Initialize Git'}
|
||||
</button>
|
||||
<div className="git-sidebar-main">
|
||||
<p>This project is not a git repository.</p>
|
||||
<input
|
||||
ref={remoteUrlInputRef}
|
||||
className="git-sidebar-input"
|
||||
type="text"
|
||||
placeholder="Optional remote repository URL"
|
||||
disabled={initializing}
|
||||
/>
|
||||
{initializing && (
|
||||
<p className="git-sidebar-progress">
|
||||
{initProgress?.message || 'Initializing repository...'}
|
||||
{typeof initProgress?.progress === 'number' ? ` (${initProgress.progress}%)` : ''}
|
||||
{initProgress?.detail ? ` — ${initProgress.detail}` : ''}
|
||||
</p>
|
||||
)}
|
||||
{error && <p className="git-sidebar-error">{error}</p>}
|
||||
<button
|
||||
className="git-sidebar-button"
|
||||
onClick={handleInitialize}
|
||||
disabled={initializing || !projectPath}
|
||||
>
|
||||
{initializing ? 'Initializing...' : 'Initialize Git'}
|
||||
</button>
|
||||
</div>
|
||||
{transcriptSection}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user