mirage / irmin

Irmin is a distributed database that follows the same design principles as Git
https://irmin.org
ISC License
1.85k stars 157 forks source link

Fix root path issue with `Irmin-git`, and remove `allow_duplicate` for root spec key #2326

Closed zazedd closed 1 month ago

zazedd commented 2 months ago

This PR addresses an issue with the repository root path in an Irmin-git repo that follows a preceding Irmin-git repo. Additionally, it eliminates the potential for duplicate root entries in an Irmin config.

Irmin-git issue

The issue arose when trying to create two Irmin-git repos one after the other:

let users_cfg = Irmin_git.config ~bare:true "./db/users"
let pipeline_cfg = Irmin_git.config ~bare:true "./db/pipeline"

...

let* users = UserStore.Repo.v users_cfg
let* pipeline = PipelineStore.Repo.v pipeline_cfg

After creating pipeline_cfg, the users repository is unable to find its root, as when Irmin-git creates a "fresh root key", it overrides the Univ function that was able to decode the root directory string for users from the config's Univ map. This results in a new git repo being created in the project's current working directory, which isn't the expected behavior and can even break an existing git repository.

Duplicate root entry

After fixing the issue with Irmin-git, I noticed it was only possible because of the allow_duplicates flag. I believe that it allows for a dangerous operation that should not be performed.

zazedd commented 2 months ago

The newest commit: