Skip to content

Commit faa0cde

Browse files
authored
Merge pull request #1724 from GitoxideLabs/gix-command-api
gix command api
2 parents cd9060a + c67770f commit faa0cde

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

gix-command/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,17 @@ mod prepare {
131131
/// Use a shell, but try to split arguments by hand if this can be safely done without a shell.
132132
///
133133
/// If that's not the case, use a shell instead.
134-
pub fn with_shell_allow_argument_splitting(mut self) -> Self {
134+
pub fn with_shell_allow_manual_argument_splitting(mut self) -> Self {
135135
self.allow_manual_arg_splitting = true;
136136
self.with_shell()
137137
}
138138

139+
/// Use a shell, but prohibit splitting arguments by hand even if this could be safely done without a shell.
140+
pub fn with_shell_disallow_manual_argument_splitting(mut self) -> Self {
141+
self.allow_manual_arg_splitting = false;
142+
self.with_shell()
143+
}
144+
139145
/// Configure the process to use `stdio` for _stdin.
140146
pub fn stdin(mut self, stdio: Stdio) -> Self {
141147
self.stdin = stdio;

gix-command/tests/command.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ mod prepare {
246246
#[test]
247247
fn multiple_arguments_in_one_line_with_auto_split() {
248248
let cmd = std::process::Command::from(
249-
gix_command::prepare("echo first second third").with_shell_allow_argument_splitting(),
249+
gix_command::prepare("echo first second third").with_shell_allow_manual_argument_splitting(),
250250
);
251251
assert_eq!(
252252
format!("{cmd:?}"),
@@ -313,19 +313,29 @@ mod prepare {
313313

314314
#[test]
315315
fn single_and_complex_arguments_with_auto_split() {
316-
let cmd =
317-
std::process::Command::from(gix_command::prepare("ls --foo=\"a b\"").with_shell_allow_argument_splitting());
316+
let cmd = std::process::Command::from(
317+
gix_command::prepare("ls --foo=\"a b\"").with_shell_allow_manual_argument_splitting(),
318+
);
318319
assert_eq!(
319320
format!("{cmd:?}"),
320321
format!(r#""ls" "--foo=a b""#),
321322
"splitting can also handle quotes"
322323
);
323324
}
324325

326+
#[test]
327+
fn single_and_complex_arguments_without_auto_split() {
328+
let cmd = std::process::Command::from(
329+
gix_command::prepare("ls --foo=\"a b\"").with_shell_disallow_manual_argument_splitting(),
330+
);
331+
assert_eq!(format!("{cmd:?}"), quoted(&[SH, "-c", r#"ls --foo=\"a b\""#, "--"]));
332+
}
333+
325334
#[test]
326335
fn single_and_complex_arguments_will_not_auto_split_on_special_characters() {
327-
let cmd =
328-
std::process::Command::from(gix_command::prepare("ls --foo=~/path").with_shell_allow_argument_splitting());
336+
let cmd = std::process::Command::from(
337+
gix_command::prepare("ls --foo=~/path").with_shell_allow_manual_argument_splitting(),
338+
);
329339
assert_eq!(
330340
format!("{cmd:?}"),
331341
format!(r#""{SH}" "-c" "ls --foo=~/path" "--""#),

gix-credentials/src/program/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Program {
8282
args.insert_str(0, git_program.to_string_lossy().as_ref());
8383
gix_command::prepare(gix_path::from_bstr(args.as_bstr()).into_owned())
8484
.arg(action.as_arg(true))
85-
.with_shell_allow_argument_splitting()
85+
.with_shell_allow_manual_argument_splitting()
8686
.into()
8787
}
8888
Kind::ExternalShellScript(for_shell)

0 commit comments

Comments
 (0)