Bug 564011 - Fetch silently fails when prefix ref exists
Summary: Fetch silently fails when prefix ref exists
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-05 18:50 EDT by Farid Zakaria CLA
Modified: 2020-06-05 18:52 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Farid Zakaria CLA 2020-06-05 18:50:50 EDT
Hello;

We ran into an interesting bug with JGit with the use of FetchCommand

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-8u232-b09-1~deb9u1-b09)

jgit version: org.eclipse.jgit:org.eclipse.jgit:5.6.1.202002131546-r

Relevant snippet:

    Git git = Git.open(new File("./my-repo"));   
    FetchCommand cmd = git.fetch();
    FetchResult result = cmd.call();


The Git directory contains a ref in the *packed_ref* file called `origin/release`

    cat packed-refs| grep origin/release
    32db1780da0c32959a312496e556af4bf701767c refs/remotes/origin/release

One of the commands incoming are to create a new ref `origin/release/v1.18`

    CREATE: 0000000000000000000000000000000000000000 579d87aea9a5558b6bde512c2da672f30361ee69 refs/remotes/origin/release/v1.18


JGit tries to detect this case in checkConflictingNames

https://github.com/eclipse/jgit/blob/f40b39345cd9b54473ee871bff401fe3d394ffe3/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java#L273

https://github.com/eclipse/jgit/blob/f40b39345cd9b54473ee871bff401fe3d394ffe3/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java#L165

Unfortunately, the RefDb update is aborted however the FetchResult is returned *successfully* giving the appearance that everything was OK.

I consider this to be a bug; and the aborted transaction should be surfaced to the caller.
Comment 1 Farid Zakaria CLA 2020-06-05 18:52:47 EDT
If it wasn't clear from the first comment: since a prefix of the ref (origin/release) already exists in the ref database; the creation of the new ref (release/v1.18) & all other refs from the `fetch` result are aborted.