|
12 | 12 | import ReduxResult from '$components/ReduxResult.svelte';
|
13 | 13 | import { OnboardingEvent, POSTHOG_WRAPPER } from '$lib/analytics/posthog';
|
14 | 14 | import { BACKEND } from '$lib/backend';
|
| 15 | +import { getUserErrorCode, Code } from '$lib/backend/ipc'; |
15 | 16 | import { BASE_BRANCH_SERVICE } from '$lib/baseBranch/baseBranchService.svelte';
|
16 | 17 | import { BRANCH_SERVICE } from '$lib/branches/branchService.svelte';
|
17 | 18 | import { SETTINGS_SERVICE } from '$lib/config/appSettingsV2';
|
|
22 | 23 | import { GITLAB_STATE } from '$lib/forge/gitlab/gitlabState.svelte';
|
23 | 24 | import { GIT_SERVICE } from '$lib/git/gitService';
|
24 | 25 | import { MODE_SERVICE } from '$lib/mode/modeService';
|
25 |
| - import { showError, showInfo, showWarning } from '$lib/notifications/toasts'; |
| 26 | + import { showError, showInfo, showWarning, showToast } from '$lib/notifications/toasts'; |
26 | 27 | import { PROJECTS_SERVICE } from '$lib/project/projectsService';
|
27 | 28 | import { FILE_SELECTION_MANAGER } from '$lib/selection/fileSelectionManager.svelte';
|
28 | 29 | import { UNCOMMITTED_SERVICE } from '$lib/selection/uncommittedService.svelte';
|
|
320 | 321 | }
|
321 | 322 | } catch (error: unknown) {
|
322 | 323 | posthog.captureOnboarding(OnboardingEvent.SetProjectActiveFailed);
|
323 |
| - showError('Failed to set the project active', error); |
| 324 | + |
| 325 | + // Check if this is a non-git repository error |
| 326 | + const errorCode = getUserErrorCode(error); |
| 327 | + if (errorCode === Code.NonGitRepository) { |
| 328 | + // Show special toast with git init option |
| 329 | + showToast({ |
| 330 | + title: 'Not a Git repository', |
| 331 | + message: 'The selected directory is not a Git repository. Would you like to initialize one?', |
| 332 | + style: 'warning', |
| 333 | + extraAction: { |
| 334 | + label: 'Initialize Repository', |
| 335 | + onClick: async (dismiss) => { |
| 336 | + try { |
| 337 | + const currentProject = projects?.find((p) => p.id === projectId); |
| 338 | + if (currentProject?.path) { |
| 339 | + await projectsService.initGitRepository(currentProject.path); |
| 340 | + dismiss(); |
| 341 | + showToast({ |
| 342 | + title: 'Repository Initialized', |
| 343 | + message: `Git repository has been successfully initialized at ${currentProject.path}. Loading project...`, |
| 344 | + style: 'info' |
| 345 | + }); |
| 346 | + // Retry setting the project active |
| 347 | + await setActiveProjectOrRedirect(projectId); |
| 348 | + } else { |
| 349 | + throw new Error('Could not find project path'); |
| 350 | + } |
| 351 | + } catch (initError) { |
| 352 | + console.error('Failed to initialize repository:', initError); |
| 353 | + dismiss(); |
| 354 | + showError('Failed to initialize repository', initError); |
| 355 | + } |
| 356 | + } |
| 357 | + } |
| 358 | + }); |
| 359 | + } else { |
| 360 | + showError('Failed to set the project active', error); |
| 361 | + } |
324 | 362 | }
|
325 | 363 | }
|
326 | 364 |
|
|
0 commit comments