This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch SCM-797
in repository https://gitbox.apache.org/repos/asf/maven-scm.git

commit f3877d91d0d68f3655bd669e07647eb88c88429e
Author: Rado Murin <rado.mu...@gmail.com>
AuthorDate: Mon Apr 13 09:34:57 2015 +0200

    [SCM-797] gitexe checkIn() fails due to Windows command line length
    limitation
    
    This workaround executes 'git add' on a per-file basis to avoid length
    limitation. The git commit has to be a generic one to avoid another
    failure by providing the same lengthly list again.
    
    This closes #30, #41, #49
---
 .../gitexe/command/checkin/GitCheckInCommand.java  | 54 ++++++++++++++--------
 1 file changed, 35 insertions(+), 19 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 e30aae0..1766aca 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.branch.GitBranchCommand;
 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.File;
 import java.io.IOException;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -66,7 +68,7 @@ public class GitCheckInCommand
         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,27 +88,46 @@ public class GitCheckInCommand
                 // 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 )
                 {
-                    return new CheckInScmResult( clAdd.toString(), "The 
git-add command failed.", stderr.getOutput(),
-                                                 false );
+                    return new CheckInScmResult( clAdd.toString(), "The 
git-add command failed.",
+                                                 stderr.getOutput(), false );
                 }
 
             }
-            
+
             // SCM-709: statusCommand uses repositoryRoot instead of 
workingDirectory, adjust it with
             // relativeRepositoryPath
             Commandline clRevparse = 
GitStatusCommand.createRevparseShowToplevelCommand( fileSet );
-            
+
             stdout = new CommandLineUtils.StringStreamConsumer();
             stderr = new CommandLineUtils.StringStreamConsumer();
 
             URI relativeRepositoryPath = null;
-            
+
             exitCode = GitCommandLineUtils.execute( clRevparse, stdout, 
stderr, getLogger() );
             if ( exitCode != 0 )
             {
@@ -139,7 +160,7 @@ public class GitCheckInCommand
                                           + "track)" );
                 }
             }
-            
+
             if ( statusConsumer.getChangedFiles().isEmpty() )
             {
                 return new CheckInScmResult( null, 
statusConsumer.getChangedFiles() );
@@ -154,7 +175,7 @@ public class GitCheckInCommand
                                              false );
             }
 
-            if ( repo.isPushChanges() ) 
+            if ( repo.isPushChanges() )
             {
                 Commandline cl = createPushCommandLine( getLogger(), 
repository, fileSet, version );
 
@@ -163,7 +184,7 @@ public class GitCheckInCommand
                 {
                     return new CheckInScmResult( cl.toString(), "The git-push 
command failed.", stderr.getOutput(),
                                                  false );
-                }                
+                }
             }
 
             List<ScmFile> checkedInFiles = new ArrayList<ScmFile>( 
statusConsumer.getChangedFiles().size() );
@@ -218,14 +239,14 @@ public class GitCheckInCommand
         Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( 
fileSet.getBasedir(), "push" );
 
         String branch = GitBranchCommand.getCurrentBranch( logger, repository, 
fileSet );
-        
+
         if ( branch == null || branch.length() == 0 )
         {
             throw new ScmException( "Could not detect the current branch. 
Don't know where I should push to!" );
         }
-        
+
         cl.createArg().setValue( repository.getPushUrl() );
-        
+
         cl.createArg().setValue( "refs/heads/" + branch + ":" + "refs/heads/" 
+ branch );
 
         return cl;
@@ -248,11 +269,6 @@ public class GitCheckInCommand
             // commit all tracked files
             cl.createArg().setValue( "-a" );
         }
-        else
-        {
-            // specify exactly which files to commit
-            GitCommandLineUtils.addTarget( cl, fileSet.getFileList() );
-        }
 
         if ( GitUtil.getSettings().isCommitNoVerify() )
         {

-- 
To stop receiving notification emails like this one, please contact
micha...@apache.org.

Reply via email to