You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ma...@apache.org on 2012/10/25 22:00:30 UTC

[1/3] git commit: [SCM-697] git add fail on windows when a lot of files to add

Updated Branches:
  refs/heads/master 94e37133f -> 26213239f


[SCM-697] git add fail on windows when a lot of files to add

Removed previous batch file workaround since this still suffers from the
line limit of 8191 characters.  Instead, added files one by
one when on Windows.

Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/26213239
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/26213239
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/26213239

Branch: refs/heads/master
Commit: 26213239f7822a404ecf775d987c8c9e6e162edc
Parents: 57a1f0a
Author: Mark Hobson <ma...@apache.org>
Authored: Thu Oct 25 20:25:39 2012 +0100
Committer: Mark Hobson <ma...@apache.org>
Committed: Thu Oct 25 20:25:39 2012 +0100

----------------------------------------------------------------------
 .../git/gitexe/command/add/GitAddCommand.java      |   76 +++++++++------
 1 files changed, 48 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/26213239/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
----------------------------------------------------------------------
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/add/GitAddCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
index 2600dcd..9a0bec5 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
@@ -19,7 +19,6 @@ package org.apache.maven.scm.provider.git.gitexe.command.add;
  * under the License.
  */
 
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFile;
@@ -38,8 +37,8 @@ import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -63,16 +62,11 @@ public class GitAddCommand
             throw new ScmException( "You must provide at least one file/directory to add" );
         }
 
-        Commandline cl = createCommandLine( fileSet.getBasedir(), fileSet.getFileList() );
-
-        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
-        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
-
-        int exitCode = GitCommandLineUtils.execute( cl, stdout, stderr, getLogger() );
+        AddScmResult result = executeAddFileSet( fileSet );
 
-        if ( exitCode != 0 )
+        if ( result != null )
         {
-            return new AddScmResult( cl.toString(), "The git-add command failed.", stderr.getOutput(), false );
+            return result;
         }
 
         // git-add doesn't show single files, but only summary :/
@@ -81,7 +75,8 @@ public class GitAddCommand
         Commandline clStatus = GitStatusCommand.createCommandLine( repository, fileSet );
 
         GitStatusConsumer statusConsumer = new GitStatusConsumer( getLogger(), fileSet.getBasedir() );
-        exitCode = GitCommandLineUtils.execute( clStatus, statusConsumer, stderr, getLogger() );
+        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+        int exitCode = GitCommandLineUtils.execute( clStatus, statusConsumer, stderr, getLogger() );
         if ( exitCode != 0 )
         {
             // git-status returns non-zero if nothing to do
@@ -105,6 +100,8 @@ public class GitAddCommand
                 }
             }
         }
+
+        Commandline cl = createCommandLine( fileSet.getBasedir(), fileSet.getFileList() );
         return new AddScmResult( cl.toString(), changedFiles );
     }
 
@@ -118,33 +115,56 @@ public class GitAddCommand
 
         GitCommandLineUtils.addTarget( cl, files );
 
-        // see MSCMPUB-2 command line can be too long for windows so generate a script file
+        return cl;
+    }
+
+    private AddScmResult executeAddFileSet( ScmFileSet fileSet )
+        throws ScmException
+    {
+        File workingDirectory = fileSet.getBasedir();
+        List<File> files = fileSet.getFileList();
+
+        // command line can be too long for windows so add files individually (see SCM-697)
         if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
         {
-            try
+            for ( File file : files )
             {
-                // TODO cleanup this file !!!
-                File tmpFile = File.createTempFile( "git-add", ".bat" );
-                FileUtils.write( tmpFile, cl.toString() );
+                AddScmResult result = executeAddFiles( workingDirectory, Collections.singletonList( file ) );
+
+                if ( result != null )
+                {
+                    return result;
+                }
+            }
+        }
+        else
+        {
+            AddScmResult result = executeAddFiles( workingDirectory, files );
 
-                cl = new Commandline();
+            if ( result != null )
+            {
+                return result;
+            }
+        }
 
-                cl.setWorkingDirectory( workingDirectory );
+        return null;
+    }
 
-                cl.setExecutable( "call" );
+    private AddScmResult executeAddFiles( File workingDirectory, List<File> files )
+        throws ScmException
+    {
+        Commandline cl = createCommandLine( workingDirectory, files );
 
-                cl.createArg().setValue( tmpFile.getAbsolutePath() );
+        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
 
-                return cl;
-            }
-            catch ( IOException e )
-            {
-                throw new ScmException( e.getMessage(), e );
-            }
+        int exitCode = GitCommandLineUtils.execute( cl, stdout, stderr, getLogger() );
 
+        if ( exitCode != 0 )
+        {
+            return new AddScmResult( cl.toString(), "The git-add command failed.", stderr.getOutput(), false );
         }
 
-        return cl;
+        return null;
     }
-
 }