Fix worktree initialization

This commit is contained in:
2022-01-24 17:24:24 +01:00
parent 881a33dc96
commit f2f1d5bcaf
3 changed files with 28 additions and 6 deletions

View File

@@ -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<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,
}
#[derive(Parser)]

View File

@@ -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)

View File

@@ -139,7 +139,7 @@ pub fn get_token_from_command(command: &str) -> Result<String, String> {
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<bool, String> {
pub fn sync_trees(config: Config, init_worktree: bool) -> Result<bool, String> {
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<bool, String> {
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);