diff --git a/java/com/google/copybara/git/AddExcludedFilesToIndex.java b/java/com/google/copybara/git/AddExcludedFilesToIndex.java index 5cba84790..ad8144478 100644 --- a/java/com/google/copybara/git/AddExcludedFilesToIndex.java +++ b/java/com/google/copybara/git/AddExcludedFilesToIndex.java @@ -70,10 +70,6 @@ void prepare(Path workdir) throws RepoException, IOException { addPathAndParents(included, relative); } else { prevExcluded.add(relative); - if (Files.isHidden(relative)) { - // File is not included but 'git add dir' doesn't work for 'dir/.file'. - addPathAndParents(included, relative.getParent()); - } } } diff --git a/javatests/com/google/copybara/git/GitDestinationTest.java b/javatests/com/google/copybara/git/GitDestinationTest.java index 8175cc73d..4c6f1121b 100644 --- a/javatests/com/google/copybara/git/GitDestinationTest.java +++ b/javatests/com/google/copybara/git/GitDestinationTest.java @@ -905,6 +905,35 @@ public void testExcludes_delete() throws Exception { assertThat(entry.files()).containsExactly("sub/tools/foo/other"); } + /** + * Regression test for previously-excluded files inside a dot-directory. Earlier code called + * {@link java.nio.file.Files#isHidden} on each tree entry's relative path; on Windows that + * resolves against the JVM's current working directory and throws {@code NoSuchFileException} + * for any entry under e.g. {@code .github/}. The dot-directory case must produce a commit that + * preserves the destination-only files unchanged, on every platform. + */ + @Test + public void testExcludes_dotDirectory_preserved() throws Exception { + fetch = primaryBranch; + push = primaryBranch; + GitTestUtil.writeFile(workdir, ".github/PULL_REQUEST_TEMPLATE.md", "destination-only"); + GitTestUtil.writeFile(workdir, "src/included", "first"); + repo().withWorkTree(workdir).add().all().run(); + repo().withWorkTree(workdir).simpleCommand("commit", "-m", "first commit"); + + Files.delete(workdir.resolve("src/included")); + GitTestUtil.writeFile(workdir, "src/included", "second"); + destinationFiles = + Glob.createGlob(ImmutableList.of("**"), ImmutableList.of(".github/**")); + + process(newWriter(), new DummyRevision("origin_ref")); + + assertThatCheckout(repo(), primaryBranch) + .containsFile(".github/PULL_REQUEST_TEMPLATE.md", "destination-only") + .containsFile("src/included", "second") + .containsNoMoreFiles(); + } + @Test public void processFetchRefDoesntExist() throws Exception { fetch = "testPullFromRef";