Custom git driver to handle merge conflicts of your buku bookmarks.
I had the idea of using git to sync my bookmarks, which are stored as a SQLite database. The first merge conflict proved me that it was a bad idea. But I am lazy and I don't want to handle the sync service myself, so I made this tool to handle the conflicts automatically for me so that I can keep using git as a "cloud service" for my bookmarks.
Feel free to use it for your own buku git repository!
From source:
- Clone the repository.
- Install Gleam.
- Run
gleam run -m gleescript
. - Add the generated
buku_merger
to yourPATH
.
Using Nix:
This repository includes a flake which provides the package. You can test the package directly by running:
nix run "github:pierrot-lc/buku-merger"
The tool expects the following:
buku_merger <base> <current> <other>
Where:
<current>
is the local version of the bookmarks database,<other>
is the remote version conflicting with your<current>
version, and<base>
is the latest common ancestor between the two conflicting databases.
To use the tool automatically when there's a conflict, you need to add the driver to your git configuration:
# .gitconfig or config
[merge "buku-driver"]
name = "Custom buku merge driver, handling the bookmarks SQLite database"
driver = buku_merger %O %A %B
recursive = binary
Add those lines either in your ~/.config/git/config
globally or in your buku
repository at .git/config
.
Then, specify in your buku repository that you want to use that driver for bookmark conflicts:
# .gitattributes
bookmarks.db merge=buku-driver
Place this file at the root of your buku repository.
The merge conflict is handled in two phases:
- Identify rows modified in
<other>
compared to<base>
and apply those modifications to<current>
. - Find new rows in
<other>
that do not exist in<current>
and add them. Find removed rows from<other>
that are still present in<base>
and remove them from<current>
.
The final file <current>
is used by git as the merged version.
I no longer delete the bookmarks, as it is too easy to mess everything up.
This tool is made using the awesome Gleam language and uses sqlight to interface with SQLite.
The flake uses nix-gleam to generate the package derivation effortlessly.