-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest.java
More file actions
71 lines (63 loc) · 2.84 KB
/
Test.java
File metadata and controls
71 lines (63 loc) · 2.84 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.*;
import java.nio.file.*;
import java.util.List;
public class Test extends Git {
public static void main(String[] args) throws IOException {
git = makeFolder("git");
objects = makeFolder("objects", git);
index = makeFile("index", git);
HEAD = makeFile("HEAD", git);
resetObjects();
resetIndex();
new File("projects").mkdir();
new File("projects/myProgram").mkdir();
new File("projects/myProgram/scripts").mkdir();
try (FileOutputStream out = new FileOutputStream("projects/myProgram/scripts/README.md")) {
out.write("readme\n".getBytes());
}
try (FileOutputStream out = new FileOutputStream("projects/myProgram/Hello.txt")) {
out.write("hello world\n".getBytes());
}
try (FileOutputStream out = new FileOutputStream("projects/myProgram/scripts/Hello.txt")) {
out.write("hello world\n".getBytes());
}
try (FileOutputStream out = new FileOutputStream("projects/myProgram/scripts/Cat.java")) {
out.write("class Cat {}\n".getBytes());
}
File readme = new File("projects/myProgram/scripts/README.md");
File helloA = new File("projects/myProgram/Hello.txt");
File helloB = new File("projects/myProgram/scripts/Hello.txt");
File cat = new File("projects/myProgram/scripts/Cat.java");
File scripts = new File("projects/myProgram/scripts");
File myProgram = new File("projects/myProgram");
addToIndex(readme);
addToIndex(helloA);
addToIndex(helloB);
addToIndex(cat);
String scriptsTree = tree(scripts);
String rootTree = tree(myProgram);
System.out.println("trees built: scripts=" + scriptsTree + " root=" + rootTree);
System.out.println("Working List:");
workingList();
File wl = new File("git/workinglist");
if (wl.exists()) {
List<String> lines = Files.readAllLines(wl.toPath());
for (String line : lines) System.out.println(line);
}
else System.out.println("No working list found.");
GitWrapper gw = new GitWrapper();
gw.init();
gw.add("projects/myProgram/Hello.txt");
gw.add("projects/myProgram/scripts/README.md");
gw.add("projects/myProgram/scripts/Hello.txt");
gw.commit("John Doe", "Initial commit");
gw.checkout("1234567890");
new File("projects/myProgram/scripts/README.md").delete();
new File("projects/myProgram/Hello.txt").delete();
new File("projects/myProgram/scripts/Hello.txt").delete();
new File("projects/myProgram/scripts/Cat.java").delete();
new File("projects/myProgram/scripts").delete();
new File("projects/myProgram").delete();
new File("projects").delete();
}
}