()
| 91 | } |
| 92 | |
| 93 | fn main() -> Result<(), anyhow::Error> { |
| 94 | let cli = Cli::parse(); |
| 95 | env_logger::Builder::new() |
| 96 | .filter_level(cli.verbosity.log_level_filter()) |
| 97 | .init(); |
| 98 | |
| 99 | match cli.action { |
| 100 | CliSubcommand::Flatten { save_dir, repo_dir } => { |
| 101 | Config::new(save_dir, repo_dir, vec![], vec![]).flatten() |
| 102 | } |
| 103 | CliSubcommand::Unflatten { save_dir, repo_dir } => { |
| 104 | Config::new(save_dir, repo_dir, vec![], vec![]).unflatten() |
| 105 | } |
| 106 | CliSubcommand::Commit { |
| 107 | save_dir, |
| 108 | git_dir, |
| 109 | branch, |
| 110 | init, |
| 111 | message, |
| 112 | use_repack, |
| 113 | extra_patterns, |
| 114 | ignore_patterns, |
| 115 | } => { |
| 116 | let parents = { |
| 117 | let mut cmd = git_cmd(&git_dir, ["rev-parse", &format!("{branch}^{{commit}}")]); |
| 118 | let out = cmd.output().context("failed to run git rev-parse")?; |
| 119 | let branch_exists = out.status.success(); |
| 120 | match (branch_exists, init) { |
| 121 | (true, false) => { |
| 122 | vec![ |
| 123 | String::from_utf8(out.stdout) |
| 124 | .context("git output is not valid UTF-8")? |
| 125 | .trim() |
| 126 | .to_owned(), |
| 127 | ] |
| 128 | } |
| 129 | (false, true) => vec![], |
| 130 | (true, true) => anyhow::bail!("branch '{branch}' exists, remove --init"), |
| 131 | (false, false) => anyhow::bail!( |
| 132 | "invalid branch name '{branch}'. Self-check via 'git --git-dir {:?} rev-parse {branch}^{{commit}}'", |
| 133 | git_dir.as_os_str() |
| 134 | ), |
| 135 | } |
| 136 | }; |
| 137 | let r#ref = format!("refs/heads/{}", &branch); |
| 138 | |
| 139 | let size_before = git_count_objects(&git_dir) |
| 140 | .context("failed to count git objects")? |
| 141 | .total_size_mib(); |
| 142 | let unprocessed = Config::new( |
| 143 | save_dir, |
| 144 | git_dir.to_owned(), |
| 145 | extra_patterns, |
| 146 | ignore_patterns, |
| 147 | ) |
| 148 | .commit(parents, &message, Some(r#ref), None, None)?; |
| 149 | if !unprocessed.is_empty() { |
| 150 | for item in &unprocessed { |
nothing calls this directly
no test coverage detected