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 a0cc80d
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 32 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.

2 changes: 1 addition & 1 deletion gitoxide-core/src/pack/multi_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn entries(multi_index_path: PathBuf, format: OutputFormat, mut out: impl st
if format != OutputFormat::Human {
bail!("Only human format is supported right now");
}
let file = gix::odb::pack::multi_index::File::at(&multi_index_path)?;
let file = gix::odb::pack::multi_index::File::at(multi_index_path)?;
for entry in file.iter() {
writeln!(out, "{} {} {}", entry.oid, entry.pack_index, entry.pack_offset)?;
}
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/repository/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn query(
let index = repo.index()?;
let mut cache = repo.excludes(
&index,
Some(gix::ignore::Search::from_overrides(&mut overrides.into_iter())),
Some(gix::ignore::Search::from_overrides(overrides.into_iter())),
Default::default(),
)?;

Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/repository/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn from_list(
let object_hash = gix::hash::Kind::Sha1;

let mut index = gix::index::State::new(object_hash);
for path in std::io::BufReader::new(std::fs::File::open(&entries_file)?).lines() {
for path in std::io::BufReader::new(std::fs::File::open(entries_file)?).lines() {
let path: PathBuf = path?.into();
if !path.is_relative() {
bail!("Input paths need to be relative, but {path:?} is not.")
Expand Down
1 change: 1 addition & 0 deletions gix-attributes/tests/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod value {
}

#[test]
#[allow(invalid_from_utf8)]
fn from_value() {
assert!(std::str::from_utf8(ILLFORMED_UTF8).is_err());
assert!(
Expand Down
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
4 changes: 2 additions & 2 deletions gix-pack/tests/pack/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod version {
#[test]
fn lookup() -> Result<(), Box<dyn std::error::Error>> {
let object_hash = gix_hash::Kind::Sha1;
let file = index::File::at(&fixture_path(INDEX_V1), object_hash)?;
let file = index::File::at(fixture_path(INDEX_V1), object_hash)?;
for (id, desired_index, assertion) in &[
(&b"036bd66fe9b6591e959e6df51160e636ab1a682e"[..], Some(0), "first"),
(b"f7f791d96b9a34ef0f08db4b007c5309b9adc3d6", Some(65), "close to last"),
Expand Down Expand Up @@ -63,7 +63,7 @@ mod version {
#[test]
fn lookup() -> Result<(), Box<dyn std::error::Error>> {
let object_hash = gix_hash::Kind::Sha1;
let file = index::File::at(&fixture_path(INDEX_V2), object_hash)?;
let file = index::File::at(fixture_path(INDEX_V2), object_hash)?;
for (id, expected, assertion_message, hex_len) in [
(&b"0ead45fc727edcf5cadca25ef922284f32bb6fc1"[..], Some(0), "first", 4),
(b"e800b9c207e17f9b11e321cc1fba5dfe08af4222", Some(29), "last", 40),
Expand Down
2 changes: 1 addition & 1 deletion gix/src/remote/connection/fetch/update_refs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mod update {

#[test]
fn checked_out_branches_in_worktrees_are_rejected_with_additional_information() -> Result {
let root = gix_path::realpath(&gix_testtools::scripted_fixture_read_only_with_args(
let root = gix_path::realpath(gix_testtools::scripted_fixture_read_only_with_args(
"make_fetch_repos.sh",
[base_repo_path()],
)?)?;
Expand Down
3 changes: 1 addition & 2 deletions gix/tests/repository/shallow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ mod traverse {
#[test]
#[parallel]
fn complex_graphs_can_be_iterated_despite_multiple_shallow_boundaries() -> crate::Result {
let base =
gix_path::realpath(&gix_testtools::scripted_fixture_read_only("make_remote_repos.sh")?.join("base"))?;
let base = gix_path::realpath(gix_testtools::scripted_fixture_read_only("make_remote_repos.sh")?.join("base"))?;
let shallow_base = gix_testtools::scripted_fixture_read_only_with_args(
"make_complex_shallow_repo.sh",
Some(base.to_string_lossy()),
Expand Down

0 comments on commit a0cc80d

Please sign in to comment.