Skip to content

Commit 27049da

Browse files
committed
chore(pre-commit/update-deprecated-links): exclude untracked files
The pre-commit script `update-deprecated-links` creates dangling links to untracked files (such as the text editor's backup files, the manually backed up files, some files that will be added later, etc.). These dangling links would block creating the commit. In this patch, we check if the target path is tracked by git or not before creating the symbolic link. We also would not try to remove untracked files or regular files in `test/deprecated/completions/`. We would only remove tracked links.
1 parent 8a34543 commit 27049da

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
#!/bin/bash
22
set -euo pipefail
33

4+
is_tracked_by_git()
5+
{
6+
git ls-files --error-unmatch "$1" &>/dev/null
7+
}
8+
49
cd "$(dirname "$0")/completions"
510
for f in *; do
6-
case $f in
7-
Makefile* | README.md) ;;
8-
*) git rm -f $f ;;
9-
esac
11+
if [[ -h $f ]] && is_tracked_by_git "$f"; then
12+
git rm -f "$f"
13+
fi
1014
done
1115
for f in ../../../completions/_*; do
12-
ln -sf $f ${f##*/_}
13-
git add --verbose ${f##*/_}
16+
if is_tracked_by_git "$f"; then
17+
ln -sf $f ${f##*/_}
18+
git add --verbose ${f##*/_}
19+
fi
1420
done

0 commit comments

Comments
 (0)