langfield / ki

version control for Anki collections
https://langfield.github.io/ki/
GNU Affero General Public License v3.0
80 stars 3 forks source link

What happens when a user deletes a card symlink? #156

Closed langfield closed 1 year ago

langfield commented 1 year ago

The Anki program does not allow you to delete individual cards, you can only delete notes. Possibly we could add a commit-hook that deletes the other links and the target note in .ki/notes/ if any cards are missing.

That seems bad though, anything that deletes files automatically is bad. Instead it could detect when cards are missing and warn the user. There should be a ki mkcards <guid> subcommand that regenerates cards. You give it a guid and it regenerates all missing card symlinks depending on what deck you're current in. Possibly it should take the deck as an argument instead of using the current working directory.

So the commit hook would do something like this:

$ git commit
warning: Missing cards 'Card 2', 'Card 3' for note '<guid>'
warning: ~~~~~~~ CONTENTS OF SORT FIELD '<name>' FOR NOTE '<guid>' ~~~~~~~
warning: <sortf>
warning: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: Remove note with: rm 'aa.Card 1.md && rm <guid>.md
warning: Regenerate missing cards with ki mkcards <guid> <target deck>
warning: Aborting commit.

But actually, maybe it is just better to delete the note. Because it is not deleting any old file. It is deleting a file that was committed and then its deletion was also committed. So there's no chance of data loss.

langfield commented 1 year ago

If we say, "deleting symlinks means delete the note", then what happens if the user deletes a symlink but makes an edit to the note source???? That is bad.

langfield commented 1 year ago

How about a pre-commit hook that just prints a warning and reverts the deletion of symlinks? You must make changes to the note source in .ki/notes/ if you want to get rid of it or something. The pre-commit hook will prune dangling symlinks.

langfield commented 1 year ago

This will be made obsolete by #157.