Skip to content

Commit fe11b9d

Browse files
committed
Fix panic on non UTF-8 file when using Git
1 parent aff35a1 commit fe11b9d

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

devtools/dev-create-test-filesystem.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/attributes"
252252

253253
# A sample Git repository
254254
# This uses cd because it's easier than telling Git where to go each time
255-
echo -e "\033[1m[10/13]\033[0m Creating Git testcases (1/3)"
255+
echo -e "\033[1m[10/13]\033[0m Creating Git testcases (1/4)"
256256
mkdir "$TEST_ROOT/git"
257257
cd "$TEST_ROOT/git"
258258
git init >/dev/null
@@ -281,7 +281,7 @@ sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git"
281281

282282
# A second Git repository
283283
# for testing two at once
284-
echo -e "\033[1m[11/13]\033[0m Creating Git testcases (2/3)"
284+
echo -e "\033[1m[11/13]\033[0m Creating Git testcases (2/4)"
285285
mkdir -p "$TEST_ROOT/git2/deeply/nested/directory"
286286
cd "$TEST_ROOT/git2"
287287
git init >/dev/null
@@ -321,7 +321,7 @@ sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git2"
321321

322322
# A third Git repository
323323
# Regression test for https://github.com/ogham/exa/issues/526
324-
echo -e "\033[1m[12/13]\033[0m Creating Git testcases (3/3)"
324+
echo -e "\033[1m[12/13]\033[0m Creating Git testcases (3/4)"
325325
mkdir -p "$TEST_ROOT/git3"
326326
cd "$TEST_ROOT/git3"
327327
git init >/dev/null
@@ -334,6 +334,20 @@ find "$TEST_ROOT/git3" -exec touch {} -h -t $FIXED_DATE \;
334334
sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git3"
335335

336336

337+
# A fourth Git repository
338+
# Regression test for https://github.com/ogham/exa/issues/698
339+
echo -e "\033[1m[12/13]\033[0m Creating Git testcases (4/4)"
340+
mkdir -p "$TEST_ROOT/git4"
341+
cd "$TEST_ROOT/git4"
342+
git init >/dev/null
343+
344+
# Create a non UTF-8 file
345+
touch 'P'$'\b\211''UUU'
346+
347+
find "$TEST_ROOT/git4" -exec touch {} -h -t $FIXED_DATE \;
348+
sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git4"
349+
350+
337351
# Hidden and dot file testcases.
338352
# We need to set the permissions of `.` and `..` because they actually
339353
# get displayed in the output here, so this has to come last.

src/fs/feature/git.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Getting the Git status of files and directories.
22
3+
use std::ffi::OsStr;
4+
#[cfg(target_family = "unix")]
5+
use std::os::unix::ffi::OsStrExt;
36
use std::path::{Path, PathBuf};
47
use std::sync::Mutex;
58

@@ -205,6 +208,11 @@ fn repo_to_statuses(repo: &git2::Repository, workdir: &Path) -> Git {
205208
match repo.statuses(None) {
206209
Ok(es) => {
207210
for e in es.iter() {
211+
#[cfg(target_family = "unix")]
212+
let path = workdir.join(Path::new(OsStr::from_bytes(e.path_bytes())));
213+
// TODO: handle non Unix systems better:
214+
// https://github.com/ogham/exa/issues/698
215+
#[cfg(not(target_family = "unix"))]
208216
let path = workdir.join(Path::new(e.path().unwrap()));
209217
let elem = (path, e.status());
210218
statuses.push(elem);

xtests/git.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ status = 0
144144
tags = [ 'long', 'git' ]
145145

146146

147+
148+
# The forth Git repo: non UTF-8 file
149+
150+
[[cmd]]
151+
name = "‘exa --git -l’ handles non UTF8 file in Git repositories"
152+
shell = "exa --git -l /testcases/git4"
153+
stdout = { file = "outputs/git4_long.ansitxt" }
154+
stderr = { empty = true }
155+
status = 0
156+
tags = [ 'long', 'git' ]
157+
158+
147159
# Both repositories 1 and 2 at once
148160

149161
[[cmd]]

xtests/outputs/git4_long.ansitxt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N P\u{8}�UUU

0 commit comments

Comments
 (0)