MCPcopy Create free account
hub / github.com/ReZeroS/git / push

Method push

src/main/java/club/qqtim/command/Push.java:52–88  ·  view source on GitHub ↗
(String remotePath, String refName)

Source from the content-addressed store, hash-verified

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

Callers 2

runMethod · 0.95
generateSnakesMethod · 0.80

Calls 9

getRemoteRefsMethod · 0.95
getRefMethod · 0.95
isAncestorOfMethod · 0.95
getCurrentDirMethod · 0.95
setRootPathContextMethod · 0.95
pushObjectMethod · 0.95
updateRefMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected