refactor(cli): sweep 15 bail("git X") sites to use git_run with context labels
This commit is contained in:
@@ -282,8 +282,7 @@ pub(super) fn cmd_backup_restore(input: PathBuf, target: PathBuf) -> Result<()>
|
||||
}
|
||||
} else {
|
||||
// No history bundled — start a fresh git repo.
|
||||
let status = crate::helpers::git_command(&target, &["init"]).status()?;
|
||||
if !status.success() { anyhow::bail!("git init failed"); }
|
||||
crate::helpers::git_run(&target, &["init"], "backup restore: git init")?;
|
||||
|
||||
// .gitignore — exclude reference image if present.
|
||||
if target.join("reference.jpg").exists() {
|
||||
|
||||
@@ -104,20 +104,17 @@ pub fn cmd_device(action: DeviceAction) -> Result<()> {
|
||||
fs::write(&devices_path, serde_json::to_string_pretty(&devices)?)?;
|
||||
|
||||
// Commit the update.
|
||||
let status = crate::helpers::git_command(
|
||||
crate::helpers::git_run(
|
||||
&root,
|
||||
&["add", ".relicario/devices.json"],
|
||||
)
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
anyhow::bail!("git add .relicario/devices.json failed");
|
||||
}
|
||||
&format!("device register \"{name}\": git add .relicario/devices.json"),
|
||||
)?;
|
||||
let msg = format!("device: register {}", name);
|
||||
let status = crate::helpers::git_command(&root, &["commit", "-m", &msg])
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
anyhow::bail!("git commit failed");
|
||||
}
|
||||
crate::helpers::git_run(
|
||||
&root,
|
||||
&["commit", "-m", &msg],
|
||||
&format!("device register \"{name}\": git commit"),
|
||||
)?;
|
||||
|
||||
eprintln!("Device '{}' registered.", name);
|
||||
eprintln!("Signing public key:");
|
||||
@@ -209,16 +206,17 @@ pub fn cmd_device(action: DeviceAction) -> Result<()> {
|
||||
".relicario/devices.json",
|
||||
".relicario/revoked.json",
|
||||
];
|
||||
let status = crate::helpers::git_command(&root, &add_args).status()?;
|
||||
if !status.success() {
|
||||
anyhow::bail!("git add failed");
|
||||
}
|
||||
crate::helpers::git_run(
|
||||
&root,
|
||||
&add_args,
|
||||
&format!("device revoke \"{name}\": git add devices.json + revoked.json"),
|
||||
)?;
|
||||
let msg = format!("device: revoke {}", name);
|
||||
let status = crate::helpers::git_command(&root, &["commit", "-m", &msg])
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
anyhow::bail!("git commit failed");
|
||||
}
|
||||
crate::helpers::git_run(
|
||||
&root,
|
||||
&["commit", "-m", &msg],
|
||||
&format!("device revoke \"{name}\": git commit"),
|
||||
)?;
|
||||
|
||||
eprintln!("Device '{}' revoked.", name);
|
||||
eprintln!("Revoked signing key: {}", device.public_key);
|
||||
|
||||
@@ -90,16 +90,16 @@ pub fn cmd_init(image: PathBuf, output: PathBuf) -> Result<()> {
|
||||
fs::write(root.join(".gitignore"), gitignore)?;
|
||||
|
||||
// git init + initial commit via hardened wrapper.
|
||||
let status = crate::helpers::git_command(&root, &["init"]).status()?;
|
||||
if !status.success() { anyhow::bail!("git init failed"); }
|
||||
crate::helpers::git_run(&root, &["init"], "init: git init")?;
|
||||
let _ = crate::helpers::git_command(&root, &[
|
||||
"add", ".gitignore", ".relicario/params.json",
|
||||
".relicario/salt", "manifest.enc", "settings.enc",
|
||||
]).status()?;
|
||||
let status = crate::helpers::git_command(&root, &[
|
||||
"commit", "-m", "init: new Relicario vault (format v2)",
|
||||
]).status()?;
|
||||
if !status.success() { anyhow::bail!("git commit failed"); }
|
||||
crate::helpers::git_run(
|
||||
&root,
|
||||
&["commit", "-m", "init: new Relicario vault (format v2)"],
|
||||
"init: git commit",
|
||||
)?;
|
||||
|
||||
eprintln!("Vault initialized at {}", root.display());
|
||||
eprintln!("Reference image: {}", output.display());
|
||||
|
||||
@@ -32,10 +32,12 @@ pub(crate) fn commit_paths(
|
||||
) -> Result<()> {
|
||||
let mut args: Vec<&str> = vec!["add"];
|
||||
args.extend_from_slice(paths);
|
||||
let status = crate::helpers::git_command(vault.root(), &args).status()?;
|
||||
if !status.success() { anyhow::bail!("git add failed"); }
|
||||
let status = crate::helpers::git_command(vault.root(), &["commit", "-m", message]).status()?;
|
||||
if !status.success() { anyhow::bail!("git commit failed"); }
|
||||
crate::helpers::git_run(vault.root(), &args, &format!("commit \"{message}\": git add"))?;
|
||||
crate::helpers::git_run(
|
||||
vault.root(),
|
||||
&["commit", "-m", message],
|
||||
&format!("commit \"{message}\": git commit"),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,8 @@ use anyhow::Result;
|
||||
|
||||
pub fn cmd_sync() -> Result<()> {
|
||||
let root = crate::helpers::vault_dir()?;
|
||||
let pull = crate::helpers::git_command(&root, &["pull", "--rebase"]).status()?;
|
||||
if !pull.success() { anyhow::bail!("git pull --rebase failed"); }
|
||||
let push = crate::helpers::git_command(&root, &["push"]).status()?;
|
||||
if !push.success() { anyhow::bail!("git push failed"); }
|
||||
crate::helpers::git_run(&root, &["pull", "--rebase"], "sync: git pull --rebase")?;
|
||||
crate::helpers::git_run(&root, &["push"], "sync: git push")?;
|
||||
eprintln!("Sync complete.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -78,11 +78,13 @@ pub fn cmd_purge(query: String) -> Result<()> {
|
||||
vault.save_manifest(&manifest)?;
|
||||
crate::refresh_groups_cache(vault.root(), &manifest);
|
||||
|
||||
let status = crate::helpers::git_command(vault.root(), &["add", "manifest.enc"]).status()?;
|
||||
if !status.success() { anyhow::bail!("git add manifest.enc failed"); }
|
||||
let status = crate::helpers::git_command(vault.root(),
|
||||
&["commit", "-m", &format!("purge: {} ({})", title, id.as_str())]).status()?;
|
||||
if !status.success() { anyhow::bail!("git commit failed"); }
|
||||
let purge_ctx = format!("purge \"{}\" ({})", title, id.as_str());
|
||||
crate::helpers::git_run(vault.root(), &["add", "manifest.enc"], &format!("{purge_ctx}: git add manifest.enc"))?;
|
||||
crate::helpers::git_run(
|
||||
vault.root(),
|
||||
&["commit", "-m", &format!("purge: {} ({})", title, id.as_str())],
|
||||
&format!("{purge_ctx}: git commit"),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -121,11 +123,16 @@ pub fn cmd_trash_empty() -> Result<()> {
|
||||
}
|
||||
|
||||
vault.save_manifest(&manifest)?;
|
||||
let status = crate::helpers::git_command(vault.root(), &["add", "manifest.enc"]).status()?;
|
||||
if !status.success() { anyhow::bail!("git add manifest.enc failed"); }
|
||||
let status = crate::helpers::git_command(vault.root(),
|
||||
&["commit", "-m", &format!("trash empty: purged {} item(s)", purged_titles.len())]).status()?;
|
||||
if !status.success() { anyhow::bail!("git commit failed"); }
|
||||
crate::helpers::git_run(
|
||||
vault.root(),
|
||||
&["add", "manifest.enc"],
|
||||
"trash empty: git add manifest.enc",
|
||||
)?;
|
||||
crate::helpers::git_run(
|
||||
vault.root(),
|
||||
&["commit", "-m", &format!("trash empty: purged {} item(s)", purged_titles.len())],
|
||||
"trash empty: git commit",
|
||||
)?;
|
||||
|
||||
eprintln!("Emptied trash: {} item(s)", purged_titles.len());
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user