maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1034733 - in /maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg: ./ command/ command/checkin/ command/inventory/ command/tag/
Date Sat, 13 Nov 2010 11:56:30 GMT
Author: olamy
Date: Sat Nov 13 11:56:29 2010
New Revision: 1034733

URL: http://svn.apache.org/viewvc?rev=1034733&view=rev
Log:
[SCM-583] mvn release:prepare fails when there is a different branch in hg outgoing changes
SUbmitted by Laurent Perez

Added:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgChangeSet.java
  (with props)
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
  (with props)
Modified:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommandConstants.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/tag/HgTagCommand.java

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java?rev=1034733&r1=1034732&r2=1034733&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
Sat Nov 13 11:56:29 2010
@@ -27,6 +27,8 @@ import org.apache.maven.scm.log.DefaultL
 import org.apache.maven.scm.log.ScmLogger;
 import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
 import org.apache.maven.scm.provider.hg.command.HgConsumer;
+import org.apache.maven.scm.provider.hg.command.inventory.HgChangeSet;
+import org.apache.maven.scm.provider.hg.command.inventory.HgOutgoingConsumer;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
@@ -98,9 +100,9 @@ public class HgUtils
             {
                 HgConfig config = new HgConfig( workingDir );
                 providerMsg =
-                    "\nEXECUTION FAILED" + "\n  Execution of cmd : " + cmdAndArgs[0] + "
failed with exit code: "
-                        + exitCode + "." + "\n  Working directory was: " + "\n    " + workingDir.getAbsolutePath()
-                        + config.toString( workingDir ) + "\n";
+                    "\nEXECUTION FAILED" + "\n  Execution of cmd : " + cmdAndArgs[0] + "
failed with exit code: " +
+                        exitCode + "." + "\n  Working directory was: " + "\n    " + workingDir.getAbsolutePath()
+
+                        config.toString( workingDir ) + "\n";
                 if ( logger.isErrorEnabled() )
                 {
                     logger.error( providerMsg );
@@ -112,8 +114,8 @@ public class HgUtils
         catch ( ScmException se )
         {
             String msg =
-                "EXECUTION FAILED" + "\n  Execution failed before invoking the Hg command.
Last exception:"
-                    + "\n    " + se.getMessage();
+                "EXECUTION FAILED" + "\n  Execution failed before invoking the Hg command.
Last exception:" + "\n    " +
+                    se.getMessage();
 
             //Add nested cause if any
             if ( se.getCause() != null )
@@ -197,13 +199,22 @@ public class HgUtils
         throws ScmException
     {
 
-        String[] revCmd = new String[]{HgCommandConstants.REVNO_CMD};
+        String[] revCmd = new String[]{ HgCommandConstants.REVNO_CMD };
         HgRevNoConsumer consumer = new HgRevNoConsumer( logger );
         HgUtils.execute( consumer, logger, workingDir, revCmd );
 
         return consumer.getCurrentRevisionNumber();
     }
 
+    public static String getCurrentBranchName( ScmLogger logger, File workingDir )
+        throws ScmException
+    {
+        String[] branchnameCmd = new String[]{ HgCommandConstants.BRANCH_NAME_CMD };
+        HgBranchnameConsumer consumer = new HgBranchnameConsumer( logger );
+        HgUtils.execute( consumer, logger, workingDir, branchnameCmd );
+        return consumer.getBranchName();
+    }
+
     /**
      * Get current (working) revision.
      * <p/>
@@ -237,4 +248,67 @@ public class HgUtils
             return revNo;
         }
     }
+
+    /**
+     * Get current (working) branch name
+     */
+    private static class HgBranchnameConsumer
+        extends HgConsumer
+    {
+
+        private String branchName;
+
+        HgBranchnameConsumer( ScmLogger logger )
+        {
+            super( logger );
+        }
+
+        public void doConsume( ScmFileStatus status, String trimmedLine )
+        {
+            branchName = String.valueOf( trimmedLine );
+        }
+
+        String getBranchName()
+        {
+            return branchName;
+        }
+    }
+
+
+    /**
+     * Check if there are outgoing changes on a different branch. If so, Mercurial default
behaviour
+     * is to block the push and warn using a 'push creates new remote branch !' message.
+     * We also warn, and return true if a different outgoing branch was found
+     * <p/>
+     * Method users should not stop the push on a negative return, instead, they should hg
push -r(branch being released)
+     *
+     * @param logger            the logger
+     * @param workingDir        the working dir
+     * @param workingbranchName the working branch name
+     * @return true if a different outgoing branch was found
+     * @throws ScmException on outgoing command error
+     */
+    public static boolean differentOutgoingBranchFound( ScmLogger logger, File workingDir,
String workingbranchName )
+        throws ScmException
+    {
+        String[] outCmd = new String[]{ HgCommandConstants.OUTGOING_CMD };
+        HgOutgoingConsumer outConsumer = new HgOutgoingConsumer( logger );
+        ScmResult outResult = HgUtils.execute( outConsumer, logger, workingDir, outCmd );
+        List changes = outConsumer.getChanges();
+        if ( outResult.isSuccess() )
+        {
+            for ( int i = 0; i < changes.size(); i++ )
+            {
+                HgChangeSet set = (HgChangeSet) changes.get( i );
+                if ( set.getBranch() != null )
+                {
+                    logger.warn( "A different branch than " + workingbranchName +
+                        " was found in outgoing changes, branch name was " + set.getBranch()
+
+                        ". Only local branch named " + workingbranchName + " will be pushed."
);
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommandConstants.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommandConstants.java?rev=1034733&r1=1034732&r2=1034733&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommandConstants.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommandConstants.java
Sat Nov 13 11:56:29 2010
@@ -65,7 +65,7 @@ public class HgCommandConstants
      * Commit changes into a new revision
      */
     public static final String COMMIT_CMD = "commit";
-    
+
     /**
      * update working-copy to tip
      */
@@ -107,6 +107,16 @@ public class HgCommandConstants
     public static final String INVENTORY_CMD = "locate";
 
     /**
+     * Outgoing changes command
+     */
+    public static final String OUTGOING_CMD = "outgoing";
+
+    /**
+     * Named branch command
+     */
+    public static final String BRANCH_NAME_CMD = "branch";
+
+    /**
      * no recurse option does not exist in mercurial
      */
     public static final String NO_RECURSE_OPTION = "";
@@ -120,6 +130,8 @@ public class HgCommandConstants
     public static final String VERSION = "version";
 
     public static final String CHECK = "check";
-    
+
     public static final String ALL_OPTION = "-A";
+
+
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java?rev=1034733&r1=1034732&r2=1034733&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java
Sat Nov 13 11:56:29 2010
@@ -60,6 +60,11 @@ public class HgCheckInCommand
             throw new ScmException( "This provider can't handle tags for this operation"
);
         }
 
+
+        File workingDir = fileSet.getBasedir();
+        String branchName = HgUtils.getCurrentBranchName( getLogger(), workingDir );
+        boolean differentOutgoingBranch = HgUtils.differentOutgoingBranchFound( getLogger(),
workingDir, branchName );
+
         // Get files that will be committed (if not specified in fileSet)
         List commitedFiles = new ArrayList();
         File[] files = fileSet.getFiles();
@@ -96,12 +101,16 @@ public class HgCheckInCommand
 
         // Push to parent branch if any
         HgScmProviderRepository repository = (HgScmProviderRepository) repo;
+
         if ( repo.isPushChanges() )
         {
 
             if ( !repository.getURI().equals( fileSet.getBasedir().getAbsolutePath() ) )
             {
-                String[] pushCmd = new String[]{ HgCommandConstants.PUSH_CMD, repository.getURI()
};
+                String[] pushCmd = new String[]{ HgCommandConstants.PUSH_CMD,
+                    differentOutgoingBranch ? HgCommandConstants.REVISION_OPTION + branchName
: null,
+                    repository.getURI() };
+
                 result = HgUtils.execute( new HgConsumer( getLogger() ), getLogger(), fileSet.getBasedir(),
pushCmd );
             }
 

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgChangeSet.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgChangeSet.java?rev=1034733&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgChangeSet.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgChangeSet.java
Sat Nov 13 11:56:29 2010
@@ -0,0 +1,51 @@
+package org.apache.maven.scm.provider.hg.command.inventory;
+
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+import org.apache.maven.scm.ChangeSet;
+
+/**
+ * Mercurial changeset
+ *
+ * @author <a href="mailto:lperez@xebia.fr">Laurent Perez</a>
+ * @version $Id$
+ */
+public class HgChangeSet
+    extends ChangeSet
+{
+
+    private String branch;
+
+    public HgChangeSet()
+    {
+        super();
+    }
+
+    public HgChangeSet( String branch )
+    {
+        this.branch = branch;
+    }
+
+    public String getBranch()
+    {
+        return branch;
+    }
+
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgChangeSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgChangeSet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java?rev=1034733&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
Sat Nov 13 11:56:29 2010
@@ -0,0 +1,63 @@
+package org.apache.maven.scm.provider.hg.command.inventory;
+
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.provider.hg.command.HgConsumer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Get a list of outgoing changes
+ *
+ * @author <a href="mailto:lperez@xebia.fr">Laurent Perez</a>
+ * @version $Id$
+ */
+public class HgOutgoingConsumer
+    extends HgConsumer
+{
+    private List changes = new ArrayList();
+
+    private static final String BRANCH = "branch";
+
+    public HgOutgoingConsumer( ScmLogger logger )
+    {
+        super( logger );
+    }
+
+    public void consumeLine( String line )
+    {
+        String branch = null;
+
+        if ( line.startsWith( BRANCH ) )
+        {
+            branch = line.substring( BRANCH.length() + 7 );
+        }
+        changes.add( new HgChangeSet( branch ) );
+
+    }
+
+    public List getChanges()
+    {
+        return changes;
+    }
+
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/inventory/HgOutgoingConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/tag/HgTagCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/tag/HgTagCommand.java?rev=1034733&r1=1034732&r2=1034733&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/tag/HgTagCommand.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/tag/HgTagCommand.java
Sat Nov 13 11:56:29 2010
@@ -19,11 +19,6 @@ package org.apache.maven.scm.provider.hg
  * under the License.
  */
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFile;
 import org.apache.maven.scm.ScmFileSet;
@@ -41,6 +36,11 @@ import org.apache.maven.scm.provider.hg.
 import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * Tag
  *
@@ -81,8 +81,8 @@ public class HgTagCommand
 
         // build the command
         String[] tagCmd =
-            new String[] { HgCommandConstants.TAG_CMD, HgCommandConstants.MESSAGE_OPTION,
-                scmTagParameters.getMessage(), tag };
+            new String[]{ HgCommandConstants.TAG_CMD, HgCommandConstants.MESSAGE_OPTION,
scmTagParameters.getMessage(),
+                tag };
 
         // keep the command about in string form for reporting
         StringBuffer cmd = joinCmd( tagCmd );
@@ -98,7 +98,14 @@ public class HgTagCommand
             {
                 if ( !repository.getURI().equals( fileSet.getBasedir().getAbsolutePath()
) )
                 {
-                    String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, repository.getURI()
};
+                    String branchName = HgUtils.getCurrentBranchName( getLogger(), workingDir
);
+                    boolean differentOutgoingBranch =
+                        HgUtils.differentOutgoingBranchFound( getLogger(), workingDir, branchName
);
+
+                    String[] pushCmd = new String[]{ HgCommandConstants.PUSH_CMD,
+                        differentOutgoingBranch ? HgCommandConstants.REVISION_OPTION + branchName
: null,
+                        repository.getURI() };
+
                     result =
                         HgUtils.execute( new HgConsumer( getLogger() ), getLogger(), fileSet.getBasedir(),
pushCmd );
                 }
@@ -110,7 +117,7 @@ public class HgTagCommand
         }
 
         // do an inventory to return the files tagged (all of them)
-        String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
+        String[] listCmd = new String[]{ HgCommandConstants.INVENTORY_CMD };
         HgListConsumer listconsumer = new HgListConsumer( getLogger() );
         result = HgUtils.execute( listconsumer, getLogger(), fileSet.getBasedir(), listCmd
);
         if ( result.isSuccess() )



Mime
View raw message