PreBuildMergeOptions mergeOptions = gitSCM.getMergeOptions();
if (mergeOptions.doMerge() && buildResult.isBetterOrEqualTo(
Result.SUCCESS)) {
RemoteConfig remote = mergeOptions.getMergeRemote();
listener.getLogger().println(new StringBuilder().append("Pushing result ")
.append(tagName)
.append(" to ")
.append(mergeOptions.getMergeTarget())
.append(" branch of ")
.append(remote.getName())
.append(" repository")
.toString());
git.push(remote, "HEAD:" + mergeOptions.getMergeTarget());
// } else {
//listener.getLogger().println("Pushing result " + buildnumber + " to origin repository");
//git.push(null);
}
return true;
}
});
} catch (Throwable e) {
listener.error("Failed to push merge to origin repository: " + e.getMessage());
build.setResult(Result.FAILURE);
mergeResult = false;
}
if (!mergeResult) {
pushResult = false;
}
}
if (isPushTags()) {
boolean allTagsResult = true;
for (final TagToPush t : tagsToPush) {
boolean tagResult = true;
if (t.getTagName() == null) {
listener.getLogger().println("No tag to push defined");
tagResult = false;
}
if (t.getTargetRepoName() == null) {
listener.getLogger().println("No target repo to push to defined");
tagResult = false;
}
if (tagResult) {
final String tagName = environment.expand(t.getTagName());
final String targetRepo = environment.expand(t.getTargetRepoName());
try {
tagResult = workingDirectory.act(new FileCallable<Boolean>() {
private static final long serialVersionUID = 1L;
public Boolean invoke(File workspace,
VirtualChannel channel) throws IOException {
IGitAPI git = new GitAPI(gitExe, new FilePath(workspace),
listener, environment);
RemoteConfig remote = gitSCM.getRepositoryByName(targetRepo);
if (remote == null) {
listener.getLogger()
.println("No repository found for target repo name " + targetRepo);
return false;
}
if (t.isCreateTag()) {
if (git.tagExists(tagName)) {
listener.getLogger()
.println("Tag " + tagName
+ " already exists and Create Tag is specified, so failing.");
return false;
}
git.tag(tagName, "Hudson Git plugin tagging with " + tagName);
} else if (!git.tagExists(tagName)) {
listener.getLogger()
.println("Tag " + tagName
+ " does not exist and Create Tag is not specified, so failing.");
return false;
}
listener.getLogger().println("Pushing tag " + tagName + " to repo "
+ targetRepo);
git.push(remote, tagName);
return true;
}
});
} catch (Throwable e) {
listener.error("Failed to push tag " + tagName + " to " + targetRepo
+ ": " + e.getMessage());
build.setResult(Result.FAILURE);
tagResult = false;
}
}
if (!tagResult) {
allTagsResult = false;
}
}
if (!allTagsResult) {
pushResult = false;
}
}
if (isPushBranches()) {
boolean allBranchesResult = true;
for (final BranchToPush b : branchesToPush) {
boolean branchResult = true;
if (b.getBranchName() == null) {
listener.getLogger().println("No branch to push defined");
return false;
}
if (b.getTargetRepoName() == null) {
listener.getLogger().println("No branch repo to push to defined");
return false;
}
final String branchName = environment.expand(b.getBranchName());
final String targetRepo = environment.expand(b.getTargetRepoName());
if (branchResult) {
try {
branchResult = workingDirectory.act(new FileCallable<Boolean>() {
private static final long serialVersionUID = 1L;
public Boolean invoke(File workspace,
VirtualChannel channel) throws IOException {
IGitAPI git = new GitAPI(gitExe, new FilePath(workspace),
listener, environment);
RemoteConfig remote = gitSCM.getRepositoryByName(targetRepo);
if (remote == null) {
listener.getLogger()
.println("No repository found for target repo name " + targetRepo);
return false;