-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGit.java
More file actions
44 lines (41 loc) · 1.23 KB
/
Git.java
File metadata and controls
44 lines (41 loc) · 1.23 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
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class Git {
//global variable to enable or disable compressing
public static final boolean COMPRESS = false;
public Git () {
}
public void initRepo() throws IOException
{
if(new File("git/index").exists())
{
System.out.println("Git Repository already exists");
}
else{
File objects = new File("git/objects");
objects.mkdirs();
File index = new File("git/index");
index.createNewFile();
}
}
public void checkAndDeleteRepo() // checks and deletes git directory and everythibg inside
{
File git = new File("git");
if(git.exists())
{
deleteDirectory(git);
}
}
public void deleteDirectory(File file) // recursively deletes all the directories and files in a directory
//adapted from https://stackoverflow.com/questions/20281835/how-to-delete-a-folder-with-files-using-java
{
File[] contents = file.listFiles();
if (contents != null) {
for (File f : contents) {
deleteDirectory(f);
}
}
file.delete();
}
}