forked from reposense/RepoSense
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitDownloader.java
More file actions
47 lines (40 loc) · 1.79 KB
/
GitDownloader.java
File metadata and controls
47 lines (40 loc) · 1.79 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
package reposense.git;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import reposense.model.RepoConfiguration;
import reposense.system.CommandRunner;
import reposense.system.LogsManager;
import reposense.util.FileUtil;
/**
* Clones the repository from GitHub.
*/
public class GitDownloader {
private static final Logger logger = LogsManager.getLogger(GitDownloader.class);
public static void downloadRepo(RepoConfiguration repoConfig)
throws GitDownloaderException {
try {
FileUtil.deleteDirectory(repoConfig.getRepoRoot());
logger.info("Cloning " + repoConfig.getLocation() + "...");
CommandRunner.cloneRepo(repoConfig.getLocation(), repoConfig.getRepoName());
logger.info("Cloning completed!");
} catch (RuntimeException rte) {
logger.log(Level.SEVERE, "Error encountered in Git Cloning, will attempt to continue analyzing", rte);
throw new GitDownloaderException(rte);
//Due to an unsolved bug on Windows Git, for some repository, Git Clone will return an error even
// though the repo is cloned properly.
} catch (IOException ioe) {
throw new GitDownloaderException(ioe);
}
try {
if (repoConfig.getBranch().equals(RepoConfiguration.DEFAULT_BRANCH)) {
String currentBranch = CommandRunner.getCurrentBranch(repoConfig.getRepoRoot());
repoConfig.setBranch(currentBranch);
}
GitChecker.checkout(repoConfig.getRepoRoot(), repoConfig.getBranch());
} catch (RuntimeException e) {
logger.log(Level.SEVERE, "Branch does not exist! Analyze terminated.", e);
throw new GitDownloaderException(e);
}
}
}