Skip to content

Commit 64bd1b9

Browse files
authored
Merge pull request ogham#584 from msehnout/fix-panic-on-broken-symlink
fix panic on broken symlink in git repository
2 parents 8a71135 + a7a8e99 commit 64bd1b9

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
@@ -489,6 +489,21 @@ Vagrant.configure(2) do |config|
489489
sudo chown #{user}:#{user} -R "#{test_dir}/git2"
490490
EOF
491491

492+
# A third Git repository
493+
# Regression test for https://github.com/ogham/exa/issues/526
494+
config.vm.provision :shell, privileged: false, inline: <<-EOF
495+
set -xe
496+
mkdir -p "#{test_dir}/git3"
497+
cd "#{test_dir}/git3"
498+
git init
499+
500+
# Create a symbolic link pointing to a non-existing file
501+
ln -s aaa/aaa/a b
502+
503+
find "#{test_dir}/git3" -exec touch {} -t #{some_date} \\;
504+
sudo chown #{user}:#{user} -R "#{test_dir}/git3"
505+
EOF
506+
492507
# Hidden and dot file testcases.
493508
# We need to set the permissions of `.` and `..` because they actually
494509
# 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
@@ -266,11 +266,11 @@ impl Git {
266266
fn reorient(path: &Path) -> PathBuf {
267267
use std::env::current_dir;
268268
// I’m not 100% on this func tbh
269-
match current_dir() {
269+
let path = match current_dir() {
270270
Err(_) => Path::new(".").join(&path),
271271
Ok(dir) => dir.join(&path),
272-
}.canonicalize().unwrap() // errors can be ignored here because they only occur if
273-
// the path does not exist / a component is not a folder
272+
};
273+
path.canonicalize().unwrap_or(path)
274274
}
275275

276276
/// 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)