From cd19b2572be17088cc1eaf6872eeb3fb034f0984 Mon Sep 17 00:00:00 2001 From: Rado Murin Date: Mon, 13 Apr 2015 09:34:57 +0200 Subject: [PATCH] SCM-714: mvn release:prepare fails if the command line is too long on windows Submitted by: Radovan Murin A workaround for the Windows terminal command limit This fix changes the behaviour of git add on Windows machines. The git add is to be executed per file. The git commit has to be a generic one --- .../command/checkin/GitCheckInCommand.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java index e30aae0c3..b9622797c 100644 --- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java @@ -38,6 +38,7 @@ import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusCommand; import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusConsumer; import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; @@ -45,6 +46,7 @@ import java.io.IOException; import java.net.URI; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -66,7 +68,7 @@ protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, Sc CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); - int exitCode; + int exitCode = -1; File messageFile = FileUtils.createTempFile( "maven-scm-", ".commit", null ); try @@ -86,9 +88,28 @@ protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, Sc // 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() ); + Commandline clAdd = null; - exitCode = GitCommandLineUtils.execute( clAdd, stdout, stderr, getLogger() ); + //SCM-714: Workaround for the Windows terminal command limit + if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) + { + for ( File file: fileSet.getFileList() ) + { + clAdd = GitAddCommand.createCommandLine( fileSet.getBasedir(), + Collections.singletonList( file ) ); + exitCode = GitCommandLineUtils.execute( clAdd, stdout, stderr, getLogger() ); + + if ( exitCode != 0 ) + { + break; + } + } + } + else + { + clAdd = GitAddCommand.createCommandLine( fileSet.getBasedir(), fileSet.getFileList() ); + exitCode = GitCommandLineUtils.execute( clAdd, stdout, stderr, getLogger() ); + } if ( exitCode != 0 ) { @@ -248,11 +269,6 @@ public static Commandline createCommitCommandLine( GitScmProviderRepository repo // commit all tracked files cl.createArg().setValue( "-a" ); } - else - { - // specify exactly which files to commit - GitCommandLineUtils.addTarget( cl, fileSet.getFileList() ); - } if ( GitUtil.getSettings().isCommitNoVerify() ) {