diff --git a/src/main.rs b/src/main.rs index 0e04b19..19fb103 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,14 @@ enum Opts { #[structopt(help = "ignore patches", long = "ignore-patches")] ignore_patches: bool, + + #[structopt( + help = "Do not transfer .git. Note that .git is hidden so .git is transferred only \ + if --transfer-hidden|-h is set and --no-transfer-git|-G is not set", + short = "G", + long = "no-transfer-git" + )] + no_transfer_git: bool, }, } @@ -130,6 +138,7 @@ fn main() { command, options, ignore_patches, + no_transfer_git, } = Opts::from_args(); let mut metadata_cmd = cargo_metadata::MetadataCommand::new(); @@ -196,6 +205,7 @@ fn main() { &format!("{}/", project_dir.display()), &format!("{}:{}", build_server, build_path), hidden, + no_transfer_git, ) .unwrap_or_else(|e| { error!("Failed to transfer project to build server (error: {})", e); @@ -203,11 +213,16 @@ fn main() { }); if !ignore_patches { - patches::handle_patches(&build_path, &build_server, manifest_path, hidden).unwrap_or_else( - |err| { - log::error!("Could not transfer patched workspaces to remote: {}", err); - }, - ); + patches::handle_patches( + &build_path, + &build_server, + manifest_path, + hidden, + no_transfer_git, + ) + .unwrap_or_else(|err| { + log::error!("Could not transfer patched workspaces to remote: {}", err); + }); } else { log::debug!("Potential patches will be ignored due to command line flag."); } @@ -300,6 +315,7 @@ pub fn copy_to_remote( local_dir: &str, remote_dir: &str, hidden: bool, + no_transfer_git: bool, ) -> Result { let mut rsync_to = Command::new("rsync"); rsync_to @@ -317,6 +333,10 @@ pub fn copy_to_remote( rsync_to.arg("--exclude").arg(".*"); } + if no_transfer_git { + rsync_to.arg("--exclude").arg(".git"); + } + rsync_to .arg("--rsync-path") .arg("mkdir -p remote-builds && rsync") diff --git a/src/patches.rs b/src/patches.rs index ed1cbe4..f11d745 100644 --- a/src/patches.rs +++ b/src/patches.rs @@ -19,6 +19,7 @@ pub fn handle_patches( build_server: &String, manifest_path: PathBuf, copy_hidden_files: bool, + no_transfer_git: bool, ) -> Result<(), String> { let cargo_file_content = std::fs::read_to_string(&manifest_path).map_err(|err| { format!( @@ -38,6 +39,7 @@ pub fn handle_patches( patched_cargo_doc, project_list, copy_hidden_files, + no_transfer_git, )?; } Ok(()) @@ -114,11 +116,7 @@ fn extract_patched_crates_and_adjust_toml Result, copy_hidden_files: bool, + no_transfer_git: bool, ) -> Result<(), String> { for patch_operation in projects_to_copy.iter() { let local_proj_path = format!("{}/", patch_operation.local_path.display()); @@ -207,7 +206,13 @@ fn copy_patches_to_remote( &remote_proj_path ); // transfer project to build server - copy_to_remote(&local_proj_path, &remote_proj_path, copy_hidden_files).map_err(|err| { + copy_to_remote( + &local_proj_path, + &remote_proj_path, + copy_hidden_files, + no_transfer_git, + ) + .map_err(|err| { format!( "Failed to transfer project {} to build server (error: {})", local_proj_path, err