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,
override_branch: Option<&str>,
)
| 471 | /// whose keys live in `~/.ssh/config` (a common setup, e.g. |
| 472 | /// `IdentityFile ~/.ssh_keys/github` with an empty agent). |
| 473 | fn push_to_remote( |
| 474 | &self, |
| 475 | git_repo: &GitRepository, |
| 476 | override_branch: Option<&str>, |
| 477 | ) -> CliResult<()> { |
| 478 | let head = git_repo.head().map_err(|e| CliError::GitError { |
| 479 | message: format!("Failed to get HEAD: {}", e), |
| 480 | })?; |
| 481 | let current = head.shorthand().unwrap_or("HEAD"); |
| 482 | let target = override_branch.unwrap_or(current); |
| 483 | let refspec = format!("HEAD:refs/heads/{}", target); |
| 484 | |
| 485 | let workdir = git_repo.workdir().ok_or_else(|| CliError::GitError { |
| 486 | message: "Git repository has no working directory (bare repository?)".to_string(), |
| 487 | })?; |
| 488 | |
| 489 | // Inherit stdio so the user sees git's native output and any |
| 490 | // interactive auth prompts (ssh passphrase, askpass) work. |
| 491 | let status = std::process::Command::new("git") |
| 492 | .args(["push", &self.remote, &refspec]) |
| 493 | .current_dir(workdir) |
| 494 | .status() |
| 495 | .map_err(|e| CliError::GitError { |
| 496 | message: format!("Failed to run git push: {}", e), |
| 497 | })?; |
| 498 | |
| 499 | if !status.success() { |
| 500 | return Err(CliError::GitError { |
| 501 | message: format!("git push exited with {}", status), |
| 502 | }); |
| 503 | } |
| 504 | |
| 505 | Ok(()) |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /// Parse a `Key: Value` trailer line from a commit message. |