I understand the concept of Git fetch. I would like to fetch objects through the FetchCommand class in the JGit API.
I have a Git repository. For example C:\jGit\.git.
I have cloned this repository. For example: C:\jGitClone\jGit\.git.
I have cloned this repository again. For example C:\Users\user\Desktop\jGitClone\.git.
Using the JGit API I have a Git class:
Git git = new Git(repository); // this is the cloned repository. C:\jGitClone\jGit\.git
How would I set the cloned repository which is on the desktop so when the fetch is called it knows to fetch into the this repository.
I have looked on some websites including the 1 below but still stuck.
Git fetch failing using jgit: Remote does not have <branchname> available for fetch
I think you missed something. in Git/jGit, a local copy is determined by a
path(like in a file system), and aremote, which is a distant repo.In your case, you want that your desktop cloned repo has a link to your
jGitClone/jGitrepo. So first, if the cloning is already done, then the desktop repo knows about its remote repo. So in your code, you just need to tell where your desktop repo is:The code might not be directly working (I didn’t test it, the doubts I have are on the path to give, and the objects to use:
Builder,Git), but it’s based on this answer that I think will help you: JGit and finding the HeadBy the way, your question is not that clear : did you already clone everything or is it what you want to do? in your code you mention a
repository: did you obtain it using code similar to what I suggested? The names you chose are not very clear either : calling a repo jGit, unless it contains jGit source code, sounds a bit clumsy. Plus, give names to your different repos (A,B,C) to have a clearer understanding.