| 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) { |