Fix new files claiming they have permission changes

pull/647/head^2 0.56.0
Wilfred Hughes 2024-03-04 22:54:57 +07:00
parent b95e6cc6e6
commit 7346c895f0
2 changed files with 27 additions and 12 deletions

@ -352,15 +352,15 @@ impl Display for FilePermissions {
}
}
impl From<String> 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<Self, Self::Error> {
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),
)
}

@ -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();