forked from eluhnow1/git-project-edwin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitTester.java
More file actions
70 lines (67 loc) · 3.18 KB
/
gitTester.java
File metadata and controls
70 lines (67 loc) · 3.18 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
import java.nio.file.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.security.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.zip.*;
import java.io.FileReader;
import java.io.FileWriter;
public class gitTester {
public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
File example = new File ("./example.txt");
System.out.println("******************************** Testing initialization: ******************************\n\n");
Git seansGit = new Git("seansTestRepo");
Git seansOtherGit = new Git ("seansTestRepo");
System.out.println("^ Should say that the repo was initialized, and then already exists");
Path indexPath = Paths.get("./seansTestRepo/git/index");
Files.deleteIfExists(indexPath);
System.out.println("...deleted index file, now trying to initialize the same repo...");
Git seansNewGit = new Git ("seansTestRepo");
System.out.println("^ Should say that the repo was initialized successfully.");
seansNewGit.deleteRepo();
seansGit.deleteRepo();
seansOtherGit.deleteRepo();
System.out.println("\n\n\n*************************** Testing blob creation ***************************");
Git seansGit2 = new Git("seansTestRepo");
seansGit2.setZipToggle(false);
seansGit2.makeBlob(example);
File index = new File ("./seansTestRepo/git/index");
FileReader fr = new FileReader (index);
System.out.print("\nIndex file contents after attempted blob creation:");
while (fr.ready()){
System.out.print((char)fr.read());
}
File hashFile = new File ("./seansTestRepo/git/objects/" + seansGit2.sha1Code(example.getPath()));
if (hashFile.exists()){
System.out.println("\n\nHashFile exists; blob was created successfully.");
}
fr.close();
seansGit2 = resetTestFiles(seansGit2);
System.out.println("\n\n\n******************************** Testing zip-compression for blob data ***************************\n\n");
seansGit2.makeBlob(example);
seansGit2.setZipToggle(true);
seansGit2.makeBlob(example);
FileReader freader = new FileReader (seansGit2.getIndex());
System.out.print("\nIndex file contents after attempted blob creation:\n");
while (freader.ready()){
System.out.print((char)freader.read());
}
File compressedFile = new File ("./seansTestRepo/git/objects/" + seansGit2.sha1Code("./example.txt.zip"));
System.out.println("\n The size of the uncompressed file is: " + hashFile.length() + " bytes. The length of the compressed file is: " + compressedFile.length() + " bytes.");
freader.close();
seansGit2.deleteRepo();
}
public static Git resetTestFiles (Git git) throws IOException{
git.deleteRepo();
return new Git("seansRepo");
}
}