Fix handling of yaml files when deleting entries

master
Jonathan Hodgson 4 years ago
parent a3bbe9b4a2
commit 6206986546
  1. 3
      inc/file-management
  2. 6
      kb

@ -155,6 +155,7 @@ $filename title changed
Please resolve manually"
else
mv "$filename" "$newFilename"
[ -e "$filename.yaml" ] && mv "$filename.yaml" "$newFilename.yaml"
if fileInDB "$filename"; then
echo "UPDATE items
SET (filename,title) =
@ -169,6 +170,7 @@ Please resolve manually"
sqlite3 "${sqliteFile}"
fi
getYamlTags "$filename" | assignTags "$filename"
gitChange "$filename" "$newFilename"
fi
fi
@ -187,6 +189,7 @@ deleteFile(){
read -r rsp
if [[ "$(echo "$rsp" | tr '[:upper:]' '[:lower:]')" = "y"* ]]; then
rm "$filename"
[ -e "$filename.yaml" ] && rm "$filename.yaml"
# This deletes the file from the sql database and any tag links
echo "DELETE FROM items
WHERE id = '$(safeSQL "$fileID")';

6
kb

@ -221,10 +221,15 @@ gitChange(){
if ! git diff --exit-code "$filename" > /dev/null 2>&1; then
# Changes
git add "$filename"
[ -e "$filename.yaml" ] && git add "$filename.yaml"
git commit -m "KB auto-commit: Updated: $filename"
elif [ -e "$filename.yaml" ] && ! git diff --exit-code "$filename.yaml" > /dev/null 2>&1; then
git add "$filename.yaml"
git commit -m "KB auto-commit: Updated: $filename.yaml"
elif ! git ls-files --error-unmatch "$filename" > /dev/null 2>&1; then
# New file
git add "$filename"
[ -e "$filename.yaml" ] && git add "$filename.yaml"
git commit -m "KB auto-commit: New: $filename"
fi
else
@ -235,6 +240,7 @@ gitChange(){
else
# if we get here, the file has been deleted
git add "$filename"
git add "$filename.yaml"
git commit -m "KB auto-commit: delete: $filename"
fi
fi

Loading…
Cancel
Save