maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject [1/2] git commit: [SCM-709] REGRESSION: git status doesn't work if repository root is not the working directory
Date Sun, 17 Mar 2013 17:36:46 GMT
[SCM-709] REGRESSION: git status doesn't work if repository root is not the working directory


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

Branch: refs/heads/master
Commit: 43bc13254dc6de2f921e2e946f1a3ead5f0f8c80
Parents: 0c152cd
Author: rfscholte <rfscholte@apache.org>
Authored: Sun Mar 17 18:05:48 2013 +0100
Committer: rfscholte <rfscholte@apache.org>
Committed: Sun Mar 17 18:05:48 2013 +0100

----------------------------------------------------------------------
 .../gitexe/command/status/GitStatusConsumer.java   |   36 ++++++++++++---
 .../command/status/GitStatusConsumerTest.java      |   13 +++++
 2 files changed, 43 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/43bc1325/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.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/status/GitStatusConsumer.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
index cf37c08..2ee90a8 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
@@ -20,6 +20,7 @@ package org.apache.maven.scm.provider.git.gitexe.command.status;
  */
 
 import java.io.File;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Matcher;
@@ -62,8 +63,13 @@ public class GitStatusConsumer
 
     private File workingDirectory;
 
+    /**
+     * Entries are relative to working directory, not to the repositoryroot
+     */
     private List<ScmFile> changedFiles = new ArrayList<ScmFile>();
 
+    private String relativeRepositoryPath;
+    
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
@@ -74,6 +80,12 @@ public class GitStatusConsumer
         this.workingDirectory = workingDirectory;
     }
 
+    public GitStatusConsumer( ScmLogger logger, File workingDirectory, String relativeRepositoryPath
)
+    {
+        this( logger, workingDirectory );
+        this.relativeRepositoryPath = relativeRepositoryPath;
+    }
+
     // ----------------------------------------------------------------------
     // StreamConsumer Implementation
     // ----------------------------------------------------------------------
@@ -100,23 +112,23 @@ public class GitStatusConsumer
         if ( ( matcher = addedRegexp.matcher( line ) ).find() )
         {
             status = ScmFileStatus.ADDED;
-            files.add( matcher.group( 1 ) );
+            files.add( resolvePath( matcher.group( 1 ), relativeRepositoryPath ) );
         }
         else if ( ( matcher = modifiedRegexp.matcher( line ) ).find() )
         {
             status = ScmFileStatus.MODIFIED;
-            files.add( matcher.group( 1 ) );
+            files.add( resolvePath( matcher.group( 1 ), relativeRepositoryPath ) );
         }
         else if ( ( matcher = deletedRegexp.matcher( line ) ) .find() )
         {
             status = ScmFileStatus.DELETED;
-            files.add( matcher.group( 1 ) );
+            files.add( resolvePath( matcher.group( 1 ), relativeRepositoryPath ) );
         }
         else if ( ( matcher = renamedRegexp.matcher( line ) ).find() )
         {
             status = ScmFileStatus.RENAMED;
-            files.add( matcher.group( 1 ) );
-            files.add( matcher.group( 2 ) );
+            files.add( resolvePath( matcher.group( 1 ), relativeRepositoryPath ) );
+            files.add( resolvePath( matcher.group( 2 ), relativeRepositoryPath ) );
             logger.debug( "RENAMED status for line '" + line + "' files added '" + matcher.group(
1 ) + "' '"
                               + matcher.group( 2 ) );
         }
@@ -184,7 +196,19 @@ public class GitStatusConsumer
     private boolean isFile( String file )
     {
         return new File( workingDirectory, file ).isFile();
-//        return !file.endsWith( "/" );
+    }
+
+    protected static String resolvePath( String fileEntry, String path )
+    {
+        if ( path != null )
+        {
+            
+            return URI.create( path ).relativize( URI.create( fileEntry ) ).getPath();
+        }
+        else
+        {
+            return fileEntry;
+        }
     }
 
     public List<ScmFile> getChangedFiles()

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/43bc1325/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
index dab9829..2f56ca3 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
@@ -279,6 +279,19 @@ public class GitStatusConsumerTest
                      ScmFileStatus.MODIFIED );
     }
 
+    // SCM-709
+    public void testResolvePath()
+    {
+        File repositoryRoot = getTestFile( "repo" );
+        File workingDirectory = getTestFile( "repo/work" );
+
+        String path = repositoryRoot.toURI().relativize( workingDirectory.toURI() ).getPath();
+
+        assertEquals( "work", path );
+
+        assertEquals( "pom.xml", GitStatusConsumer.resolvePath( "work/pom.xml", path ) );
+        assertEquals( "work/pom.xml", GitStatusConsumer.resolvePath( "work/pom.xml", null
) );
+    }
 
     private void testScmFile( ScmFile fileToTest, String expectedFilePath, ScmFileStatus
expectedStatus )
     {


Mime
View raw message