File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
try {
FileUtils.fileWrite(messageFile.getAbsolutePath(), message);
} catch (IOException ex) {
return new CheckInScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null,
false);
}
try {
Commandline cl = null;
if (!fileSet.getFileList().isEmpty()) {
// If specific fileSet is given, we have to git-add them first,
// otherwise we will use 'git-commit -a' later.
cl = GitAddCommand.createCommandLine(fileSet.getBasedir(), fileSet.getFileList());
exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
if (exitCode != 0) {
return new CheckInScmResult(cl.toString(), "The git-add command failed.", stderr.getOutput(), false);
}
}
// The git-commit command doesn't show single files, but only summary :/
// so we must run git-status and consume the output.
// Borrow a few things from the git-status command.
GitStatusConsumer statusConsumer = new GitStatusConsumer(getLogger(), fileSet.getBasedir());
cl = GitStatusCommand.createCommandLine(repository, fileSet);
exitCode = GitCommandLineUtils.execute(cl, statusConsumer, stderr, getLogger());
if (exitCode != 0) {
// git-status returns non-zero if nothing to do.
if (getLogger().isInfoEnabled()) {
getLogger().info("nothing added to commit but untracked files present (use \"git add\" to "
+ "track)");
}
}
cl = createCommitCommandLine(fileSet, messageFile);
exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
if (exitCode != 0) {
return new CheckInScmResult(cl.toString(), "The git-commit command failed.", stderr.getOutput(), false);
}
cl = createPushCommandLine(fileSet, repository, version);
exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
if (exitCode != 0) {
return new CheckInScmResult(cl.toString(), "The git-push command failed.", stderr.getOutput(), false);
}
List<ScmFile> checkedInFiles = new ArrayList<ScmFile>(statusConsumer.getChangedFiles().size());
// rewrite all detected files to now have status 'checked_in'
for (Object foo : statusConsumer.getChangedFiles()) {
ScmFile scmfile = new ScmFile(((ScmFile) foo).getPath(), ScmFileStatus.CHECKED_IN);
if (fileSet.getFileList().isEmpty()) {
checkedInFiles.add(scmfile);
} else {
// If a specific fileSet is given, we have to check if the file is really tracked.
for (Iterator<?> itfl = fileSet.getFileList().iterator(); itfl.hasNext();) {
File f = (File) itfl.next();
if (f.toString().equals(scmfile.getPath())) {
checkedInFiles.add(scmfile);
}
}
}
}
return new CheckInScmResult(cl.toString(), checkedInFiles);
} finally {
try {
FileUtils.forceDelete(messageFile);
} catch (IOException ex) {
// ignore