Compare commits

...

1 Commits

Author SHA1 Message Date
Conrad Irwin
af5fd3a197 fix git 2025-03-28 12:27:00 -06:00
2 changed files with 55 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
use crate::status::GitStatus;
use crate::{Oid, SHORT_SHA_LENGTH};
use anyhow::{anyhow, Context as _, Result};
use askpass::AskPassDelegate;
use collections::HashMap;
use futures::future::BoxFuture;
use futures::{select_biased, AsyncWriteExt, FutureExt as _};
@@ -255,7 +256,7 @@ pub trait GitRepository: Send + Sync {
branch_name: String,
upstream_name: String,
options: Option<PushOptions>,
askpass: AskPassSession,
askpass: AskPassDelegate,
env: HashMap<String, String>,
// This method takes an AsyncApp to ensure it's invoked on the main thread,
// otherwise git-credentials-manager won't work.
@@ -966,35 +967,65 @@ impl GitRepository for RealGitRepository {
branch_name: String,
remote_name: String,
options: Option<PushOptions>,
ask_pass: AskPassSession,
ask_pass: AskPassDelegate,
env: HashMap<String, String>,
_cx: AsyncApp,
cx: AsyncApp,
) -> BoxFuture<Result<RemoteCommandOutput>> {
let working_directory = self.working_directory();
let executor = cx.background_executor().clone();
async move {
let working_directory = working_directory?;
let mut command = new_smol_command("git");
command
.envs(env)
.env("GIT_ASKPASS", ask_pass.script_path())
.env("SSH_ASKPASS", ask_pass.script_path())
.env("SSH_ASKPASS_REQUIRE", "force")
.env("GIT_HTTP_USER_AGENT", "Zed")
.current_dir(&working_directory)
.args(["push"])
.args(options.map(|option| match option {
PushOptions::SetUpstream => "--set-upstream",
PushOptions::Force => "--force-with-lease",
}))
.arg(remote_name)
.arg(format!("{}:{}", branch_name, branch_name))
.stdin(smol::process::Stdio::null())
.stdout(smol::process::Stdio::piped())
.stderr(smol::process::Stdio::piped());
let git_process = command.spawn()?;
if env.contains_key("GIT_ASKPASS") {
dbg!("raw...");
let mut command = new_smol_command("git");
command
.envs(env)
.current_dir(&working_directory)
.args(["push"])
.args(options.map(|option| match option {
PushOptions::SetUpstream => "--set-upstream",
PushOptions::Force => "--force-with-lease",
}))
.arg(remote_name)
.arg(format!("{}:{}", branch_name, branch_name))
.stdin(smol::process::Stdio::null())
.stdout(smol::process::Stdio::piped())
.stderr(smol::process::Stdio::piped());
let git_process = command.spawn()?;
let output = git_process.output().await?;
if !output.status.success() {
Err(anyhow!("{}", String::from_utf8_lossy(&output.stderr)))
} else {
Ok(RemoteCommandOutput {
stdout: String::from_utf8_lossy(&output.stdout).to_string(),
stderr: String::from_utf8_lossy(&output.stderr).to_string(),
})
}
} else {
let ask_pass = AskPassSession::new(&executor, ask_pass).await?;
let mut command = new_smol_command("git");
command
.envs(env)
.env("GIT_ASKPASS", ask_pass.script_path())
.env("SSH_ASKPASS", ask_pass.script_path())
.env("SSH_ASKPASS_REQUIRE", "force")
.env("GIT_HTTP_USER_AGENT", "Zed")
.current_dir(&working_directory)
.args(["push"])
.args(options.map(|option| match option {
PushOptions::SetUpstream => "--set-upstream",
PushOptions::Force => "--force-with-lease",
}))
.arg(remote_name)
.arg(format!("{}:{}", branch_name, branch_name))
.stdin(smol::process::Stdio::null())
.stdout(smol::process::Stdio::piped())
.stderr(smol::process::Stdio::piped());
let git_process = command.spawn()?;
run_remote_command(ask_pass, git_process).await
run_remote_command(ask_pass, git_process).await
}
}
.boxed()
}

View File

@@ -3373,7 +3373,7 @@ impl Repository {
match git_repo {
RepositoryState::Local(git_repository) => {
let env = env.await;
let askpass = AskPassSession::new(&executor, askpass).await?;
// let askpass = AskPassSession::new(&executor, askpass).await?;
git_repository
.push(
branch.to_string(),