radicle-link icon indicating copy to clipboard operation
radicle-link copied to clipboard

libgit2 does not respect force flag

Open FintanH opened this issue 4 years ago • 0 comments

We ran into a scenario that meant that a peer can end up on a previous commit despite having the latest commit beforehand. The scenario was discovered by the following interactions.

There are 3 peers, A, B, and Seed.

  1. A creates a project X and announces it to Seed
  2. Seed replicates the project and has commit P
  3. B replicates the project from Seed and has commit P
  4. A pushes a commit Q and announces to Seed
  5. Seed replicates from A
  6. Seed announces to B
  7. B replicates from Seed, which in turn kicks off rere (mutual replication)
  8. rere wins the race against the replication of B from the Seed
  9. Seed replicates and has commit P -- the initial commit
  10. B replicates from Seed and stays at commit P

Initially, we thought it was messing up by setting the wrong force value, but after setting it to false the situation was not remedied.

The issue can be replicated using two local repositories and a script using git2 to fetch an outdated branch.

Digging into the issue further, we did some spelunking in the libgit2 code to see how the force flag might be used. From what we could see, it wasn't be used at all and we found this issue which also agrees that the force flags aren't respected.

It seems we will have to work around this until a patch is (possibly) added. One solution we've mentioned is having some kind of staging area for references that we fetch into and check if they are fast-forwards or not.

FintanH avatar Apr 30 '21 08:04 FintanH