Fix worktree initialization
This commit is contained in:
@@ -170,6 +170,17 @@ pub struct Config {
|
|||||||
help = "Path to the configuration file"
|
help = "Path to the configuration file"
|
||||||
)]
|
)]
|
||||||
pub config: String,
|
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;
|
pub type RemoteProvider = grm::provider::RemoteProvider;
|
||||||
@@ -224,6 +235,17 @@ pub struct SyncRemoteArgs {
|
|||||||
|
|
||||||
#[clap(long, help = "Base URL for the API")]
|
#[clap(long, help = "Base URL for the API")]
|
||||||
pub api_url: Option<String>,
|
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)]
|
#[derive(Parser)]
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ fn main() {
|
|||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match grm::sync_trees(config) {
|
match grm::sync_trees(config, args.init_worktree == "true") {
|
||||||
Ok(success) => {
|
Ok(success) => {
|
||||||
if !success {
|
if !success {
|
||||||
process::exit(1)
|
process::exit(1)
|
||||||
@@ -93,7 +93,7 @@ fn main() {
|
|||||||
|
|
||||||
let config = config::Config::from_trees(trees);
|
let config = config::Config::from_trees(trees);
|
||||||
|
|
||||||
match grm::sync_trees(config) {
|
match grm::sync_trees(config, args.init_worktree == "true") {
|
||||||
Ok(success) => {
|
Ok(success) => {
|
||||||
if !success {
|
if !success {
|
||||||
process::exit(1)
|
process::exit(1)
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ pub fn get_token_from_command(command: &str) -> Result<String, String> {
|
|||||||
Ok(token.to_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 repo_path = root_path.join(&repo.name);
|
||||||
let actual_git_directory = get_actual_git_directory(&repo_path, repo.worktree_setup);
|
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() {
|
match repo_handle.default_branch() {
|
||||||
Ok(branch) => {
|
Ok(branch) => {
|
||||||
add_worktree(&repo_path, &branch.name()?, None, None, false)?;
|
add_worktree(&repo_path, &branch.name()?, None, None, false)?;
|
||||||
@@ -273,7 +273,7 @@ pub fn find_unmanaged_repos(
|
|||||||
Ok(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;
|
let mut failures = false;
|
||||||
for tree in config.trees()?.as_vec() {
|
for tree in config.trees()?.as_vec() {
|
||||||
let repos = tree.repos.unwrap_or_default();
|
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));
|
let root_path = expand_path(Path::new(&tree.root));
|
||||||
|
|
||||||
for repo in &repos {
|
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"),
|
Ok(_) => print_repo_success(&repo.name, "OK"),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
print_repo_error(&repo.name, &error);
|
print_repo_error(&repo.name, &error);
|
||||||
|
|||||||
Reference in New Issue
Block a user