mirror of
https://seed.radicle.dev/rad:zwTxygwuz5LDGBq255RA2CbNGrz8.git
synced 2026-10-18 19:30:29 +08:00
feat: msg::helper::runcmd takes a non-empty argv vector
This makes is the empty-argv mistake that much easier to avoid. Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Generated
+10
-3
@@ -1527,6 +1527,12 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nonempty"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "549e471b99ccaf2f89101bec68f4d244457d5a95a9c3d0672e9564124397741d"
|
||||
|
||||
[[package]]
|
||||
name = "normpath"
|
||||
version = "1.3.0"
|
||||
@@ -1921,7 +1927,7 @@ dependencies = [
|
||||
"localtime",
|
||||
"log",
|
||||
"multibase",
|
||||
"nonempty",
|
||||
"nonempty 0.9.0",
|
||||
"once_cell",
|
||||
"qcheck",
|
||||
"radicle-cob",
|
||||
@@ -1947,6 +1953,7 @@ dependencies = [
|
||||
"culpa",
|
||||
"duration-str",
|
||||
"html-page",
|
||||
"nonempty 0.11.0",
|
||||
"qcheck",
|
||||
"qcheck-macros",
|
||||
"radicle",
|
||||
@@ -1980,7 +1987,7 @@ dependencies = [
|
||||
"fastrand",
|
||||
"git2",
|
||||
"log",
|
||||
"nonempty",
|
||||
"nonempty 0.9.0",
|
||||
"once_cell",
|
||||
"radicle-crypto",
|
||||
"radicle-dag",
|
||||
@@ -2063,7 +2070,7 @@ dependencies = [
|
||||
"flate2",
|
||||
"git2",
|
||||
"log",
|
||||
"nonempty",
|
||||
"nonempty 0.9.0",
|
||||
"radicle-git-ext",
|
||||
"radicle-std-ext",
|
||||
"serde",
|
||||
|
||||
@@ -15,6 +15,7 @@ anyhow = "1.0.95"
|
||||
clap = { version = "4.5.11", features = ["derive", "wrap_help"] }
|
||||
duration-str = "0.12.0"
|
||||
html-page = "0.4.0"
|
||||
nonempty = "0.11.0"
|
||||
radicle-crypto = "0.11.0"
|
||||
radicle-git-ext = "0.8.0"
|
||||
radicle-surf = { version = "0.22.0", default-features = false, features = ["serde"] }
|
||||
|
||||
+11
-14
@@ -1225,6 +1225,7 @@ pub mod trigger_from_ci_event_tests {
|
||||
pub mod helper {
|
||||
use std::{path::Path, process::Command};
|
||||
|
||||
use nonempty::{nonempty, NonEmpty};
|
||||
use radicle::prelude::{Profile, RepoId};
|
||||
|
||||
use super::{MessageError, Oid, Request, Response, RunId, RunResult};
|
||||
@@ -1290,29 +1291,25 @@ pub mod helper {
|
||||
|
||||
/// Run `git clone` for the repository.
|
||||
fn git_clone(repo_path: &Path, src: &Path) -> Result<(), MessageHelperError> {
|
||||
runcmd(
|
||||
&[
|
||||
"git",
|
||||
"clone",
|
||||
&repo_path.to_string_lossy(),
|
||||
&src.to_string_lossy(),
|
||||
],
|
||||
Path::new("."),
|
||||
)?;
|
||||
let repo_path = repo_path.to_string_lossy();
|
||||
let src = src.to_string_lossy();
|
||||
runcmd(&nonempty!["git", "clone", &repo_path, &src], Path::new("."))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Check out the requested commit.
|
||||
fn git_checkout(commit: Oid, src: &Path) -> Result<(), MessageHelperError> {
|
||||
runcmd(&["git", "config", "advice.detachedHead", "false"], src)?;
|
||||
runcmd(&["git", "checkout", &commit.to_string()], src)?;
|
||||
runcmd(
|
||||
&nonempty!["git", "config", "advice.detachedHead", "false"],
|
||||
src,
|
||||
)?;
|
||||
let commit = commit.to_string();
|
||||
runcmd(&nonempty!["git", "checkout", &commit], src)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Run a program.
|
||||
pub fn runcmd(argv: &[&str], cwd: &Path) -> Result<i32, MessageHelperError> {
|
||||
assert!(!argv.is_empty());
|
||||
|
||||
pub fn runcmd(argv: &NonEmpty<&str>, cwd: &Path) -> Result<i32, MessageHelperError> {
|
||||
let output = Command::new("bash")
|
||||
.arg("-c")
|
||||
.arg(r#""$@" 2>&1"#)
|
||||
|
||||
Reference in New Issue
Block a user