yadm-config/.config/yadm/hooks/pre_commit

28 lines
544 B
Bash
Executable file

#!/bin/env sh
foundSymlinks=false
for file in $(yadm diff --name-only --cached); do
lsResult=$(ls -1 -l "$file")
if [[ $lsResult != *"->"* ]]; then
break
fi
symlinkTarget=$(echo "$lsResult" | awk '{print $NF}')
if [[ $lsResult != *"##"* ]]; then
break
fi
echo "$file is a YADM symlink. Telling git to ignore it..."
yadm restore --staged "$file"
echo "$file" >>~/.gitignore
foundSymlinks=true
done
if [ $foundSymlinks ]; then
echo "Symlinks found. Adding .gitignore to commit..."
yadm add ~/.gitignore
fi