* @throws Exception
*/
public static FetchResult fetchRepository(CredentialsProvider credentialsProvider,
Repository repository, RefSpec... refSpecs) throws Exception {
Git git = new Git(repository);
FetchCommand fetch = git.fetch();
List<RefSpec> specs = new ArrayList<RefSpec>();
if (refSpecs == null || refSpecs.length == 0) {
specs.add(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
specs.add(new RefSpec("+refs/tags/*:refs/tags/*"));
specs.add(new RefSpec("+refs/notes/*:refs/notes/*"));
} else {
specs.addAll(Arrays.asList(refSpecs));
}
if (credentialsProvider != null) {
fetch.setCredentialsProvider(credentialsProvider);
}
fetch.setRefSpecs(specs);
FetchResult fetchRes = fetch.call();
return fetchRes;
}