Refuse to push against non-pushable remotes (e.g. HTTPS for now)

This commit is contained in:
2021-12-23 18:33:14 +01:00
parent b183590096
commit fcc22791e5
2 changed files with 22 additions and 3 deletions

View File

@@ -980,12 +980,21 @@ impl RemoteHandle<'_> {
.to_string()
}
pub fn is_pushable(&self) -> Result<bool, String> {
let remote_type = detect_remote_type(self.0.url().expect("Remote name is not valid utf-8")).ok_or_else(|| String::from("Could not detect remote type"))?;
Ok(matches!(remote_type, RemoteType::Ssh | RemoteType::File))
}
pub fn push(
&mut self,
local_branch_name: &str,
remote_branch_name: &str,
_repo: &Repo,
) -> Result<(), String> {
if !self.is_pushable()? {
return Err(String::from("Trying to push to a non-pushable remote"));
}
let mut callbacks = git2::RemoteCallbacks::new();
callbacks.push_update_reference(|_, status| {
if let Some(message) = status {