Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Single Branch Fetch(I'm having difficulty getting JGit to run a single branch fetch, please help!)
Single Branch Fetch [message #1837274] Tue, 26 January 2021 20:30 Go to next message
Corbin Crutchley is currently offline Corbin CrutchleyFriend
Messages: 1
Registered: January 2021
Junior Member
I'm utilizing JGit for a mobile Android app currently, and am trying to implement a toggle to `fetch` a single branch.

However, attempting to do the following:

```java
Git git;
Repository repo;
String localBranch;
String trackedBranch;
try {
git = Git.open(new File(path));
repo = git.getRepository();
localBranch = repo.getBranch();
trackedBranch = new BranchConfig(repo.getConfig(), localBranch).getTrackingBranch();
} catch (Throwable e) {
promise.reject(e);
return;
}

FetchCommand gitFetch = git.fetch()
.setRemoveDeletedRefs(prune)
.setRemote(remote)
.setProgressMonitor(new FetchMonitor());

if (singleBranch) {
// I've tried using the full `refs/remotes/origin/branchName` as well, doesn't seem to work
String remoteRef = trackedBranch.replace("refs/remotes/" + remote + "/", "");
RefSpec ref = new RefSpec(remoteRef + ":" + localBranch);

Log.d("GITSHARK", remoteRef);
Log.d("GITSHARK", ref.toString());

gitFetch
.setRefSpecs(ref);
}

gitFetch.call();
```

Simply gives me the error: `Remote does not have branchName available for fetch`

When I know the repo in question does in fact have that branch in that remote.

What am I doing wrong?
Re: Single Branch Fetch [message #1837276 is a reply to message #1837274] Wed, 27 January 2021 00:00 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1180
Registered: July 2009
Senior Member
try with a refspec refs/heads/branchname:refs/remotes/origin/branchname

- left side is the ref in the remote repository you want to fetch
- usually fetch is done from a bare repository which has no remote tracking branches
- if local repository has a working tree (is non-bare) you fetch to remote tracking branch
- local branches change when you create a new commit locally
- remote tracking branches change when you fetch new commits from another repository

see https://wiki.eclipse.org/EGit/User_Guide#Branches
Previous Topic:Again and again stuck when trying to resolve conflicts
Next Topic:Determining if a file is ignored via .gitignore
Goto Forum:
  


Current Time: Thu Aug 05 12:27:32 GMT 2021

Powered by FUDForum. Page generated in 0.03915 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top