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>,
)
| 514 | /// whose keys live in `~/.ssh/config` (a common setup, e.g. |
| 515 | /// `IdentityFile ~/.ssh_keys/github` with an empty agent). |
| 516 | fn push_to_remote( |
| 517 | &self, |
| 518 | git_repo: &GitRepository, |
| 519 | override_branch: Option<&str>, |
| 520 | ) -> CliResult<()> { |
| 521 | let head = git_repo.head().map_err(|e| CliError::GitError { |
| 522 | message: format!("Failed to get HEAD: {}", e), |
| 523 | })?; |
| 524 | let current = head.shorthand().unwrap_or("HEAD"); |
| 525 | let target = override_branch.unwrap_or(current); |
| 526 | let refspec = format!("HEAD:refs/heads/{}", target); |
| 527 | |
| 528 | let workdir = git_repo.workdir().ok_or_else(|| CliError::GitError { |
| 529 | message: "Git repository has no working directory (bare repository?)".to_string(), |
| 530 | })?; |
| 531 | |
| 532 | // Inherit stdio so the user sees git's native output and any |
| 533 | // interactive auth prompts (ssh passphrase, askpass) work. |
| 534 | let status = std::process::Command::new("git") |
| 535 | .args(["push", &self.remote, &refspec]) |
| 536 | .current_dir(workdir) |
| 537 | .status() |
| 538 | .map_err(|e| CliError::GitError { |
| 539 | message: format!("Failed to run git push: {}", e), |
| 540 | })?; |
| 541 | |
| 542 | if !status.success() { |
| 543 | return Err(CliError::GitError { |
| 544 | message: format!("git push exited with {}", status), |
| 545 | }); |
| 546 | } |
| 547 | |
| 548 | Ok(()) |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | /// Parse a `Key: Value` trailer line from a commit message. |