feat: add exit-code to link check
This commit is contained in:
@@ -24,6 +24,10 @@ pub enum Link {
|
|||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
porcelain: bool,
|
porcelain: bool,
|
||||||
|
|
||||||
|
/// Exit with 1 when anything is outside the store, for scripts
|
||||||
|
#[arg(long)]
|
||||||
|
exit_code: bool,
|
||||||
|
|
||||||
/// Terminate porcelain entries with NUL
|
/// Terminate porcelain entries with NUL
|
||||||
#[arg(short = 'z')]
|
#[arg(short = 'z')]
|
||||||
null: bool,
|
null: bool,
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ fn main() -> Result<()> {
|
|||||||
paths,
|
paths,
|
||||||
porcelain,
|
porcelain,
|
||||||
null,
|
null,
|
||||||
} => scripts::link::check(&paths, porcelain, null),
|
exit_code,
|
||||||
|
} => scripts::link::check(&paths, porcelain, null, exit_code),
|
||||||
},
|
},
|
||||||
cli::Commands::Completions { shell } => scripts::completions::completions(shell),
|
cli::Commands::Completions { shell } => scripts::completions::completions(shell),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ use std::cell::Cell;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io::{self, Write};
|
||||||
use std::os::unix::fs::symlink;
|
use std::os::unix::fs::symlink;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{Context, Result, anyhow};
|
||||||
@@ -62,7 +64,7 @@ fn warn(msg: impl std::fmt::Display) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// list untracked paths not in the store, i.e. what a sandbox can still read
|
// list untracked paths not in the store, i.e. what a sandbox can still read
|
||||||
pub fn check(paths: &[PathBuf], porcelain: bool, null: bool) -> Result<()> {
|
pub fn check(paths: &[PathBuf], porcelain: bool, null: bool, exit_code: bool) -> Result<()> {
|
||||||
let repo = Repo::discover()?;
|
let repo = Repo::discover()?;
|
||||||
let pathspecs = relative_pathspecs(&repo, paths)?;
|
let pathspecs = relative_pathspecs(&repo, paths)?;
|
||||||
|
|
||||||
@@ -89,6 +91,12 @@ pub fn check(paths: &[PathBuf], porcelain: bool, null: bool) -> Result<()> {
|
|||||||
print_listing(&repo, &exposed);
|
print_listing(&repo, &exposed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// git's --exit-code convention: nothing to report is 0, anything is 1
|
||||||
|
if exit_code && !exposed.is_empty() {
|
||||||
|
io::stdout().flush().context("writing the listing")?;
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user