Skip to content

Commit d92aadc

Browse files
authored
Merge pull request #9637 from Byron/fix
fix `git fetch` to ignore lock failures just like Git
2 parents 8d22666 + bb2858a commit d92aadc

File tree

5 files changed

+33
-39
lines changed

5 files changed

+33
-39
lines changed

Cargo.lock

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

crates/gitbutler-git/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ test-askpass-path = []
2828
benches = []
2929

3030
[dependencies]
31+
tracing.workspace = true
3132
thiserror.workspace = true
33+
anyhow.workspace = true
3234
serde = { workspace = true, optional = true }
3335
tokio = { workspace = true, optional = true, features = [
3436
"process",

crates/gitbutler-git/src/executor/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ pub unsafe trait GitExecutor {
7777
let mut args = args.as_ref().to_vec();
7878

7979
args.insert(0, "--no-pager");
80-
// TODO(qix-): Test the performance impact of this.
81-
args.insert(0, "--no-optional-locks");
8280
// '-c' arguments must be inserted in reverse order; Git does not support
8381
// shortflags for '-c' arguments, so they must be separated.
8482
args.insert(0, "protocol.version=2");

crates/gitbutler-git/src/executor/tokio/mod.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ mod unix;
55
#[cfg(windows)]
66
mod windows;
77

8+
use gix::bstr::ByteSlice;
89
use std::{collections::HashMap, path::Path};
9-
1010
use tokio::process::Command;
1111

1212
#[cfg(unix)]
@@ -32,24 +32,6 @@ unsafe impl super::GitExecutor for TokioExecutor {
3232
let git_exe = gix::path::env::exe_invocation();
3333
let mut cmd = Command::new(git_exe);
3434

35-
// Output the command being executed to stderr, for debugging purposes
36-
// (only on test configs).
37-
#[cfg(any(test, debug_assertions))]
38-
{
39-
let mut envs_str = String::new();
40-
if let Some(envs) = &envs {
41-
for (key, value) in envs.iter() {
42-
envs_str.push_str(&format!("{key}={value:?} "));
43-
}
44-
}
45-
let args_str = args
46-
.iter()
47-
.map(|s| format!("{s:?}"))
48-
.collect::<Vec<_>>()
49-
.join(" ");
50-
eprintln!("env {envs_str} {git_exe:?} {args_str}");
51-
}
52-
5335
cmd.kill_on_drop(true);
5436
cmd.current_dir(cwd);
5537

@@ -90,7 +72,9 @@ unsafe impl super::GitExecutor for TokioExecutor {
9072

9173
let output = cmd.output().await?;
9274

93-
#[cfg(any(test, debug_assertions))]
75+
debug_log_sanitised_git_cmd(&mut cmd);
76+
77+
#[cfg(test)]
9478
{
9579
eprintln!(
9680
"\n\n GIT STDOUT:\n\n{}\n\nGIT STDERR:\n\n{}\n\nGIT EXIT CODE: {}\n",
@@ -100,6 +84,15 @@ unsafe impl super::GitExecutor for TokioExecutor {
10084
);
10185
}
10286

87+
if !output.status.success() {
88+
tracing::error!(
89+
?cmd,
90+
stdout = output.stdout.as_bstr().to_string(),
91+
stderr = output.stderr.as_bstr().to_string(),
92+
"Git invocation failed"
93+
);
94+
}
95+
10396
Ok((
10497
output.status.code().unwrap_or(127) as usize,
10598
String::from_utf8_lossy(&output.stdout).trim().into(),
@@ -129,6 +122,14 @@ unsafe impl super::GitExecutor for TokioExecutor {
129122
}
130123
}
131124
}
125+
126+
fn debug_log_sanitised_git_cmd(cmd: &mut Command) {
127+
cmd.env_remove("GITBUTLER_ASKPASS_SECRET")
128+
.env_remove("GITBUTLER_ASKPASS_PIPE")
129+
.env_remove("SSH_ASKPASS");
130+
tracing::debug!(?cmd, "sanitised Git invocation");
131+
}
132+
132133
#[cfg(test)]
133134
mod tests {
134135
use std::time::Duration;

crates/gitbutler-git/src/repository.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ where
158158
.or_else(|| std::env::var("GIT_SSH").ok())
159159
{
160160
Some(v) => v,
161-
None => get_core_sshcommand(executor, &repo_path)
162-
.await
161+
None => get_core_sshcommand(&repo_path)
162+
.ok()
163+
.flatten()
163164
.unwrap_or_else(|| "ssh".into()),
164165
};
165166

@@ -507,19 +508,9 @@ where
507508
Ok(commit_hash)
508509
}
509510

510-
async fn get_core_sshcommand<E: GitExecutor, P: AsRef<Path>>(
511-
executor: &E,
512-
cwd: P,
513-
) -> Option<String> {
514-
executor
515-
.execute(&["config", "--get", "core.sshCommand"], cwd, None)
516-
.await
517-
.map(|(status, stdout, _)| {
518-
if status != 0 {
519-
None
520-
} else {
521-
Some(stdout.trim().to_string())
522-
}
523-
})
524-
.unwrap_or(None)
511+
fn get_core_sshcommand(cwd: impl AsRef<Path>) -> anyhow::Result<Option<String>> {
512+
Ok(gix::open(cwd.as_ref())?
513+
.config_snapshot()
514+
.trusted_program(&gix::config::tree::Core::SSH_COMMAND)
515+
.map(|program| program.to_string_lossy().into_owned()))
525516
}

0 commit comments

Comments
 (0)