8
8
public class GitUtil {
9
9
10
10
public static Boolean clone (String repoName , String usrName , Path targetDir ) {
11
+
12
+ if (targetDir .toFile ().exists ()){
13
+ FileUtil .deleteDirectory (targetDir .toFile ());
14
+ }
15
+ targetDir .toFile ().mkdirs ();
11
16
12
- String cmd = "timeout 600 git clone https://github.com/" + repoName + "/" + usrName + " " + targetDir ;
13
-
17
+ String cmd = "timeout 300 git clone https://github.com/" + repoName + "/" + usrName + " " + targetDir ;
18
+
14
19
ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , targetDir );
15
20
if (pr .exitCode == 0 ) {
16
21
return true ;
17
22
} else {
18
23
System .out .println ("cmd " + cmd + "\n " );
19
24
System .out .println ("report \n " + pr .toString ());
25
+ FileUtil .deleteDirectory (targetDir .toFile ());
20
26
return false ;
21
27
}
22
28
}
23
29
24
30
public static List <String > getAllCommitsSha (Path repoDir ) {
25
31
26
- String cmd = "timeout 600 git log --pretty=format:\" %H\" " ;
32
+ String cmd = "timeout 300 git log --pretty=format:\" %H\" " ;
27
33
28
34
ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir );
29
35
if (pr .exitCode == 0 ) {
@@ -37,7 +43,7 @@ public static List<String> getAllCommitsSha(Path repoDir) {
37
43
38
44
public static String getCommitMsg (Path repoDir , String com ) {
39
45
40
- String cmd = "git log --format=%B -n 1 " + com ;
46
+ String cmd = "timeout 300 git log --format=%B -n 1 " + com ;
41
47
42
48
ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir );
43
49
if (pr .exitCode == 0 ) {
@@ -51,7 +57,7 @@ public static String getCommitMsg(Path repoDir, String com) {
51
57
52
58
public static String getParentCommit (Path repoDir , String com ) {
53
59
54
- String cmd = "git log --pretty=%P -n 1 " + com ;
60
+ String cmd = "timeout 300 git log --pretty=%P -n 1 " + com ;
55
61
56
62
ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir );
57
63
if (pr .exitCode == 0 ) {
@@ -75,10 +81,10 @@ public static String getDiffBetween2Commits(Path repoDir, String oldCom, String
75
81
76
82
String cmd = null ;
77
83
if (diffMode != null ) {
78
- cmd = "git --git-dir " + repoDir .toString () + " /.git --work-tree " + repoDir .toString () + " diff "
84
+ cmd = "timeout 300 git --git-dir " + repoDir .toString () + " /.git --work-tree " + repoDir .toString () + " diff "
79
85
+ diffMode + " --unified=0 " + oldCom + " " + newCom ;
80
86
} else {
81
- cmd = "git --git-dir " + repoDir .toString () + " /.git --work-tree " + repoDir .toString ()
87
+ cmd = "timeout 300 git --git-dir " + repoDir .toString () + " /.git --work-tree " + repoDir .toString ()
82
88
+ " diff --unified=0 " + oldCom + " " + newCom ;
83
89
}
84
90
@@ -94,7 +100,7 @@ public static String getDiffBetween2Commits(Path repoDir, String oldCom, String
94
100
95
101
public static List <String > getChangedFileList (Path repoDir , String com ) {
96
102
97
- String cmd = "git diff-tree --no-commit-id --name-only -r " + com ;
103
+ String cmd = "timeout 300 git diff-tree --no-commit-id --name-only -r " + com ;
98
104
99
105
ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir );
100
106
if (pr .exitCode == 0 ) {
@@ -111,25 +117,25 @@ public static Boolean checkout(Path repoDir, String com, Boolean ifForce) {
111
117
ProcessUtil .ProcessReporter pr = new ProcessUtil .ProcessReporter ();
112
118
113
119
if (ifForce ) {
114
- String resetCMD = "git reset --hard" ;
120
+ String resetCMD = "timeout 300 git reset --hard" ;
115
121
pr = ProcessUtil .executeCMD (resetCMD , null , repoDir );
116
122
}
117
123
118
124
String checkoutCMD = null ;
119
125
if (com == null ) { // checkout latest if null
120
- checkoutCMD = "git checkout master" ;
126
+ checkoutCMD = "timeout 300 git checkout master" ;
121
127
} else {
122
- checkoutCMD = "git checkout " + com ;
128
+ checkoutCMD = "timeout 300 git checkout " + com ;
123
129
}
124
130
pr = ProcessUtil .executeCMD (checkoutCMD , null , repoDir );
125
131
126
132
if (pr .exitCode == 0 ) {
127
133
return true ;
128
134
} else {
129
- String cleanCMD = "git --git-dir " + repoDir .toString () + " /.git --work-tree " + repoDir .toString ()
135
+ String cleanCMD = "timeout 300 git --git-dir " + repoDir .toString () + " /.git --work-tree " + repoDir .toString ()
130
136
+ " clean -dfx ." ;
131
137
pr = ProcessUtil .executeCMD (cleanCMD , null , repoDir );
132
- String resetCMD = "git --git-dir " + repoDir .toString () + " /.git --work-tree " + repoDir .toString ()
138
+ String resetCMD = "timeout 300 git --git-dir " + repoDir .toString () + " /.git --work-tree " + repoDir .toString ()
133
139
+ " reset --hard" ;
134
140
pr = ProcessUtil .executeCMD (resetCMD , null , repoDir );
135
141
pr = ProcessUtil .executeCMD (checkoutCMD , null , repoDir );
0 commit comments