slawekjaranowski commented on code in PR #1370:
URL: https://github.com/apache/maven-scm/pull/1370#discussion_r4712125416


##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/status/JGitStatusCommand.java:
##########
@@ -51,7 +55,22 @@ protected StatusScmResult 
executeStatusCommand(ScmProviderRepository repo, ScmFi
             git = JGitUtils.openRepo(fileSet.getBasedir());
             Status status = git.status().call();
             List<ScmFile> changedFiles = getFileStati(status);
-
+            if (isFileSetFiltered(fileSet)) {
+                // account for difference in repo and fileSet base path
+                Path gitRoot = git.getRepository()
+                        .getWorkTree()
+                        .toPath()
+                        .toAbsolutePath()
+                        .normalize();
+                Path fileSetBase =
+                        
fileSet.getBasedir().toPath().toAbsolutePath().normalize();
+                Path relativeBase = gitRoot.relativize(fileSetBase);
+                Set<Path> fileSetPaths = fileSet.getFileList().stream()
+                        .map(f -> relativeBase.resolve(f.toPath()).normalize())
+                        .collect(Collectors.toSet());

Review Comment:
   Minor edge case: if a caller puts absolute paths into the file list (e.g. 
`new ScmFileSet(basedir, new File(basedir, "a.txt"))`), 
`relativeBase.resolve(f.toPath())` returns the absolute path unchanged. It then 
never equals the work-tree-relative path from JGit, so the changed file 
silently disappears from the result. gitexe's `GitStatusConsumer` still reports 
it, because it matches loosely on `endsWith(f.getName())`.
   
   The `ScmFileSet` javadoc says the files "have to be relative to basedir", so 
this is arguably caller error. Still, dropping a modified file without any 
warning seems worse than tolerating it:
   
   ```suggestion
                   Set<Path> fileSetPaths = fileSet.getFileList().stream()
                           .map(f -> f.toPath())
                           .map(p -> p.isAbsolute()
                                   ? gitRoot.relativize(p.normalize())
                                   : relativeBase.resolve(p).normalize())
                           .collect(Collectors.toSet());
   ```
   
   Not a blocker for me. Feel free to handle it in a follow-up.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to