mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
Fix git sync nag showing immediately after cloning external projects
Store the HEAD commit OID as 'shakespeare.clonedAt' git config at clone time, then use it to determine whether the user has actually altered the project before showing the backup warning.
This commit is contained in:
3 files changed
+47
-11
No files matched your search
@@ -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 <IndicatorDot color="yellow" />;
|
||||
}
|
||||
|
||||
// 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 <IndicatorDot color="primary" />;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in new issue
Block a user