(String remotePath, String refName)
| 50 | } |
| 51 | |
| 52 | private void push(String remotePath, String refName) { |
| 53 | final List<RefObjValue> remoteRefs = Fetch.getRemoteRefs(remotePath); |
| 54 | final RefObjValue remoteRef = remoteRefs.stream().filter(e -> e.getRefName().equals(refName)).findAny().orElse(null); |
| 55 | |
| 56 | final String localRef = ZitContext.getRef(refName).getValue(); |
| 57 | |
| 58 | // new branch or have common parent commit |
| 59 | if(!(Objects.isNull(remoteRef) || isAncestorOf(localRef, remoteRef.getValue()))){ |
| 60 | log.error("force pushed fail"); |
| 61 | throw new IllegalArgumentException("can be forced push"); |
| 62 | |
| 63 | } |
| 64 | |
| 65 | final String currentDir = FileUtil.getCurrentDir(); |
| 66 | FileUtil.setRootPathContext(remotePath); |
| 67 | |
| 68 | final List<String> knownRemoteRefs = remoteRefs.stream().map(RefObjValue::getValue).filter(ZitContext::objectExists).collect(Collectors.toList()); |
| 69 | final Set<String> remoteObjects = new HashSet<>(ZitContext.iteratorObjectsInCommits(knownRemoteRefs)); |
| 70 | |
| 71 | FileUtil.setRootPathContext(currentDir); |
| 72 | |
| 73 | |
| 74 | final Set<String> localObjects = new HashSet<>(ZitContext.iteratorObjectsInCommits(Collections.singletonList(localRef))); |
| 75 | final List<String> objectsToPush = localObjects.stream().filter(object -> !remoteObjects.contains(object)).collect(Collectors.toList()); |
| 76 | |
| 77 | // only push missing objects |
| 78 | for (String objectId : objectsToPush) { |
| 79 | ZitContext.pushObject(objectId, remotePath); |
| 80 | } |
| 81 | |
| 82 | FileUtil.setRootPathContext(remotePath); |
| 83 | { |
| 84 | ZitContext.updateRef(refName, new RefValue(false, localRef)); |
| 85 | } |
| 86 | FileUtil.setRootPathContext(currentDir); |
| 87 | |
| 88 | } |
| 89 | |
| 90 | |
| 91 |
no test coverage detected