Skip to content

Commit 7346c89

Browse files
committed
Fix new files claiming they have permission changes
1 parent b95e6cc commit 7346c89

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/options.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ impl Display for FilePermissions {
352352
}
353353
}
354354

355-
impl From<String> for FilePermissions {
356-
fn from(s: String) -> Self {
357-
Self(s)
358-
}
359-
}
355+
impl TryFrom<&OsStr> for FilePermissions {
356+
type Error = ();
360357

361-
impl From<&OsStr> for FilePermissions {
362-
fn from(s: &OsStr) -> Self {
363-
Self(s.to_string_lossy().into_owned())
358+
fn try_from(s: &OsStr) -> Result<Self, Self::Error> {
359+
if s == "." {
360+
Err(())
361+
} else {
362+
Ok(Self(s.to_string_lossy().into_owned()))
363+
}
364364
}
365365
}
366366

@@ -760,8 +760,8 @@ pub(crate) fn parse_args() -> Mode {
760760
display_path.to_string_lossy().to_string(),
761761
FileArgument::from_path_argument(lhs_tmp_file),
762762
FileArgument::from_path_argument(rhs_tmp_file),
763-
Some((*lhs_mode).into()),
764-
Some((*rhs_mode).into()),
763+
FilePermissions::try_from(*lhs_mode).ok(),
764+
FilePermissions::try_from(*rhs_mode).ok(),
765765
None,
766766
)
767767
}
@@ -778,8 +778,8 @@ pub(crate) fn parse_args() -> Mode {
778778
new_name,
779779
FileArgument::from_path_argument(lhs_tmp_file),
780780
FileArgument::from_path_argument(rhs_tmp_file),
781-
Some((*lhs_mode).into()),
782-
Some((*rhs_mode).into()),
781+
FilePermissions::try_from(*lhs_mode).ok(),
782+
FilePermissions::try_from(*rhs_mode).ok(),
783783
Some(renamed),
784784
)
785785
}

tests/cli.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ fn git_style_arguments_rename() {
202202
cmd.assert().stdout(predicate_fn);
203203
}
204204

205+
#[test]
206+
fn git_style_arguments_new_file() {
207+
let mut cmd = get_base_command();
208+
209+
cmd.arg("simple.txt")
210+
.arg("/dev/null")
211+
.arg(".")
212+
.arg(".")
213+
.arg("sample_files/simple_before.txt")
214+
.arg("abcdef1234")
215+
.arg("100644");
216+
let predicate_fn = predicate::str::contains("File permissions changed").not();
217+
cmd.assert().stdout(predicate_fn);
218+
}
219+
205220
#[test]
206221
fn drop_different_path_starts() {
207222
let mut cmd = get_base_command();

0 commit comments

Comments
 (0)