Skip to content

Instantly share code, notes, and snippets.

@cimentadaj
Created August 13, 2020 15:16
Show Gist options
  • Save cimentadaj/f30bc7aac30dd278c04e4c487ae6e83a to your computer and use it in GitHub Desktop.
Save cimentadaj/f30bc7aac30dd278c04e4c487ae6e83a to your computer and use it in GitHub Desktop.
#!/bin/bash
MSG="use 'git commit --no-verify' to override this check"
files=$(ls -d vignettes/* | grep -Ei '\.orig$')
for fl in $files; do
# Remove .orig from the vignette files
rmd=$(echo $fl | sed 's/.orig//')
# Remove .Rmd to get the raw file name
vignettefile=$(echo $rmd | sed 's/.Rmd//')
# Check if the raw file name has changed in git (regardless of whether
# it's the .orig of .Rmd)
vignettes=($(git diff --name-only | grep -Ei $vignettefile))
if
[[ "$fl" -nt "$rmd" ]]; then
echo -e "$rmd is out of date; Please re-knit $fl\n$MSG"
exit 1
elif
[[ ${#vignettes[*]} -lt 2 && ${#vignettes[*]} -gt 0 ]]; then
echo -e "$fl and $rmd should be both staged\n$MSG"
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment