-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGitDirectory.java
More file actions
90 lines (74 loc) · 2.39 KB
/
GitDirectory.java
File metadata and controls
90 lines (74 loc) · 2.39 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
import java.io.File;
public class GitDirectory {
public static File directory = new File("git");
public static File objects = new File(directory.getPath(), "objects");
public static File index = new File(directory.getPath(), "index");
public static File HEAD = new File(directory.getPath(), "HEAD");
public static void makeGitDirectoryAndFiles(){
if (checkGitFiles() == true){
return;
}
//makes git directory
if (!directory.exists()){
directory.mkdir();
}
//makes object directory inside of git
if (!objects.exists()){
objects.mkdir();
}
// makes the index file inside of git
try {
if (!index.exists()){
index.createNewFile();
}
} catch (Exception e) {
System.out.println("Error creating: " + index);
}
//makes the HEAD file inside of git
try {
if (!HEAD.exists()){
HEAD.createNewFile();
}
} catch (Exception e) {
System.out.println("Error creating: " + HEAD);
}
System.out.println("Git Repository Created");
}
public static boolean checkGitFiles(){
if (directory.exists() && objects.exists() && index.exists() && HEAD.exists()){
System.out.println("Git Repository Already Exists");
return true;
}
return false;
}
public static void deleteGit(){
deleteObjects();
HEAD.delete();
index.delete();
objects.delete();
directory.delete();
}
public static void deleteObjects(){
File[] files = objects.listFiles();
if (files != null) {
for (File file : files) {
if (!file.delete()) {
System.out.println("Failed to delete: " + file.getPath());
}
}
}
}
public static void StressTest(int times){
for (int i = 0; i < times; i++){
makeGitDirectoryAndFiles();
deleteGit();
}
System.out.println("Did " + times + " cycles of making GIT and deleting it.");
}
public static void masterRESET(){
deleteGit();
makeGitDirectoryAndFiles();
RandomFiles.deleteRandomFileMaker();
System.out.println("Reset to blank GIT");
}
}