Skip to content

Commit 90ef91f

Browse files
CopilotByron
andcommitted
Add NonGitRepository error code and detection in set_project_active
Co-authored-by: Byron <[email protected]>
1 parent 5910953 commit 90ef91f

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

apps/desktop/src/lib/error/knownErrors.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export enum Code {
88
ProjectMissing = 'errors.projects.missing',
99
SecretKeychainNotFound = 'errors.secret.keychain_notfound',
1010
MissingLoginKeychain = 'errors.secret.missing_login_keychain',
11-
GitHubTokenExpired = 'errors.github.expired_token'
11+
GitHubTokenExpired = 'errors.github.expired_token',
12+
NonGitRepository = 'errors.projects.not_git_repository'
1213
}
1314

1415
export const KNOWN_ERRORS: Record<string, string> = {
@@ -34,5 +35,8 @@ With \`seahorse\` or equivalent, create a \`Login\` password store, right click
3435
`,
3536
[Code.GitHubTokenExpired]: `
3637
Your GitHub token appears expired, please check your settings!
38+
`,
39+
[Code.NonGitRepository]: `
40+
The selected directory is not a Git repository. Would you like to initialize a Git repository in this directory?
3741
`
3842
};

crates/gitbutler-error/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ pub enum Code {
139139
SecretKeychainNotFound,
140140
MissingLoginKeychain,
141141
GitForcePushProtection,
142+
NonGitRepository,
142143
}
143144

144145
impl std::fmt::Display for Code {
@@ -157,6 +158,7 @@ impl std::fmt::Display for Code {
157158
Code::SecretKeychainNotFound => "errors.secret.keychain_notfound",
158159
Code::MissingLoginKeychain => "errors.secret.missing_login_keychain",
159160
Code::GitForcePushProtection => "errors.git.force_push_protection",
161+
Code::NonGitRepository => "errors.projects.not_git_repository",
160162
};
161163
f.write_str(code)
162164
}

crates/gitbutler-tauri/src/projects.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ 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.
75+
err.context(gitbutler_error::error::Code::NonGitRepository)
7276
} else {
7377
err
7478
}

0 commit comments

Comments
 (0)