-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGitHashTester.java
More file actions
132 lines (113 loc) · 4.76 KB
/
GitHashTester.java
File metadata and controls
132 lines (113 loc) · 4.76 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class GitHashTester {
public static void main(String[] args) throws IOException {
GitHash.cleanObjectsAndINDEX();
GitHash.add("goofy_ahh/wow.txt");
GitHash.add("goofy_ahh/BEANS/dawg.txt");
GitHash.add("goofy_ahh/goofy_nahhh/snog/dog.txt");
GitHash.stageFolders();
// PriorityQueue<WorkingDirectoryInfo> q = GitHash.convertIndexToWorkingDirectory();
// System.out.println(q.poll().size());
// System.out.println(q.poll().size());
// System.out.println(q.poll().size());
// GitHash.writeDirContents(new File("./goofy_ahh"));
// System.out.println();
// GitHash.gitRepoInit();
// System.out.println();
// testGenerateSHA1Hash();
// System.out.println();
// indexMethodsTester(5, 20);
}
public static void gitRepoInitTester() throws IOException {
GitHash.deleteGitDirectory();
areAllFilesDeleted();
System.out.println();
GitHash.gitRepoInit();
areAllFilesInitialized();
GitHash.deleteGitDirectory();
areAllFilesDeleted();
System.out.println();
GitHash.createDirectoryIfMissing("git");
GitHash.gitRepoInit();
areAllFilesInitialized();
GitHash.deleteGitDirectory();
areAllFilesDeleted();
System.out.println();
GitHash.createDirectoryIfMissing("git");
GitHash.createDirectoryIfMissing("git/objects");
GitHash.gitRepoInit();
areAllFilesInitialized();
GitHash.deleteGitDirectory();
areAllFilesDeleted();
System.out.println();
GitHash.gitRepoInit();
GitHash.gitRepoInit();
areAllFilesInitialized();
GitHash.deleteGitDirectory();
areAllFilesDeleted();
}
public static void areAllFilesInitialized() {
File gitFile = new File("git");
File objectsFile = new File("git/objects");
File headFile = new File("git/HEAD");
File indexFile = new File("git/INDEX");
if (gitFile.exists() && objectsFile.exists() && headFile.exists() && indexFile.exists()) {
System.out.println("All Files Are Initialized");
} else {
System.out.println("Some Files Missing");
}
}
public static void areAllFilesDeleted() {
File gitFile = new File("git");
File objectsFile = new File("git/objects");
File headFile = new File("git/HEAD");
File indexFile = new File("git/INDEX");
if (!(gitFile.exists() || objectsFile.exists() || headFile.exists() || indexFile.exists())) {
System.out.println("All Files Are Deleted");
} else {
System.out.println("Some Files Still Exist");
}
}
public static void testGenerateSHA1Hash() throws IOException {
File testFileHash = new File("testFileHash.txt");
testFileHash.createNewFile();
FileWriter testFileHashWriter = new FileWriter(testFileHash);
testFileHashWriter.write("I believe in you. Keep coding!");
testFileHashWriter.close();
System.out.println(
"From SHA1 website should output:\n657ea366b820a51f36ff13e8236f574e7cfb5e81\nMethod outputs:\n"
+ GitHash.generateSHA1Hash(testFileHash));
}
public static void doBLOBMethodsWork() throws IOException {
File testFileBLOB = new File("testFileHash.txt");
testFileBLOB.createNewFile();
FileWriter testFileBLOBWriter = new FileWriter(testFileBLOB);
testFileBLOBWriter.write("Gott hilft denen, die sich selbst helfen.");
testFileBLOBWriter.close();
GitHash.blobExists(testFileBLOB);
GitHash.createBLOBAndAddToObjects(testFileBLOB);
GitHash.blobExists(testFileBLOB);
// GitHash.deleteBLOBFromObjects(testFileBLOB);
// GitHash.blobExists(testFileBLOB);
}
public static void indexMethodsTester(int numFiles, int fileLength) throws IOException {
for (int i = 0; i < numFiles; i++) {
File newTestFile = new File("testFile" + i + ".txt");
newTestFile.createNewFile();
FileWriter testFileWriter = new FileWriter(newTestFile);
String fileContents = "";
for (int j = 0; j < fileLength; j++) {
fileContents += (char) (Math.random() * 94 + 33);
}
testFileWriter.write(fileContents);
testFileWriter.close();
GitHash.createBLOBAndAddToObjects(newTestFile);
GitHash.addBLOBEntryToIndex(newTestFile.getName());
doIndexEntriesMatchActualFiles(newTestFile);
}
}
public static void doIndexEntriesMatchActualFiles(File newTestFile) throws IOException {
}
}