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
4 changed files with 19 additions and 17 deletions

2
Cargo.lock generated
View File

@@ -188,7 +188,7 @@ dependencies = [
[[package]] [[package]]
name = "git-repo-manager" name = "git-repo-manager"
version = "0.1.0" version = "0.3.0"
dependencies = [ dependencies = [
"clap", "clap",
"comfy-table", "comfy-table",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "git-repo-manager" name = "git-repo-manager"
version = "0.2.0" version = "0.3.0"
edition = "2021" edition = "2021"
authors = [ authors = [
"Hannes Körber <hannes@hkoerber.de>", "Hannes Körber <hannes@hkoerber.de>",

View File

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

View File

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