Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] What's the best way of checking if a local branch has a remote counterpart?

Hi guys,

On http://egit.eclipse.org/r/#change,4022 I'm trying to figure out a proper
set of RefSpec for the PushCommand. What I don't like about the current
implementation is that it doesn't push changes on local branches which have
existing remote counterparts. The code I'm using for this looks like that:

Map<String, Ref> headsRefList = repo.getRefDatabase().getRefs(
Constants.R_HEADS);
Map<String, Ref> remotesRefList = repo.getRefDatabase().getRefs
(Constants.R_REMOTES);
for (Iterator<Entry<String, Ref>> iterator = headsRefList.entrySet
().iterator(); iterator.hasNext();) {
   Entry<String, Ref> entry = iterator.next();
   for (String remoteKey : remotesRefList.keySet()) {
      if (remoteKey.endsWith(entry.getKey()))
         refSpecs.add(new RefSpec(entry.getValue().getLeaf().getName()));
      }
   }
}

This makes the test I prepared pass, but it doesn't feel right. Could you
give me some tips how it should look like? Pointing to a better impl in
JGit source code would be enough. Thanks.

Cheers,
--
Tomasz Zarna



Back to the top