diff --git a/src/options.rs b/src/options.rs index 699b228f69..0321c23f45 100644 --- a/src/options.rs +++ b/src/options.rs @@ -352,15 +352,15 @@ impl Display for FilePermissions { } } -impl From for FilePermissions { - fn from(s: String) -> Self { - Self(s) - } -} +impl TryFrom<&OsStr> for FilePermissions { + type Error = (); -impl From<&OsStr> for FilePermissions { - fn from(s: &OsStr) -> Self { - Self(s.to_string_lossy().into_owned()) + fn try_from(s: &OsStr) -> Result { + if s == "." { + Err(()) + } else { + Ok(Self(s.to_string_lossy().into_owned())) + } } } @@ -760,8 +760,8 @@ pub(crate) fn parse_args() -> Mode { display_path.to_string_lossy().to_string(), FileArgument::from_path_argument(lhs_tmp_file), FileArgument::from_path_argument(rhs_tmp_file), - Some((*lhs_mode).into()), - Some((*rhs_mode).into()), + FilePermissions::try_from(*lhs_mode).ok(), + FilePermissions::try_from(*rhs_mode).ok(), None, ) } @@ -778,8 +778,8 @@ pub(crate) fn parse_args() -> Mode { new_name, FileArgument::from_path_argument(lhs_tmp_file), FileArgument::from_path_argument(rhs_tmp_file), - Some((*lhs_mode).into()), - Some((*rhs_mode).into()), + FilePermissions::try_from(*lhs_mode).ok(), + FilePermissions::try_from(*rhs_mode).ok(), Some(renamed), ) } diff --git a/tests/cli.rs b/tests/cli.rs index ab718e6ee8..467b5b64ab 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -202,6 +202,21 @@ fn git_style_arguments_rename() { cmd.assert().stdout(predicate_fn); } +#[test] +fn git_style_arguments_new_file() { + let mut cmd = get_base_command(); + + cmd.arg("simple.txt") + .arg("/dev/null") + .arg(".") + .arg(".") + .arg("sample_files/simple_before.txt") + .arg("abcdef1234") + .arg("100644"); + let predicate_fn = predicate::str::contains("File permissions changed").not(); + cmd.assert().stdout(predicate_fn); +} + #[test] fn drop_different_path_starts() { let mut cmd = get_base_command();