forked from pranachtarski/git-project-PRANAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitTester.java
More file actions
76 lines (68 loc) · 2.67 KB
/
GitTester.java
File metadata and controls
76 lines (68 loc) · 2.67 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
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
public class GitTester {
public static void main (String [] args){
//initialize repository
Git repo = new Git();
File test = new File("testData.txt");
//check repository initialization
File git = new File ("./git/");
File objects = new File ("./git/objects/");
File index = new File ("./git/index");
if (git.exists())
System.out.println ("/git directory creation success");
else
System.out.println ("WARNING: git directory creation failure");
if (objects.exists())
System.out.println ("/git/objects directory creation success");
else
System.out.println ("WARNING: objects directory creation failure");
if (index.exists())
System.out.println ("/index creation success");
else
System.out.println ("WARNING: index creation failure");
//check Sha1Hash
if (repo.Sha1Hash(test).equals("d720c05e3787a35beeb764524814e83ed26d0e7d"))
System.out.println ("Sha1Hash functioning properly");
else
System.out.println ("WARNING: Sha1Hash method not functioning properly (or you changed testData.txt)");
//check Hashing
repo.HashData("testData.txt");
boolean isInIndex = false;
String hashCode;
//finds compressed hashcode if nessesary
if (repo.COMPRESS_FILES)
hashCode = repo.Sha1Hash(repo.compress(test));
else
hashCode = repo.Sha1Hash(test);
//checks to see if in index
String expectedIndex = (hashCode + " " + test.getName());
try {
BufferedReader reader = new BufferedReader(new FileReader("./git/index"));
while (reader.ready()){
if (expectedIndex.equals(reader.readLine()))
isInIndex = true;
}
reader.close();
}
catch (IOException e){
e.printStackTrace();;
}
if (isInIndex)
System.out.println("Blob indexing successful");
else
System.out.println("WARNING: Blob indexing unsuccessful");
//check to see if in objects
File blob = new File("./git/objects/" + hashCode);
if (blob.exists())
System.out.println ("Blob object creation successful");
else
System.out.println ("WARNING: Blob object creation unsuccessful");
//leave true if you want repository to reset at end of test
if (false){
repo.deleteRepository();
}
}
}