mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-30 11:46:20 +03:00
fixed bin file size diff on untracked files (closes #171)
This commit is contained in:
parent
02bd22d3b3
commit
26f734c57d
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Fixed
|
### Fixed
|
||||||
- switch deprecated transitive dependency `net2`->`socket2` [in `crossterm`->`mio`] ([#66](https://github.com/extrawurst/gitui/issues/66))
|
- switch deprecated transitive dependency `net2`->`socket2` [in `crossterm`->`mio`] ([#66](https://github.com/extrawurst/gitui/issues/66))
|
||||||
- crash diffing stash created on command line ([#178](https://github.com/extrawurst/gitui/issues/178))
|
- crash diffing stash created on command line ([#178](https://github.com/extrawurst/gitui/issues/178))
|
||||||
|
- delta file size diff on untracked binary files ([#171](https://github.com/extrawurst/gitui/issues/171))
|
||||||
|
|
||||||
## [0.8.0] - 2020-07-06
|
## [0.8.0] - 2020-07-06
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ fn raw_diff_to_file_diff<'a>(
|
|||||||
let mut patch = Patch::from_buffers(
|
let mut patch = Patch::from_buffers(
|
||||||
&[],
|
&[],
|
||||||
None,
|
None,
|
||||||
newfile_content.as_bytes(),
|
newfile_content.as_slice(),
|
||||||
Some(&newfile_path),
|
Some(&newfile_path),
|
||||||
None,
|
None,
|
||||||
)?;
|
)?;
|
||||||
@ -283,14 +283,16 @@ fn raw_diff_to_file_diff<'a>(
|
|||||||
Ok(res.into_inner())
|
Ok(res.into_inner())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_file_content(path: &Path) -> Option<String> {
|
fn new_file_content(path: &Path) -> Option<Vec<u8>> {
|
||||||
if let Ok(meta) = fs::symlink_metadata(path) {
|
if let Ok(meta) = fs::symlink_metadata(path) {
|
||||||
if meta.file_type().is_symlink() {
|
if meta.file_type().is_symlink() {
|
||||||
if let Ok(path) = fs::read_link(path) {
|
if let Ok(path) = fs::read_link(path) {
|
||||||
return Some(path.to_str()?.to_string());
|
return Some(
|
||||||
|
path.to_str()?.to_string().as_bytes().into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if meta.file_type().is_file() {
|
} else if meta.file_type().is_file() {
|
||||||
if let Ok(content) = fs::read_to_string(path) {
|
if let Ok(content) = fs::read(path) {
|
||||||
return Some(content);
|
return Some(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,28 +461,6 @@ mod tests {
|
|||||||
assert_eq!(diff.hunks[0].lines[1].content, "test");
|
assert_eq!(diff.hunks[0].lines[1].content, "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_diff_new_binary_file_using_invalid_utf8() -> Result<()> {
|
|
||||||
let file_path = Path::new("bar");
|
|
||||||
let (_td, repo) = repo_init_empty().unwrap();
|
|
||||||
let root = repo.path().parent().unwrap();
|
|
||||||
let repo_path = root.as_os_str().to_str().unwrap();
|
|
||||||
|
|
||||||
File::create(&root.join(file_path))?
|
|
||||||
.write_all(b"\xc3\x28")?;
|
|
||||||
|
|
||||||
let diff = get_diff(
|
|
||||||
repo_path,
|
|
||||||
String::from(file_path.to_str().unwrap()),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(diff.hunks.len(), 0);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_diff_delta_size() -> Result<()> {
|
fn test_diff_delta_size() -> Result<()> {
|
||||||
let file_path = Path::new("bar");
|
let file_path = Path::new("bar");
|
||||||
@ -511,6 +491,30 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_binary_diff_delta_size_untracked() -> Result<()> {
|
||||||
|
let file_path = Path::new("bar");
|
||||||
|
let (_td, repo) = repo_init_empty().unwrap();
|
||||||
|
let root = repo.path().parent().unwrap();
|
||||||
|
let repo_path = root.as_os_str().to_str().unwrap();
|
||||||
|
|
||||||
|
File::create(&root.join(file_path))?
|
||||||
|
.write_all(b"\x00\xc7")?;
|
||||||
|
|
||||||
|
let diff = get_diff(
|
||||||
|
repo_path,
|
||||||
|
String::from(file_path.to_str().unwrap()),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
dbg!(&diff);
|
||||||
|
assert_eq!(diff.sizes, (0, 2));
|
||||||
|
assert_eq!(diff.size_delta, 2);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_diff_delta_size_commit() -> Result<()> {
|
fn test_diff_delta_size_commit() -> Result<()> {
|
||||||
let file_path = Path::new("bar");
|
let file_path = Path::new("bar");
|
||||||
|
Loading…
Reference in New Issue
Block a user