Bug 578621 - An error occured on cloning the git repo with lfs support, if the path to the repository is specified without *.git
Summary: An error occured on cloning the git repo with lfs support, if the path to the...
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 6.1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-07 10:03 EST by Nail Samatov CLA
Modified: 2022-02-08 08:33 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nail Samatov CLA 2022-02-07 10:03:27 EST
For example we have git repository https://git-server.com/foo/bar
and it uses LFS.

Native git supports cloning (and checkout later) for both urls:
1) https://git-server.com/foo/bar
2) https://git-server.com/foo/bar.git

If you use JGit with built-in LFS support, only second case works.
First case doesn't work, we get error message:
"When trying to open a connection to https://github.com/sanail/tmp-lfs/info/lfs/objects/batch the server responded with an error code. rc=403"

According to Git LFS documentation both URLs are correct and should work.

Please see this document: https://github.com/git-lfs/git-lfs/blob/main/docs/api/server-discovery.md

***** quote *****
Guessing the Server

By default, Git LFS will append .git/info/lfs to the end of a Git remote url to build the LFS server URL it will use:

Git Remote: https://git-server.com/foo/bar
LFS Server: https://git-server.com/foo/bar.git/info/lfs

Git Remote: https://git-server.com/foo/bar.git
LFS Server: https://git-server.com/foo/bar.git/info/lfs
***** quote *****

In the JGit only second case is supported for now.

Example of the code:
        BuiltinLFS.register();

        try (Git cloned = Git.cloneRepository()
                .setURI(uri)
                .setDirectory(local)
                .setNoCheckout(true)
                .call()) {

            String branch = "main";
            cloned.branchCreate()
                    .setName(branch)
                    .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
                    .setStartPoint(Constants.DEFAULT_REMOTE_NAME + "/" + branch)
                    .call();

            LfsFactory.getInstance().getInstallCommand().setRepository(cloned.getRepository()).call();

            cloned.checkout().setName(branch).call();
        }
Comment 1 Eclipse Genie CLA 2022-02-07 10:17:32 EST
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/190527
Comment 3 Thomas Wolf CLA 2022-02-08 08:33:37 EST
Thanks, Nail!