88public class GitUtil {
99
1010 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 ();
1116
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+
1419 ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , targetDir );
1520 if (pr .exitCode == 0 ) {
1621 return true ;
1722 } else {
1823 System .out .println ("cmd " + cmd + "\n " );
1924 System .out .println ("report \n " + pr .toString ());
25+ FileUtil .deleteDirectory (targetDir .toFile ());
2026 return false ;
2127 }
2228 }
2329
2430 public static List <String > getAllCommitsSha (Path repoDir ) {
2531
26- String cmd = "timeout 600 git log --pretty=format:\" %H\" " ;
32+ String cmd = "timeout 300 git log --pretty=format:\" %H\" " ;
2733
2834 ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir );
2935 if (pr .exitCode == 0 ) {
@@ -37,7 +43,7 @@ public static List<String> getAllCommitsSha(Path repoDir) {
3743
3844 public static String getCommitMsg (Path repoDir , String com ) {
3945
40- String cmd = "git log --format=%B -n 1 " + com ;
46+ String cmd = "timeout 300 git log --format=%B -n 1 " + com ;
4147
4248 ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir );
4349 if (pr .exitCode == 0 ) {
@@ -51,7 +57,7 @@ public static String getCommitMsg(Path repoDir, String com) {
5157
5258 public static String getParentCommit (Path repoDir , String com ) {
5359
54- String cmd = "git log --pretty=%P -n 1 " + com ;
60+ String cmd = "timeout 300 git log --pretty=%P -n 1 " + com ;
5561
5662 ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir );
5763 if (pr .exitCode == 0 ) {
@@ -75,10 +81,10 @@ public static String getDiffBetween2Commits(Path repoDir, String oldCom, String
7581
7682 String cmd = null ;
7783 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 "
7985 + diffMode + " --unified=0 " + oldCom + " " + newCom ;
8086 } 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 ()
8288 + " diff --unified=0 " + oldCom + " " + newCom ;
8389 }
8490
@@ -94,7 +100,7 @@ public static String getDiffBetween2Commits(Path repoDir, String oldCom, String
94100
95101 public static List <String > getChangedFileList (Path repoDir , String com ) {
96102
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 ;
98104
99105 ProcessUtil .ProcessReporter pr = ProcessUtil .executeCMD (cmd , null , repoDir );
100106 if (pr .exitCode == 0 ) {
@@ -111,25 +117,25 @@ public static Boolean checkout(Path repoDir, String com, Boolean ifForce) {
111117 ProcessUtil .ProcessReporter pr = new ProcessUtil .ProcessReporter ();
112118
113119 if (ifForce ) {
114- String resetCMD = "git reset --hard" ;
120+ String resetCMD = "timeout 300 git reset --hard" ;
115121 pr = ProcessUtil .executeCMD (resetCMD , null , repoDir );
116122 }
117123
118124 String checkoutCMD = null ;
119125 if (com == null ) { // checkout latest if null
120- checkoutCMD = "git checkout master" ;
126+ checkoutCMD = "timeout 300 git checkout master" ;
121127 } else {
122- checkoutCMD = "git checkout " + com ;
128+ checkoutCMD = "timeout 300 git checkout " + com ;
123129 }
124130 pr = ProcessUtil .executeCMD (checkoutCMD , null , repoDir );
125131
126132 if (pr .exitCode == 0 ) {
127133 return true ;
128134 } 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 ()
130136 + " clean -dfx ." ;
131137 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 ()
133139 + " reset --hard" ;
134140 pr = ProcessUtil .executeCMD (resetCMD , null , repoDir );
135141 pr = ProcessUtil .executeCMD (checkoutCMD , null , repoDir );
0 commit comments