List of usage examples for org.eclipse.jgit.api PushCommand add
public PushCommand add(String nameOrSpec)
From source file:jbyoshi.gitupdate.processor.Push.java
License:Apache License
private static void process(Repository repo, Git git, String remote, Collection<String> branches, Report report) throws Exception { // Figure out if anything needs to be pushed. Map<String, ObjectId> oldIds = new HashMap<>(); boolean canPush = false; for (String branch : branches) { BranchConfig config = new BranchConfig(repo.getConfig(), branch); ObjectId target = repo.getRef(branch).getObjectId(); Ref remoteRef = repo.getRef(config.getRemoteTrackingBranch()); if (remoteRef == null || !target.equals(remoteRef.getObjectId())) { canPush = true;/* w ww.j ava 2 s . c om*/ } oldIds.put(branch, remoteRef == null ? ObjectId.zeroId() : remoteRef.getObjectId()); } if (!canPush) { return; } PushCommand push = git.push().setCredentialsProvider(Prompts.INSTANCE).setTimeout(5).setRemote(remote); for (String branch : branches) { push.add(Constants.R_HEADS + branch); } for (PushResult result : push.call()) { for (RemoteRefUpdate update : result.getRemoteUpdates()) { if (update.getStatus() == RemoteRefUpdate.Status.OK) { String branchName = Utils.getShortBranch(update.getSrcRef()); ObjectId oldId = oldIds.get(branchName); String old = oldId.equals(ObjectId.zeroId()) ? "new branch" : oldId.name(); report.newChild(branchName + ": " + old + " -> " + update.getNewObjectId().name()).modified(); } } } }