forked from jreiner16/GitStage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitTester.java
More file actions
88 lines (76 loc) · 2.87 KB
/
GitTester.java
File metadata and controls
88 lines (76 loc) · 2.87 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.io.IOException;
public class GitTester {
public static void main(String args[]) {
clearFiles();
GitWrapper gw = new GitWrapper();
testInit(gw);
testFileAddition(gw);
testBuildCommit(gw);
}
public static void testBuildCommit(GitWrapper gw) {
System.out.println("\n--TEST COMMIT--");
try {
System.out.println("[1st commit]");
String commitHash = gw.commit("author", "message");
System.out.println("sha1 | " + commitHash);
System.out.println("hash contents | " + Utils.readFile("ProjectFolder/git/objects/" + commitHash));
System.out.println("\n[2nd commit]");
String commitHash2 = gw.commit("author", "message");
System.out.println("sha1 | " + commitHash2);
System.out.println("hash contents | " + Utils.readFile("ProjectFolder/git/objects/" + commitHash2));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void testFileAddition(GitWrapper gw) {
try {
Utils.makeDir("ProjectFolder/testFiles");
Utils.makeFile("ProjectFolder/testFiles/testFile.txt", "hello");
Utils.makeFile("ProjectFolder/testFile.txt", "hello.txt");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("\n--TEST FILE ADDITION--");
try {
System.out.println("[adding dir]");
gw.add("testFiles");
} catch (IOException e) {
System.out.println(e);
}
try {
System.out.println("\n[adding file that dne]");
gw.add("testFileDNE.txt");
} catch (IOException e) {
System.out.println(e);
}
try {
System.out.println("\n[adding file (base) + more than once]");
gw.add("ProjectFolder/testFile.txt");
gw.add("ProjectFolder/testFile.txt");
System.out.println("index contents | " + Utils.readFile("ProjectFolder/git/index"));
} catch (IOException e) {
System.out.println(e);
}
try {
System.out.println("\n[adding file in folder");
gw.add("ProjectFolder/testFiles/testFile.txt");
System.out.println("index contents | " + Utils.readFile("ProjectFolder/git/index"));
} catch (IOException e) {
System.out.println(e);
}
}
public static void testInit(GitWrapper gw) {
System.out.println("--TEST INIT--\n[test init]");
gw.init();
System.out.println("[already exists case]");
gw.init();
}
public static void clearFiles() {
try {
Utils.deleteDirectory("ProjectFolder");
System.out.println("[files cleared]\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}