region = defaultIfBlank(region, "us-east-1");
}
@Override
protected Object executeInternal() throws Exception {
Git git = getGitRepo();
String versionLabel = null;
String commitId = null;
Ref masterRef = git.getRepository()
.getRef("master");
if (null != masterRef)
commitId = ObjectId.toString(masterRef.getObjectId());
Status status = git.status().call();
boolean pushAhead = false;
if (null != commitId && status.isClean()) {
versionLabel = lookupVersionLabelForCommitId(commitId);
if (null == versionLabel) {
getLog().info("No Changes. However, we've didn't get something close in AWS Elastic Beanstalk and we're pushing ahead");
pushAhead = true;
} else {
getLog().info("No Changes. However, we've got something close in AWS Elastic Beanstalk and we're continuing");
project.getProperties().put("beanstalk.versionLabel", versionLabel);
return null;
}
}
if (!pushAhead) {
// Asks for Existing Files to get added
git.add().setUpdate(true).addFilepattern(".").call();
// Now as for any new files (untracked)
AddCommand addCommand = git.add();
if (!status.getUntracked().isEmpty()) {
for (String s : status.getUntracked()) {
getLog().info("Adding file " + s);
addCommand.addFilepattern(s);
}
addCommand.call();
}
git.commit().setAll(true).setMessage(versionDescription).call();
masterRef = git.getRepository()
.getRef("master");
commitId = ObjectId.toString(masterRef.getObjectId());
}
String environmentName = null;
/*
* Builds the remote push URL
*/
if (null != curEnv && !skipEnvironmentUpdate)
environmentName = curEnv.getEnvironmentName();
String remote = new RequestSigner(getAWSCredentials(), applicationName,
region, commitId, environmentName, new Date()).getPushUrl();
/*
* Does the Push
*/
{
PushCommand cmd = git.//
push();
if (! silentUpload)
cmd.setProgressMonitor(new TextProgressMonitor());