Skip to content

Commit 72de844

Browse files
authored
Merge pull request #10170 from Byron/fix
better error for repossitory ownership issues
2 parents 1276a4c + 67d1962 commit 72de844

File tree

8 files changed

+35
-46
lines changed

8 files changed

+35
-46
lines changed

Cargo.lock

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/src/components/ChromeHeader.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
{/if}
229229
</div>
230230

231-
{#if isNotInWorkspace}
231+
{#if currentMode !== null && isNotInWorkspace}
232232
<Tooltip text="Switch back to gitbutler/workspace">
233233
<Button
234234
kind="outline"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export enum Code {
22
Unknown = 'errors.unknown',
33
Validation = 'errors.validation',
4+
RepoOwnership = 'errors.repo_ownership',
45
ProjectsGitAuth = 'errors.projects.git.auth',
56
DefaultTargetNotFound = 'errors.projects.default_target.not_found',
67
CommitSigningFailed = 'errors.commit.signing_failed',
@@ -16,6 +17,11 @@ Commit signing failed and has now been disabled. You can configure commit signin
1617
1718
Please check our [documentation](https://docs.gitbutler.com/features/virtual-branches/signing-commits) on setting up commit signing and verification.
1819
`,
20+
[Code.RepoOwnership]: `
21+
The repository ownership couldn't be determined. Consider allowing it using:
22+
23+
git config --global --add safe.directory copy/of/path/shown/below
24+
`,
1925
[Code.SecretKeychainNotFound]: `
2026
Please install a keychain service to store and retrieve secrets with.
2127

crates/gitbutler-command-context/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ impl CommandContext {
5555
/// Open the repository identified by `project` and perform some checks.
5656
pub fn open(project: &Project, app_settings: AppSettings) -> Result<Self> {
5757
let repo = git2::Repository::open(&project.path)?;
58+
Self::open_from(project, app_settings, repo)
59+
}
60+
61+
pub fn open_from(
62+
project: &Project,
63+
app_settings: AppSettings,
64+
repo: git2::Repository,
65+
) -> Result<Self> {
5866
Ok(Self {
5967
git_repo: repo,
6068
project: project.clone(),

crates/gitbutler-error/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub enum Code {
128128
#[default]
129129
Unknown,
130130
Validation,
131+
RepoOwnership,
131132
ProjectGitAuth,
132133
DefaultTargetNotFound,
133134
CommitSigningFailed,
@@ -144,6 +145,7 @@ impl std::fmt::Display for Code {
144145
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
145146
let code = match self {
146147
Code::Unknown => "errors.unknown",
148+
Code::RepoOwnership => "errors.repo_ownership",
147149
Code::Validation => "errors.validation",
148150
Code::ProjectGitAuth => "errors.projects.git.auth",
149151
Code::DefaultTargetNotFound => "errors.projects.default_target.not_found",

crates/gitbutler-project/src/controller.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ impl Controller {
153153
}
154154
}
155155

156-
// FIXME(qix-): On windows, we have to force to system executable.
157-
// FIXME(qix-): This is a hack for now, and will be smoothed over in the future.
158156
#[cfg(windows)]
159157
let project_owned = {
160158
let mut project = project.clone();
@@ -218,7 +216,6 @@ impl Controller {
218216
}
219217
}
220218

221-
// FIXME(qix-): On windows, we have to force to system executable
222219
#[cfg(windows)]
223220
{
224221
project.preferred_key = AuthKey::SystemExecutable;

crates/gitbutler-tauri/Cargo.toml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ tauri-build = { version = "2.3.1", features = [] }
2121
anyhow = "1.0.99"
2222
backtrace = { version = "0.3.74", optional = true }
2323
console-subscriber = "0.4.1"
24-
git2.workspace = true
2524
gix = { workspace = true, features = [
2625
"max-performance",
2726
"blocking-http-transport-curl",
2827
"worktree-mutation",
2928
] }
30-
reqwest = { version = "0.12.23", features = ["json"] }
3129
serde.workspace = true
3230
serde_json = { version = "1.0", features = ["std", "arbitrary_precision"] }
33-
serde-error = "0.1.3"
3431
tauri = { version = "^2.7.0", features = ["unstable"] }
3532
tauri-plugin-dialog = "2.3.2"
3633
tauri-plugin-fs = "2.4.1"
@@ -47,45 +44,28 @@ tauri-plugin-clipboard-manager = "2.3.0"
4744

4845
parking_lot.workspace = true
4946
log = "^0.4"
47+
git2.workspace = true
5048
# The features here optimize for performance.
5149
tokio = { workspace = true, features = ["rt-multi-thread", "parking_lot"] }
5250
tracing.workspace = true
5351
tracing-appender = "0.2.3"
5452
tracing-subscriber.workspace = true
5553
tracing-forest = { version = "0.2.0" }
5654
gitbutler-watcher.workspace = true
57-
gitbutler-branch-actions.workspace = true
58-
gitbutler-oplog.workspace = true
59-
gitbutler-repo.workspace = true
6055
gitbutler-repo-actions.workspace = true
6156
gitbutler-command-context.workspace = true
6257
but-feedback.workspace = true
6358
gitbutler-project.workspace = true
64-
gitbutler-user.workspace = true
65-
gitbutler-branch.workspace = true
66-
gitbutler-reference.workspace = true
6759
gitbutler-error.workspace = true
6860
gitbutler-secret.workspace = true
6961
gitbutler-id.workspace = true
70-
gitbutler-oxidize.workspace = true
71-
gitbutler-stack.workspace = true
72-
gitbutler-diff.workspace = true
73-
gitbutler-operating-modes.workspace = true
74-
gitbutler-edit-mode.workspace = true
75-
gitbutler-sync.workspace = true
76-
gitbutler-forge.workspace = true
7762
but-broadcaster.workspace = true
7863
but-db.workspace = true
7964
but-settings.workspace = true
8065
but-workspace.workspace = true
8166
but-core.workspace = true
82-
but-graph.workspace = true
83-
but-hunk-dependency.workspace = true
84-
but-hunk-assignment.workspace = true
8567
but-action.workspace = true
8668
but-bot.workspace = true
87-
but-rules.workspace = true
88-
but-path.workspace = true
8969
but-api.workspace = true
9070
but-claude.workspace = true
9171
open = "5"

crates/gitbutler-tauri/src/projects.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,23 @@ pub fn set_project_active(
6161
return Ok(None);
6262
}
6363
};
64-
let ctx = &mut CommandContext::open(&project, AppSettings::load_from_default_path_creating()?)?;
64+
let repo = git2::Repository::open(&project.path)
65+
// Only capture this information here to prevent spawning too many errors because of this
66+
// (the UI has many parallel calls in flight).
67+
.map_err(|err| {
68+
let code = err.code();
69+
let err = anyhow::Error::from(err);
70+
if code == git2::ErrorCode::Owner {
71+
err.context(gitbutler_error::error::Code::RepoOwnership)
72+
} else {
73+
err
74+
}
75+
})?;
76+
let ctx = &mut CommandContext::open_from(
77+
&project,
78+
AppSettings::load_from_default_path_creating()?,
79+
repo,
80+
)?;
6581
let mode =
6682
window_state.set_project_to_window(window.label(), &project, &app_settings_sync, ctx)?;
6783
let db_error = assure_database_valid(project.gb_dir())?;

0 commit comments

Comments
 (0)