Skip to content

Commit 0813edf

Browse files
CopilotByron
andcommitted
Improve error handling robustness and user feedback
Co-authored-by: Byron <[email protected]>
1 parent 9f86c69 commit 0813edf

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

apps/desktop/src/routes/[projectId]/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ import { getUserErrorCode, Code } from '$lib/backend/ipc';
340340
dismiss();
341341
showToast({
342342
title: 'Repository Initialized',
343-
message: 'Git repository has been initialized successfully. Retrying...',
343+
message: `Git repository has been successfully initialized at ${currentProject.path}. Loading project...`,
344344
style: 'info'
345345
});
346346
// Retry setting the project active

crates/gitbutler-tauri/src/projects.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ pub fn set_project_active(
6969
let err = anyhow::Error::from(err);
7070
if code == git2::ErrorCode::Owner {
7171
err.context(gitbutler_error::error::Code::RepoOwnership)
72-
} else if code == git2::ErrorCode::NotFound {
73-
// When git2::Repository::open fails with NotFound, it likely means the directory
74-
// is not a git repository, so we attach our custom error code.
72+
} else if code == git2::ErrorCode::NotFound ||
73+
code == git2::ErrorCode::Invalid ||
74+
code == git2::ErrorCode::Config {
75+
// Common error codes when a directory is not a git repository:
76+
// - NotFound: .git directory or repository not found
77+
// - Invalid: Invalid repository structure
78+
// - Config: Repository configuration issues
7579
err.context(gitbutler_error::error::Code::NonGitRepository)
7680
} else {
7781
err
@@ -223,7 +227,7 @@ Ensure these aren't touched by GitButler or avoid using it in this repository.",
223227
pub fn init_git_repository(path: String) -> Result<(), Error> {
224228
let repo_path = std::path::Path::new(&path);
225229

226-
// Check if path exists and is a directory
230+
// Validate path
227231
if !repo_path.exists() {
228232
return Err(anyhow::anyhow!("Path does not exist: {}", path).into());
229233
}
@@ -236,6 +240,14 @@ pub fn init_git_repository(path: String) -> Result<(), Error> {
236240
return Err(anyhow::anyhow!("Directory is already a Git repository").into());
237241
}
238242

243+
// Check if directory is writable
244+
let temp_file = repo_path.join(".gitbutler_write_test");
245+
if let Err(_) = std::fs::write(&temp_file, "test") {
246+
return Err(anyhow::anyhow!("Directory is not writable: {}", path).into());
247+
}
248+
// Clean up test file
249+
let _ = std::fs::remove_file(&temp_file);
250+
239251
// Initialize the repository
240252
git2::Repository::init(repo_path)
241253
.with_context(|| format!("Failed to initialize Git repository at {}", path))?;

0 commit comments

Comments
 (0)