I know from Retrieve specific commit from a remote Git repository that it's possible to fetch a specific commit from a remote git repository.
However, trying to do so from JGit, it's failing. For the same repository, when I run git fetch origin 57eab609d9efda3b8ee370582c3762c0e721033d:HEAD
from terminal, the commit I want (with all its ancestors) is fetched from the remote repository. However, when I run the following using JGit, I get an exception:
RefSpec refSpec = new RefSpec()
.setSourceDestination(commitId, HEAD)
.setForceUpdate(true);
refs = Lists.newArrayList(refSpec);
git.fetch().setRemote(GIT_REMOTE_NAME)
.setTimeout(REMOTE_FETCH_TIMEOUT)
.setTransportConfigCallback(transportConfigurer)
.setCredentialsProvider(gitCredentials)
.setTagOpt(TagOpt.FETCH_TAGS)
.setRefSpecs(refs)
.call();
The exception is org.eclipse.jgit.errors.TransportException: Remote does not have 57eab609d9efda3b8ee370582c3762c0e721033d available for fetch.