Skip to content

Commit a7a8e99

Browse files
author
Martin Sehnoutka
committed
fix panic on broken symlink in git repository
The issue including reproducer is described here: #526 This commit includes proposed change as well as integration test.
1 parent 89c861f commit a7a8e99

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Vagrantfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,21 @@ Vagrant.configure(2) do |config|
484484
sudo chown #{user}:#{user} -R "#{test_dir}/git2"
485485
EOF
486486

487+
# A third Git repository
488+
# Regression test for https://github.com/ogham/exa/issues/526
489+
config.vm.provision :shell, privileged: false, inline: <<-EOF
490+
set -xe
491+
mkdir -p "#{test_dir}/git3"
492+
cd "#{test_dir}/git3"
493+
git init
494+
495+
# Create a symbolic link pointing to a non-existing file
496+
ln -s aaa/aaa/a b
497+
498+
find "#{test_dir}/git3" -exec touch {} -t #{some_date} \\;
499+
sudo chown #{user}:#{user} -R "#{test_dir}/git3"
500+
EOF
501+
487502
# Hidden and dot file testcases.
488503
# We need to set the permissions of `.` and `..` because they actually
489504
# get displayed in the output here, so this has to come last.

src/fs/feature/git.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ impl Git {
265265
fn reorient(path: &Path) -> PathBuf {
266266
use std::env::current_dir;
267267
// I’m not 100% on this func tbh
268-
match current_dir() {
268+
let path = match current_dir() {
269269
Err(_) => Path::new(".").join(&path),
270270
Ok(dir) => dir.join(&path),
271-
}.canonicalize().unwrap() // errors can be ignored here because they only occur if
272-
// the path does not exist / a component is not a folder
271+
};
272+
path.canonicalize().unwrap_or(path)
273273
}
274274

275275
/// The character to display if the file has been modified, but not staged.

xtests/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ $exa $testcases/git2/target -l --git 2>&1 | diff -q - $results
210210
$exa $testcases/git2/deeply/nested/repository -l --git 2>&1 | diff -q - $results/git_2_repository || exit 1
211211
$exa $testcases/git2/{deeply,ignoreds,target} -l --git 2>&1 | diff -q - $results/git_2_all || exit 1
212212

213+
# Regressions test
214+
$exa $testcases/git3 -l --git &>/dev/null || echo "Failed to display broken symlink in git repository"; exit 1
215+
213216
COLUMNS=150 $exa $testcases/git/**/* $testcases --git --long --grid -d | diff -q - $results/git_1_files || exit 1
214217

215218
$exa $testcases/git $testcases/git2 --git --long | diff -q - $results/git_12 || exit 1

0 commit comments

Comments
 (0)