I've needed this a few times but failed to fine it.
Here's the link for next time: https://github.com/elihunter173/dirbuf.nvim
FWIW, this would be lovely is implemented as an external helper which only commits if exit code == 0.