You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/06/21 11:26:03 UTC

[maven-scm] 02/02: [SCM-932] Absolute paths are converted to relative based on the repo root, not the basedir of the fileset. Relative paths are checked to see if the repo root matches the basedir of the fileset and if not, are re-based on the repo root.

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

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

commit 6d3940f7d5621bc90e93ad4c26ad8de027063a6a
Author: Alex Harui <ah...@apache.org>
AuthorDate: Thu Apr 9 22:35:31 2020 -0700

    [SCM-932] Absolute paths are converted to relative based on the repo root, not the basedir of the fileset.  Relative paths are checked to see if the repo root matches the basedir of the fileset and if not, are re-based on the repo root.
---
 .../scm/provider/git/jgit/command/JGitUtils.java     | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java
index 6ad56ba..1cbcb2e 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java
@@ -303,7 +303,7 @@ public class JGitUtils
 
             if ( file.exists() )
             {
-                String path = relativize( baseUri, file );
+                String path = relativize( baseUri, file, git );
                 add.addFilepattern( path );
                 add.addFilepattern( file.getAbsolutePath() );
             }
@@ -329,7 +329,7 @@ public class JGitUtils
             // really tracked
             for ( Iterator<File> itfl = fileSet.getFileList().iterator(); itfl.hasNext(); )
             {
-                String path = FilenameUtils.normalizeFilename( relativize( baseUri, itfl.next() ) );
+                String path = FilenameUtils.normalizeFilename( relativize( baseUri, itfl.next(), git ) );
                 if ( path.equals( FilenameUtils.normalizeFilename( scmfile.getPath() ) ) )
                 {
                     addedFiles.add( scmfile );
@@ -339,12 +339,24 @@ public class JGitUtils
         return addedFiles;
     }
 
-    private static String relativize( URI baseUri, File f )
+    private static String relativize( URI baseUri, File f, Git git )
     {
         String path = f.getPath();
+        URI repoUri = git.getRepository().getWorkTree().toURI();
         if ( f.isAbsolute() )
         {
-            path = baseUri.relativize( new File( path ).toURI() ).getPath();
+            path = repoUri.relativize( new File( path ).toURI() ).getPath();
+        }
+        else // relative
+        {
+            // check if fileset base is same as repo root
+            if ( baseUri.compareTo( repoUri ) != 0 )
+            {
+                // if not, adjust the relative path to be relative to the root of the repo
+                // not the fileset base
+                String baseFolder = baseUri.getPath();
+                path = repoUri.relativize( new File( baseFolder, f.getPath() ).toURI() ).getPath();
+            }
         }
         return path;
     }