Skip to content

Commit

Permalink
Fix new files claiming they have permission changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Mar 5, 2024
1 parent b95e6cc commit 7346c89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}
}

Expand Down Expand Up @@ -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,
)
}
Expand All @@ -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),
)
}
Expand Down
15 changes: 15 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7346c89

Please sign in to comment.