(arg_matches: ArgMatches)
| 73 | } |
| 74 | |
| 75 | pub fn run(arg_matches: ArgMatches) -> Result<(), Error> { |
| 76 | let git_chain = GitChain::init()?; |
| 77 | |
| 78 | match arg_matches.subcommand() { |
| 79 | ("init", Some(sub_matches)) => { |
| 80 | // Initialize the current branch to a chain. |
| 81 | |
| 82 | let chain_name = sub_matches.value_of("chain_name").unwrap().to_string(); |
| 83 | let root_branch = sub_matches.value_of("root_branch"); |
| 84 | |
| 85 | let before_branch = sub_matches.value_of("before"); |
| 86 | let after_branch = sub_matches.value_of("after"); |
| 87 | |
| 88 | let branch_name = git_chain.get_current_branch_name()?; |
| 89 | |
| 90 | let root_branch = if Chain::chain_exists(&git_chain, &chain_name)? { |
| 91 | // Derive root branch from an existing chain |
| 92 | let chain = Chain::get_chain(&git_chain, &chain_name)?; |
| 93 | |
| 94 | if let Some(user_provided_root_branch) = root_branch { |
| 95 | if user_provided_root_branch != chain.root_branch { |
| 96 | println!( |
| 97 | "Using root branch {} of chain {} instead of {}", |
| 98 | chain.root_branch.bold(), |
| 99 | chain_name.bold(), |
| 100 | user_provided_root_branch.bold() |
| 101 | ); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | chain.root_branch |
| 106 | } else if let Some(root_branch) = root_branch { |
| 107 | root_branch.to_string() |
| 108 | } else { |
| 109 | eprintln!("Please provide the root branch."); |
| 110 | process::exit(1); |
| 111 | }; |
| 112 | |
| 113 | if !git_chain.git_branch_exists(&root_branch)? { |
| 114 | eprintln!("Root branch does not exist: {}", root_branch.bold()); |
| 115 | process::exit(1); |
| 116 | } |
| 117 | |
| 118 | if root_branch == branch_name { |
| 119 | eprintln!( |
| 120 | "Current branch cannot be the root branch: {}", |
| 121 | branch_name.bold() |
| 122 | ); |
| 123 | process::exit(1); |
| 124 | } |
| 125 | |
| 126 | let sort_option = if sub_matches.is_present("first") { |
| 127 | SortBranch::First |
| 128 | } else { |
| 129 | parse_sort_option(&git_chain, &chain_name, before_branch, after_branch)? |
| 130 | }; |
| 131 | |
| 132 | git_chain.init_chain(&chain_name, &root_branch, &branch_name, sort_option)? |
no test coverage detected