You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/07/20 06:41:09 UTC

[GitHub] [maven-scm] kwin commented on a diff in pull request #144: [SCM-925] Implement RemoveCommand in maven-scm-provider-jgit

kwin commented on code in PR #144:
URL: https://github.com/apache/maven-scm/pull/144#discussion_r925229583


##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java:
##########
@@ -461,5 +462,60 @@ public RevFilter clone()
             return revs;
         }
     }
+    
+    /**
+     * Remove all files in the given fileSet to the repository.
+     *
+     * @param git     the repo to remove the files from
+     * @param fileSet the set of files within the workspace, the files are removed
+     *                relative to the basedir of this fileset
+     * @return a list of removed files
+     * @throws GitAPIException
+     * @throws NoFilepatternException
+     */
+    public static List<ScmFile> removeAllFiles( Git git, ScmFileSet fileSet )
+        throws GitAPIException, NoFilepatternException
+    {
+        URI baseUri = fileSet.getBasedir().toURI();
+        RmCommand remove = git.rm();
+        for ( File file : fileSet.getFileList() )
+        {
+            if ( !file.isAbsolute() )
+            {
+                file = new File( fileSet.getBasedir().getPath(), file.getPath() );
+            }
+
+            if ( file.exists() )
+            {
+                String path = relativize( baseUri, file );
+                remove.addFilepattern( path );
+                remove.addFilepattern( file.getAbsolutePath() );

Review Comment:
   RmCommand needs repository relative paths with forward slashes (https://archive.eclipse.org/jgit/site/5.0.1.201806211838-r/apidocs/org/eclipse/jgit/api/RmCommand.html#addFilepattern-java.lang.String-), therefore IMHO we need:
   
   ```
   URI workingCopyRootUri = git.getRepository().getWorkTree().toURI();
   String path = FilenameUtils.normalizeFilename( relativize( workingCopyRootUri, file ) );
   remove.addFilepattern( path );
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org