{
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
{
if ( !fileSet.getFileList().isEmpty() )
{
// if specific fileSet is given, we have to git-add them first
// otherwise we will use 'git-commit -a' later
Commandline clAdd = GitAddCommand.createCommandLine( fileSet.getBasedir(), fileSet.getFileList() );
exitCode = GitCommandLineUtils.execute( clAdd, stdout, stderr, getLogger() );
if ( exitCode != 0 )
{
return new CheckInScmResult( clAdd.toString(), "The git-add command failed.", stderr.getOutput(),
false );
}
}
// git-commit 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
Commandline clStatus = GitStatusCommand.createCommandLine( repository, fileSet );
GitStatusConsumer statusConsumer = new GitStatusConsumer( getLogger(), fileSet.getBasedir() );
exitCode = GitCommandLineUtils.execute( clStatus, 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)" );
}
}
if ( statusConsumer.getChangedFiles().isEmpty() )
{
return new CheckInScmResult( null, statusConsumer.getChangedFiles() );
}
Commandline clCommit = createCommitCommandLine( repository, fileSet, messageFile );
exitCode = GitCommandLineUtils.execute( clCommit, stdout, stderr, getLogger() );
if ( exitCode != 0 )
{
return new CheckInScmResult( clCommit.toString(), "The git-commit command failed.", stderr.getOutput(),
false );
}
if( repo.isPushChanges() )
{
Commandline cl = createPushCommandLine( getLogger(), repository, fileSet, 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 ( ScmFile changedFile : statusConsumer.getChangedFiles() )
{
ScmFile scmfile = new ScmFile( changedFile.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 ( File f : fileSet.getFileList() )
{
if ( f.toString().equals( scmfile.getPath() ) )
{
checkedInFiles.add( scmfile );
}
}
}
}
return new CheckInScmResult( clCommit.toString(), checkedInFiles );
}
finally
{
try
{