slawekjaranowski commented on code in PR #1370: URL: https://github.com/apache/maven-scm/pull/1370#discussion_r4712170149
########## maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/status/JGitStatusCommandTest.java: ########## @@ -0,0 +1,84 @@ +/* + * 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. + */ +package org.apache.maven.scm.provider.git.jgit.command.status; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.maven.scm.ScmFileSet; +import org.apache.maven.scm.command.status.StatusScmResult; +import org.eclipse.jgit.api.Git; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Status filtering when the file set base directory is a subdirectory of the work tree. + */ +class JGitStatusCommandTest { + + @TempDir + Path workTree; + + private File basedir; + + @BeforeEach + void setUp() throws Exception { + Path sub = Files.createDirectory(workTree.resolve("sub")); + Files.write(sub.resolve("a.txt"), "a".getBytes(StandardCharsets.UTF_8)); + Files.write(sub.resolve("b.txt"), "b".getBytes(StandardCharsets.UTF_8)); + try (Git git = Git.init().setDirectory(workTree.toFile()).call()) { + git.add().addFilepattern("sub").call(); + git.commit() + .setMessage("initial") + .setAuthor("test", "[email protected]") + .setCommitter("test", "[email protected]") + .setSign(false) + .call(); + } + Files.write(sub.resolve("a.txt"), "a2".getBytes(StandardCharsets.UTF_8)); + Files.write(sub.resolve("b.txt"), "b2".getBytes(StandardCharsets.UTF_8)); + basedir = sub.toFile(); + } + + @Test + void explicitFileListFiltersStatus() throws Exception { + assertEquals(Collections.singletonList("sub/a.txt"), changedPaths(new ScmFileSet(basedir, new File("a.txt")))); + assertEquals( + Collections.singletonList("sub/b.txt"), + changedPaths(new ScmFileSet(basedir, Collections.singletonList(new File("b.txt"))))); + } + + @Test + void includesAndExcludesFilterStatus() throws Exception { + assertEquals(Collections.singletonList("sub/a.txt"), changedPaths(new ScmFileSet(basedir, "*.txt", "b.txt"))); + } Review Comment: If the absolute-path handling suggested above is taken, a test would lock it in. The existing tests only use relative paths, so they pass either way: ```suggestion } @Test void absoluteFileListFiltersStatus() throws Exception { assertEquals( Collections.singletonList("sub/a.txt"), changedPaths(new ScmFileSet(basedir, new File(basedir, "a.txt")))); } ``` I checked this locally with both suggestions applied: without the main-code change the test fails (`expected: <[sub/a.txt]> but was: <[]>`), with it `mvn verify` on the jgit provider passes, Spotless included. -- 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]
