-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreateTreeTester.java
More file actions
50 lines (42 loc) · 1.62 KB
/
CreateTreeTester.java
File metadata and controls
50 lines (42 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.*;
import java.security.NoSuchAlgorithmException;
public class CreateTreeTester {
public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
System.out.println("=== Running CreateTreeTester ===");
createTreeTester();
}
public static void createTreeTester() throws IOException, NoSuchAlgorithmException {
Git.cleanUp();
// setup directory
String baseDir = "./git/demoDir";
File mainDir = new File(baseDir);
if (!mainDir.exists()) {
mainDir.mkdir();
}
String[] fileNames = { "a.txt", "b.txt" };
String[] fileContents = {
"a text content",
"b text content"
};
for (int i = 0; i < fileNames.length; i++) {
File f = new File(baseDir + "/" + fileNames[i]);
f.createNewFile();
try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
bw.write(fileContents[i]);
}
Git.makeBlob(baseDir + "/" + fileNames[i]);
Git.updateIndex(new File(baseDir + "/" + fileNames[i]));
}
String treeSHA = Git.createTree("./git/index");
if (treeSHA != null) {
File treeFile = new File("./git/objects/" + treeSHA);
if (treeFile.exists()) {
System.out.println("Tree creation successful → " + treeSHA);
} else {
System.out.println("Tree file missing from objects folder.");
}
} else {
System.out.println("createTree() returned null — tree not created.");
}
}
}