diff --git a/src/grm/cmd.rs b/src/grm/cmd.rs index 27a1c82..3145b7d 100644 --- a/src/grm/cmd.rs +++ b/src/grm/cmd.rs @@ -170,6 +170,17 @@ pub struct Config { help = "Path to the configuration file" )] pub config: String, + + #[clap( + long, + help = "Check out the default worktree after clone", + possible_values = &["true", "false"], + default_value = "true", + default_missing_value = "true", + min_values = 0, + max_values = 1, + )] + pub init_worktree: String, } pub type RemoteProvider = grm::provider::RemoteProvider; @@ -224,6 +235,17 @@ pub struct SyncRemoteArgs { #[clap(long, help = "Base URL for the API")] pub api_url: Option, + + #[clap( + long, + help = "Check out the default worktree after clone", + possible_values = &["true", "false"], + default_value = "true", + default_missing_value = "true", + min_values = 0, + max_values = 1, + )] + pub init_worktree: String, } #[derive(Parser)] diff --git a/src/grm/main.rs b/src/grm/main.rs index 40a8652..3f202f0 100644 --- a/src/grm/main.rs +++ b/src/grm/main.rs @@ -23,7 +23,7 @@ fn main() { process::exit(1); } }; - match grm::sync_trees(config) { + match grm::sync_trees(config, args.init_worktree == "true") { Ok(success) => { if !success { process::exit(1) @@ -93,7 +93,7 @@ fn main() { let config = config::Config::from_trees(trees); - match grm::sync_trees(config) { + match grm::sync_trees(config, args.init_worktree == "true") { Ok(success) => { if !success { process::exit(1) diff --git a/src/lib.rs b/src/lib.rs index 95b0b77..fcda502 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,7 +139,7 @@ pub fn get_token_from_command(command: &str) -> Result { Ok(token.to_string()) } -fn sync_repo(root_path: &Path, repo: &RepoConfig) -> Result<(), String> { +fn sync_repo(root_path: &Path, repo: &RepoConfig, init_worktree: bool) -> Result<(), String> { let repo_path = root_path.join(&repo.name); let actual_git_directory = get_actual_git_directory(&repo_path, repo.worktree_setup); @@ -189,7 +189,7 @@ fn sync_repo(root_path: &Path, repo: &RepoConfig) -> Result<(), String> { } }; - if repo.worktree_setup { + if repo.worktree_setup && init_worktree { match repo_handle.default_branch() { Ok(branch) => { add_worktree(&repo_path, &branch.name()?, None, None, false)?; @@ -273,7 +273,7 @@ pub fn find_unmanaged_repos( Ok(unmanaged_repos) } -pub fn sync_trees(config: Config) -> Result { +pub fn sync_trees(config: Config, init_worktree: bool) -> Result { let mut failures = false; for tree in config.trees()?.as_vec() { let repos = tree.repos.unwrap_or_default(); @@ -281,7 +281,7 @@ pub fn sync_trees(config: Config) -> Result { let root_path = expand_path(Path::new(&tree.root)); for repo in &repos { - match sync_repo(&root_path, repo) { + match sync_repo(&root_path, repo, init_worktree) { Ok(_) => print_repo_success(&repo.name, "OK"), Err(error) => { print_repo_error(&repo.name, &error);