summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2024-03-04 22:54:57 -0800
committerWilfred Hughes <me@wilfred.me.uk>2024-03-04 22:54:57 -0800
commit7346c895f02ea6b2dddb34efe5e14291fccd3ae8 (patch)
tree2a0e51167882372c3bb9e2024f4a536bde0ab11e
parentb95e6cc6e6d8141e87e86d467851f7d271dddb46 (diff)
Fix new files claiming they have permission changes0.56.0
-rw-r--r--src/options.rs24
-rw-r--r--tests/cli.rs15
2 files changed, 27 insertions, 12 deletions
diff --git a/src/options.rs b/src/options.rs
index 699b228f6..0321c23f4 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -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),
)
}
diff --git a/tests/cli.rs b/tests/cli.rs
index ab718e6ee..467b5b64a 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -203,6 +203,21 @@ fn git_style_arguments_rename() {
}
#[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();