Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions java/com/google/copybara/git/AddExcludedFilesToIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down
29 changes: 29 additions & 0 deletions javatests/com/google/copybara/git/GitDestinationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down