4 Commits

Author SHA1 Message Date
48f3bc0199 Support file remotes 2021-11-28 16:23:30 +01:00
0973ae36b8 Properly report push errors 2021-11-28 16:22:22 +01:00
09c67d4908 Remove wrong error message about remote branch 2021-11-28 16:22:22 +01:00
47841dadfb Release v0.3 2021-11-26 17:27:39 +01:00
2 changed files with 17 additions and 15 deletions

View File

@@ -949,10 +949,6 @@ pub fn run() {
.set_upstream(Some(&upstream_branch_name))
.unwrap();
} else {
print_error(&format!(
"Remote branch {} not found",
&upstream_branch_name
));
let split_at = upstream_branch_name.find('/').unwrap_or(0);
if split_at == 0 || split_at >= upstream_branch_name.len() - 1 {
print_error("Tracking branch needs to match the pattern <remote>/<branch_name>");
@@ -997,7 +993,10 @@ pub fn run() {
);
remote
.push(&[push_refspec], Some(&mut push_options))
.unwrap();
.unwrap_or_else(|error| {
print_error(&format!("Pushing to {} ({}) failed: {}", remote_name, remote.url().unwrap(), error));
process::exit(1);
});
target_branch
.set_upstream(Some(&upstream_branch_name))

View File

@@ -10,6 +10,7 @@ use crate::output::*;
pub enum RemoteType {
Ssh,
Https,
File,
}
#[derive(Debug, PartialEq)]
@@ -127,6 +128,14 @@ mod tests {
);
}
#[test]
fn check_file_remote() {
assert_eq!(
detect_remote_type("file:///somedir"),
Some(RemoteType::File)
);
}
#[test]
fn check_invalid_remotes() {
assert_eq!(detect_remote_type("https//example.com"), None);
@@ -147,12 +156,6 @@ mod tests {
fn check_unsupported_protocol_git() {
detect_remote_type("git://example.com");
}
#[test]
#[should_panic]
fn check_unsupported_protocol_file() {
detect_remote_type("file:///");
}
}
pub fn detect_remote_type(remote_url: &str) -> Option<RemoteType> {
@@ -166,15 +169,15 @@ pub fn detect_remote_type(remote_url: &str) -> Option<RemoteType> {
if remote_url.starts_with("https://") {
return Some(RemoteType::Https);
}
if remote_url.starts_with("file://") {
return Some(RemoteType::File);
}
if remote_url.starts_with("http://") {
unimplemented!("Remotes using HTTP protocol are not supported");
}
if remote_url.starts_with("git://") {
unimplemented!("Remotes using git protocol are not supported");
}
if remote_url.starts_with("file://") || remote_url.starts_with('/') {
unimplemented!("Remotes using local protocol are not supported");
}
None
}
@@ -254,7 +257,7 @@ pub fn clone_repo(
&remote.url
));
match remote.remote_type {
RemoteType::Https => {
RemoteType::Https | RemoteType::File => {
let mut builder = git2::build::RepoBuilder::new();
builder.bare(is_worktree);
builder.clone(&remote.url, &clone_target)?;