mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-24 21:07:34 +00:00
Fix panic on non UTF-8 file when using Git
This commit is contained in:
parent
aff35a1643
commit
fe11b9d319
@ -252,7 +252,7 @@ sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/attributes"
|
||||
|
||||
# A sample Git repository
|
||||
# This uses cd because it's easier than telling Git where to go each time
|
||||
echo -e "\033[1m[10/13]\033[0m Creating Git testcases (1/3)"
|
||||
echo -e "\033[1m[10/13]\033[0m Creating Git testcases (1/4)"
|
||||
mkdir "$TEST_ROOT/git"
|
||||
cd "$TEST_ROOT/git"
|
||||
git init >/dev/null
|
||||
@ -281,7 +281,7 @@ sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git"
|
||||
|
||||
# A second Git repository
|
||||
# for testing two at once
|
||||
echo -e "\033[1m[11/13]\033[0m Creating Git testcases (2/3)"
|
||||
echo -e "\033[1m[11/13]\033[0m Creating Git testcases (2/4)"
|
||||
mkdir -p "$TEST_ROOT/git2/deeply/nested/directory"
|
||||
cd "$TEST_ROOT/git2"
|
||||
git init >/dev/null
|
||||
@ -321,7 +321,7 @@ sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git2"
|
||||
|
||||
# A third Git repository
|
||||
# Regression test for https://github.com/ogham/exa/issues/526
|
||||
echo -e "\033[1m[12/13]\033[0m Creating Git testcases (3/3)"
|
||||
echo -e "\033[1m[12/13]\033[0m Creating Git testcases (3/4)"
|
||||
mkdir -p "$TEST_ROOT/git3"
|
||||
cd "$TEST_ROOT/git3"
|
||||
git init >/dev/null
|
||||
@ -334,6 +334,20 @@ find "$TEST_ROOT/git3" -exec touch {} -h -t $FIXED_DATE \;
|
||||
sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git3"
|
||||
|
||||
|
||||
# A fourth Git repository
|
||||
# Regression test for https://github.com/ogham/exa/issues/698
|
||||
echo -e "\033[1m[12/13]\033[0m Creating Git testcases (4/4)"
|
||||
mkdir -p "$TEST_ROOT/git4"
|
||||
cd "$TEST_ROOT/git4"
|
||||
git init >/dev/null
|
||||
|
||||
# Create a non UTF-8 file
|
||||
touch 'P'$'\b\211''UUU'
|
||||
|
||||
find "$TEST_ROOT/git4" -exec touch {} -h -t $FIXED_DATE \;
|
||||
sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git4"
|
||||
|
||||
|
||||
# Hidden and dot file testcases.
|
||||
# We need to set the permissions of `.` and `..` because they actually
|
||||
# get displayed in the output here, so this has to come last.
|
||||
|
@ -1,5 +1,8 @@
|
||||
//! Getting the Git status of files and directories.
|
||||
|
||||
use std::ffi::OsStr;
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Mutex;
|
||||
|
||||
@ -205,6 +208,11 @@ fn repo_to_statuses(repo: &git2::Repository, workdir: &Path) -> Git {
|
||||
match repo.statuses(None) {
|
||||
Ok(es) => {
|
||||
for e in es.iter() {
|
||||
#[cfg(target_family = "unix")]
|
||||
let path = workdir.join(Path::new(OsStr::from_bytes(e.path_bytes())));
|
||||
// TODO: handle non Unix systems better:
|
||||
// https://github.com/ogham/exa/issues/698
|
||||
#[cfg(not(target_family = "unix"))]
|
||||
let path = workdir.join(Path::new(e.path().unwrap()));
|
||||
let elem = (path, e.status());
|
||||
statuses.push(elem);
|
||||
|
@ -144,6 +144,18 @@ status = 0
|
||||
tags = [ 'long', 'git' ]
|
||||
|
||||
|
||||
|
||||
# The forth Git repo: non UTF-8 file
|
||||
|
||||
[[cmd]]
|
||||
name = "‘exa --git -l’ handles non UTF8 file in Git repositories"
|
||||
shell = "exa --git -l /testcases/git4"
|
||||
stdout = { file = "outputs/git4_long.ansitxt" }
|
||||
stderr = { empty = true }
|
||||
status = 0
|
||||
tags = [ 'long', 'git' ]
|
||||
|
||||
|
||||
# Both repositories 1 and 2 at once
|
||||
|
||||
[[cmd]]
|
||||
|
1
xtests/outputs/git4_long.ansitxt
Normal file
1
xtests/outputs/git4_long.ansitxt
Normal file
@ -0,0 +1 @@
|
||||
.[1;33mr[31mw[0m[38;5;244m-[33mr[31mw[38;5;244m-[33mr[38;5;244m--[0m [1;32m0[0m cassowary [34m 1 Jan 12:34[0m [38;5;244m-[32mN[0m P[31m\u{8}[0m<30>UUU
|
Loading…
Reference in New Issue
Block a user