File gitAttributes = new File(rootFolder, ".gitattributes");
if (!gitAttributes.exists()) {
try {
IOHelper.write(gitAttributes, getDefaultGitAttributes());
git.add().addFilepattern(".gitattributes").call();
CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage("Added default .gitattributes");
try {
commitThenPush(git, branch, commit);
} catch (Exception e) {
LOG.warn("Failed to commit initial .gitattributes. " + e, e);
}
} catch (Exception e) {
LOG.warn("Failed to write git " + gitAttributes + ". " + e, e);
}
}
System.out.println("Importing initial URLs: " + initialImportURLs);
if (Strings.isNotBlank(initialImportURLs)) {
String[] split = initialImportURLs.split(",");
if (split != null) {
for (String importURL : split) {
if (Strings.isNotBlank(importURL)) {
InputStream inputStream = null;
try {
inputStream = ConfigFacade.getSingleton().openURL(importURL);
} catch (IOException e) {
LOG.warn("Could not load initial import URL: " + importURL + ". " + e, e);
return;
}
if (inputStream == null) {
LOG.warn("Could not load initial import URL: " + importURL);
return;
}
try {
Zips.unzip(inputStream, rootFolder);
} catch (IOException e) {
LOG.warn("Failed to unzip initial import URL: " + importURL + ". " + e, e);
}
}
}
}
}
// now lets add any expanded stuff to git
int count = 0;
File[] files = rootFolder.listFiles();
if (files != null) {
for (File file : files) {
String name = file.getName();
if (!Objects.equals(".git", name) && !Objects.equals(".gitattributes", name)) {
try {
count += addFiles(git, rootFolder, file);
} catch (Exception e) {
LOG.warn("Failed to add file " + name + ". " + e, e);
}
}
}
}
// commit any changes
if (count > 0) {
CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage("Added import URLs: " + initialImportURLs);
try {
commitThenPush(git, branch, commit);
} catch (Exception e) {
LOG.warn("Failed to commit initial import of " + initialImportURLs + ". " + e, e);
}