Push the current branch to the remote. Delegates the network operation to the `git` CLI so authentication behaves exactly like a plain `git push`: OpenSSH client config (`Host`/`IdentityFile`/`IdentitiesOnly`), ssh-agents, askpass prompts, and HTTPS credential helpers all work as the user expects. Do not "simplify" this back to libgit2's transport: its credential callback can only consult the ss
(&self, git_repo: &GitRepository)
| 402 | /// whose keys live in `~/.ssh/config` (a common setup, e.g. |
| 403 | /// `IdentityFile ~/.ssh_keys/github` with an empty agent). |
| 404 | fn push_to_remote(&self, git_repo: &GitRepository) -> CliResult<()> { |
| 405 | let head = git_repo.head().map_err(|e| CliError::GitError { |
| 406 | message: format!("Failed to get HEAD: {}", e), |
| 407 | })?; |
| 408 | let current = head.shorthand().unwrap_or("HEAD"); |
| 409 | let target = self.branch.as_deref().unwrap_or(current); |
| 410 | let refspec = format!("HEAD:refs/heads/{}", target); |
| 411 | |
| 412 | let workdir = git_repo.workdir().ok_or_else(|| CliError::GitError { |
| 413 | message: "Git repository has no working directory (bare repository?)".to_string(), |
| 414 | })?; |
| 415 | |
| 416 | // Inherit stdio so the user sees git's native output and any |
| 417 | // interactive auth prompts (ssh passphrase, askpass) work. |
| 418 | let status = std::process::Command::new("git") |
| 419 | .args(["push", &self.remote, &refspec]) |
| 420 | .current_dir(workdir) |
| 421 | .status() |
| 422 | .map_err(|e| CliError::GitError { |
| 423 | message: format!("Failed to run git push: {}", e), |
| 424 | })?; |
| 425 | |
| 426 | if !status.success() { |
| 427 | return Err(CliError::GitError { |
| 428 | message: format!("git push exited with {}", status), |
| 429 | }); |
| 430 | } |
| 431 | |
| 432 | Ok(()) |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /// Parse a `Key: Value` trailer line from a commit message. |