Skip to content

Commit

Permalink
remove special handling in favor of allowing shell-avoidance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 16, 2023
1 parent 05972f1 commit b78950d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion gix-credentials/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ gix-trace = { version = "^0.1.3", path = "../gix-trace" }
thiserror = "1.0.32"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
bstr = { version = "1.3.0", default-features = false, features = ["std"]}
shell-words = "1.0"



Expand Down
22 changes: 4 additions & 18 deletions gix-credentials/src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,10 @@ impl Program {
args.insert_str(0, "credential-");
args.insert_str(0, " ");
args.insert_str(0, git_program);
let split_args = if args.find_byteset(b"\\|&;<>()$`\n*?[#~%").is_none() {
args.to_str()
.ok()
.and_then(|args| shell_words::split(args).ok().map(Vec::into_iter))
} else {
None
};
match split_args {
Some(mut args) => {
let mut cmd = Command::new(args.next().expect("non-empty input"));
cmd.args(args).arg(action.as_arg(true));
cmd
}
None => gix_command::prepare(gix_path::from_bstr(args.as_ref()).into_owned())
.arg(action.as_arg(true))
.with_shell()
.into(),
}
gix_command::prepare(gix_path::from_bstr(args.as_ref()).into_owned())
.arg(action.as_arg(true))
.with_shell_allow_argument_splitting()
.into()
}
Kind::ExternalShellScript(for_shell)
| Kind::ExternalPath {
Expand Down
14 changes: 11 additions & 3 deletions gix-credentials/tests/program/from_custom_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ fn path_with_args_that_definitely_need_shell() {
assert!(matches!(&prog.kind, Kind::ExternalPath{path_and_args} if path_and_args == input));
assert_eq!(
format!("{:?}", prog.to_command(&helper::Action::Store("egal".into()))),
format!(r#""{SH}" "-c" "/abs/name --arg --bar=\"a b\" \"$@\"" "--" "store""#)
if cfg!(windows) {
r#""/abs/name" "--arg" "--bar=a b" "store""#.to_owned()
} else {
format!(r#""{SH}" "-c" "/abs/name --arg --bar=\"a b\" \"$@\"" "--" "store""#)
}
);
}

Expand All @@ -96,7 +100,11 @@ fn path_with_simple_args() {
assert!(matches!(&prog.kind, Kind::ExternalPath{path_and_args} if path_and_args == input));
assert_eq!(
format!("{:?}", prog.to_command(&helper::Action::Store("egal".into()))),
format!(r#""{SH}" "-c" "/abs/name a b \"$@\"" "--" "store""#),
"a shell is used as well because there are arguments, and we don't do splitting ourselves. On windows, this can be a problem."
if cfg!(windows) {
r#""/abs/name" "a" "b" "store""#.to_owned()
} else {
format!(r#""{SH}" "-c" "/abs/name a b \"$@\"" "--" "store""#)
},
"a shell is used as there are arguments, and it's generally more flexible, but on windows we split ourselves"
);
}
2 changes: 1 addition & 1 deletion gix-index/src/extension/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Link {
.expect("split index file in .git folder")
.join(format!("sharedindex.{}", self.shared_index_checksum));
let mut shared_index = crate::File::at(
&shared_index_path,
shared_index_path,
object_hash,
skip_hash,
crate::decode::Options {
Expand Down

0 comments on commit b78950d

Please sign in to comment.