diff --git a/src/components/git-sync/GitSyncButton.tsx b/src/components/git-sync/GitSyncButton.tsx index 11972ff5..e41a2edd 100644 --- a/src/components/git-sync/GitSyncButton.tsx +++ b/src/components/git-sync/GitSyncButton.tsx @@ -54,19 +54,28 @@ export function GitSyncButton({ projectId, className }: GitSyncButtonProps) { prevIsGitActionOccurring.current = isGitActionOccurring; }, [isGitActionOccurring, hasError]); + // Determine if the user has altered the project (made commits beyond the initial state). + // - Template projects (no clonedAtOid): altered when totalCommits > 1 (beyond the initial template commit) + // - Cloned projects (has clonedAtOid): altered when the latest commit differs from the clone point + const isProjectAltered = !isGitStatusLoading && gitStatus && (() => { + if (gitStatus.clonedAtOid) { + return gitStatus.latestCommit !== null && gitStatus.latestCommit.oid !== gitStatus.clonedAtOid; + } + return gitStatus.totalCommits > 1; + })(); + // Check if we need to show the warning popover - const needsRemote = !isGitStatusLoading && gitStatus && - !gitStatus.remotes.find(r => r.name === 'origin') && - gitStatus.totalCommits > 1; + const needsRemote = isProjectAltered && + !gitStatus?.remotes.find(r => r.name === 'origin'); // Show warning popover when purple indicator is visible (only if not dismissed) useEffect(() => { - if (needsRemote && !warningDismissed.current && gitStatus.totalCommits > 1) { + if (needsRemote && !warningDismissed.current) { setShowWarningPopover(true); } else { setShowWarningPopover(false); } - }, [gitStatus?.totalCommits, needsRemote]); + }, [needsRemote]); // Handle button click - dismiss warning popover permanently const handleButtonClick = () => { @@ -96,19 +105,18 @@ export function GitSyncButton({ projectId, className }: GitSyncButtonProps) { if (isGitStatusLoading || !gitStatus) return null; - const originRemote = gitStatus.remotes.find(r => r.name === 'origin'); - const hasRemote = !!originRemote; + const hasOrigin = !!gitStatus.remotes.find(r => r.name === 'origin'); - const { remoteBranchExists, ahead, behind, totalCommits } = gitStatus; + const { remoteBranchExists, ahead, behind } = gitStatus; // Yellow indicator: unsynced changes (ahead or behind remote) - third priority - const hasUnsyncedChanges = hasRemote && remoteBranchExists && (ahead > 0 || behind > 0); + const hasUnsyncedChanges = hasOrigin && remoteBranchExists && (ahead > 0 || behind > 0); if (hasUnsyncedChanges) { return ; } - // Purple indicator: no remote configured, but has commits - lowest priority - const needsRemote = !hasRemote && totalCommits > 1; + // Purple indicator: project altered but no origin remote configured - lowest priority + const needsRemote = isProjectAltered && !hasOrigin; if (needsRemote) { return ; } diff --git a/src/hooks/useGitStatus.ts b/src/hooks/useGitStatus.ts index 31c2af97..99fbd4af 100644 --- a/src/hooks/useGitStatus.ts +++ b/src/hooks/useGitStatus.ts @@ -39,6 +39,7 @@ interface GitStatus { ahead: number; behind: number; remoteBranchExists: boolean; + clonedAtOid: string | null; } export function useGitStatus(projectId: string | null) { @@ -61,6 +62,7 @@ export function useGitStatus(projectId: string | null) { ahead: 0, behind: 0, remoteBranchExists: false, + clonedAtOid: null, }; } @@ -83,6 +85,7 @@ export function useGitStatus(projectId: string | null) { ahead: 0, behind: 0, remoteBranchExists: false, + clonedAtOid: null, }; } @@ -168,6 +171,17 @@ export function useGitStatus(projectId: string | null) { console.warn('Could not get remotes:', error); } + // Get clonedAt OID (set when project was cloned from an external repo) + let clonedAtOid: string | null = null; + try { + const value = await git.getConfig({ dir: cwd, path: 'shakespeare.clonedAt' }); + if (typeof value === 'string' && value.length > 0) { + clonedAtOid = value; + } + } catch { + // Config key doesn't exist, that's fine + } + // Get git status to see what files have changed const statusMatrix = await git.statusMatrix({ dir: cwd, @@ -274,6 +288,7 @@ export function useGitStatus(projectId: string | null) { ahead, behind, remoteBranchExists, + clonedAtOid, }; } catch (error) { console.error('Error checking git status:', error); @@ -289,6 +304,7 @@ export function useGitStatus(projectId: string | null) { ahead: 0, behind: 0, remoteBranchExists: false, + clonedAtOid: null, }; } }, diff --git a/src/lib/ProjectsManager.ts b/src/lib/ProjectsManager.ts index 56459b42..e72cf0c8 100644 --- a/src/lib/ProjectsManager.ts +++ b/src/lib/ProjectsManager.ts @@ -524,6 +524,18 @@ export class ProjectsManager { remote: fork ? 'upstream' : undefined, // Use 'upstream' for forks, otherwise defaults to 'origin' }); + // Store the HEAD commit OID at clone time so we can detect user modifications later + try { + const headOid = await this.git.resolveRef({ dir: projectPath, ref: 'HEAD' }); + await this.git.setConfig({ + dir: projectPath, + path: 'shakespeare.clonedAt', + value: headOid, + }); + } catch (error) { + console.warn('Failed to store clonedAt commit OID:', error); + } + if (!fork) { // Set up 'shakespeare.autosync' config for non-forked repositories await this.git.setConfig({