// pull current branch
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't pull.");
Preconditions.checkState(currHead.get() instanceof SymRef,
"Can't pull from detached HEAD");
final SymRef headRef = (SymRef) currHead.get();
final String currentBranch = Ref.localName(headRef.getTarget());
refSpecs.add(currentBranch + ":" + currentBranch);
}
for (String refspec : refSpecs) {
String[] refs = refspec.split(":");
Preconditions.checkArgument(refs.length < 3,
"Invalid refspec, please use [+]<remoteref>[:<localref>].");
boolean force = refspec.length() > 0 && refspec.charAt(0) == '+';
String remoteref = refs[0].substring(force ? 1 : 0);
Optional<Ref> sourceRef = findRemoteRef(remoteref);
if (!sourceRef.isPresent()) {
continue;
}
String destinationref = "";
if (refs.length == 2) {
destinationref = refs[1];
} else {
// pull into current branch
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
Preconditions.checkState(currHead.isPresent(),
"Repository has no HEAD, can't pull.");
Preconditions.checkState(currHead.get() instanceof SymRef,
"Can't pull from detached HEAD");
final SymRef headRef = (SymRef) currHead.get();
destinationref = headRef.getTarget();
}
Optional<Ref> destRef = command(RefParse.class).setName(destinationref).call();
if (destRef.isPresent()) {
if (destRef.get().getObjectId().equals(sourceRef.get().getObjectId())