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

Method commit

src/main/java/club/qqtim/command/Commit.java:38–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36 }
37
38 private String commit() {
39 // calc the commit message
40 WriteTree writeTree = new WriteTree();
41 String commitMessage = String.format("%s %s\n", ConstantVal.TREE, writeTree.call());
42
43 // set last commit as parent commit
44 String headId = ZitContext.getRef(ConstantVal.HEAD).getValue();
45 if (headId != null) {
46 commitMessage += String.format("%s %s\n", ConstantVal.PARENT, headId);
47 }
48
49 String mergedHead = ZitContext.getRef(ConstantVal.MERGE_HEAD).getValue();
50 if (mergedHead != null) {
51 commitMessage += String.format("%s %s\n", ConstantVal.PARENT, mergedHead);
52 ZitContext.deleteRef(ConstantVal.MERGE_HEAD, false);
53 }
54
55 // write commit message
56 commitMessage += String.format("\n%s\n", message);
57
58 // write commit object and return commit id
59 final String commitId = HashObject.hashObject(commitMessage.getBytes(Charsets.UTF_8), ConstantVal.COMMIT);
60 ZitContext.updateRef(ConstantVal.HEAD, new RefValue(false, commitId));
61 return commitId;
62 }
63
64
65 public static CommitObject getCommit(String id) {

Callers 1

callMethod · 0.95

Calls 5

callMethod · 0.95
getRefMethod · 0.95
deleteRefMethod · 0.95
hashObjectMethod · 0.95
updateRefMethod · 0.95

Tested by

no test coverage detected