From 73332abfb9a493255da7a4332d106ae369bddce0 Mon Sep 17 00:00:00 2001 From: gui Date: Tue, 4 Feb 2025 10:11:03 +0900 Subject: [PATCH 1/3] add the feature --- src/main.rs | 12 +++++++++++- src/patches.rs | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0e04b19..a7115c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,9 @@ enum Opts { #[structopt(help = "ignore patches", long = "ignore-patches")] ignore_patches: bool, + + #[structopt(help = "do not transfer .git", short = "G", long = "no-transfer-git")] + no_transfer_git: bool, }, } @@ -130,6 +133,7 @@ fn main() { command, options, ignore_patches, + no_transfer_git, } = Opts::from_args(); let mut metadata_cmd = cargo_metadata::MetadataCommand::new(); @@ -196,6 +200,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,7 +208,7 @@ fn main() { }); if !ignore_patches { - patches::handle_patches(&build_path, &build_server, manifest_path, hidden).unwrap_or_else( + 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); }, @@ -300,6 +305,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 +323,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..49f649f 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(()) @@ -117,7 +119,6 @@ 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 +209,7 @@ 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 From 42994c4a7877affcd799ee4fbbb4a7fbce417e6f Mon Sep 17 00:00:00 2001 From: gui Date: Tue, 4 Feb 2025 10:11:33 +0900 Subject: [PATCH 2/3] fmt --- src/main.rs | 15 ++++++++++----- src/patches.rs | 13 ++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index a7115c9..a0ad94f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -208,11 +208,16 @@ fn main() { }); if !ignore_patches { - 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); - }, - ); + 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."); } diff --git a/src/patches.rs b/src/patches.rs index 49f649f..f11d745 100644 --- a/src/patches.rs +++ b/src/patches.rs @@ -116,10 +116,7 @@ fn extract_patched_crates_and_adjust_toml Result Date: Tue, 4 Feb 2025 10:13:25 +0900 Subject: [PATCH 3/3] doc --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a0ad94f..19fb103 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,7 +82,12 @@ enum Opts { #[structopt(help = "ignore patches", long = "ignore-patches")] ignore_patches: bool, - #[structopt(help = "do not transfer .git", short = "G", long = "no-transfer-git")] + #[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, }, }