Skip to content

Commit

Permalink
New file created by copy/paste in git repo ignores commit exclusion flag
Browse files Browse the repository at this point in the history
In addition to the create case, the copy case for new files also needs
to check the exclusion flag.

Closes: #7006
  • Loading branch information
matthiasblaesing committed Feb 21, 2024
1 parent 820558e commit 38303f1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,12 @@ public void doCopy (final File from, final File to) throws IOException {
FileUtils.copyFile(from, to);
}

if (root == null || cache.getStatus(to).containsStatus(Status.NOTVERSIONED_EXCLUDED)) {
// target lies under ignored folder, do not add it
if (root == null
// target lies under ignored folder, do not add it
|| cache.getStatus(to).containsStatus(Status.NOTVERSIONED_EXCLUDED)
// user choose that new files shall be excluded from commit by
// default, so follow that decision
|| GitModuleConfig.getDefault().getExludeNewFiles()) {
return;
}
GitClient client = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,39 @@ public void testCopyVersionedFile_DO() throws Exception {
assertFalse(info.isCopied());
}

public void testCopyVersionedFile_DO_IgnoreNewFiles() throws Exception {
try {
GitModuleConfig.getDefault().setExcludeNewFiles(true);

// init
File fromFile = new File(repositoryLocation, "file");
fromFile.createNewFile();
File toFolder = new File(repositoryLocation, "toFolder");
toFolder.mkdirs();
add();
commit();
File toFile = new File(toFolder, fromFile.getName());

// copy
h.setFilesToRefresh(Collections.singleton(toFile));
copyDO(fromFile, toFile);
assertTrue(h.waitForFilesToRefresh());
getCache().refreshAllRoots(Collections.singleton(fromFile));

// test
assertTrue(fromFile.exists());
assertTrue(toFile.exists());

assertEquals(EnumSet.of(Status.UPTODATE), getCache().getStatus(fromFile).getStatus());
FileInformation info = getCache().getStatus(toFile);
assertEquals(EnumSet.of(Status.NEW_INDEX_WORKING_TREE, Status.NEW_HEAD_WORKING_TREE), info.getStatus());
// sadly does not work in jgit
assertFalse(info.isCopied());
} finally {
GitModuleConfig.getDefault().setExcludeNewFiles(false);
}
}

public void testCopyUnversionedFile_DO() throws Exception {
// init
File fromFile = new File(repositoryLocation, "file");
Expand Down

0 comments on commit 38303f1

Please sign in to comment.