/** * Updates the remote ref that matches the given refspec. * * @param refspec the ref to update * @param commitId the new value of the ref * @param delete if true, the remote ref will be deleted * @return the updated ref */ @Override protected Optional<Ref> updateRemoteRef(String refspec, ObjectId commitId, boolean delete) { Optional<Ref> updatedRef = remoteRepo.command(UpdateRef.class).setName(refspec) .setNewValue(commitId).setDelete(delete).call(); if (updatedRef.isPresent()) { final Ref remoteHead = headRef().orNull(); if (remoteHead instanceof SymRef) { if (((SymRef) remoteHead).getTarget().equals(updatedRef.get().getName())) { remoteRepo.command(UpdateSymRef.class).setName(Ref.HEAD) .setNewValue(updatedRef.get().getName()).call(); RevCommit commit = remoteRepo.getCommit(commitId); remoteRepo.workingTree().updateWorkHead(commit.getTreeId()); remoteRepo.index().updateStageHead(commit.getTreeId()); } } } return updatedRef; }
/** * Updates the remote ref that matches the given refspec. * * @param refspec the ref to update * @param commitId the new value of the ref * @param delete if true, the remote ref will be deleted * @return the updated ref */ @Override protected Optional<Ref> updateRemoteRef(String refspec, ObjectId commitId, boolean delete) { Optional<Ref> updatedRef = remoteRepo.command(UpdateRef.class).setName(refspec) .setNewValue(commitId).setDelete(delete).call(); if (updatedRef.isPresent()) { final Ref remoteHead = headRef().orNull(); if (remoteHead instanceof SymRef) { if (((SymRef) remoteHead).getTarget().equals(updatedRef.get().getName())) { remoteRepo.command(UpdateSymRef.class).setName(Ref.HEAD) .setNewValue(updatedRef.get().getName()).call(); RevCommit commit = remoteRepo.getCommit(commitId); remoteRepo.workingTree().updateWorkHead(commit.getTreeId()); remoteRepo.index().updateStageHead(commit.getTreeId()); } } } return updatedRef; }