in git-agent/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/agent/UpdaterImpl.java [591:637]
public Collection<String> getPathsToExclude(@NotNull VcsRootEntry otherRoot, @NotNull String targetPath) {
final SortedSet<String> clashingPaths = new TreeSet<>(); // we need an ordered tree here
for (IncludeRule rule : otherRoot.getCheckoutRules().getRootIncludeRules()) {
final String to = rule.getTo();
if (targetPath.equals(to)) {
myLogger
.warning("Two VCS roots shouldn't be checked out into the same folder: performing git clean for " + myRoot.getName() +
" will remove files checked out for " + otherRoot.getVcsRoot().getName() +
" and vice versa. Please configure checkout to separate folders using Checkout rules.");
return Collections.emptyList();
}
if (targetPath.isEmpty()) {
clashingPaths.add(to);
} else if (to.isEmpty() || targetPath.startsWith(to + "/")) {
// check if the targetPath is excluded by checkout rules. In this case the contents of the directory can be managed and cleaned by myRoot, without accidentally cleaning files of otherRoot
// For example we don't want to add warning if we have separate vcs root for a submodule and have it exluded in the main vcs root, see TW-82946
if (!canCheckoutIntoSameDir(targetPath, rule, otherRoot.getCheckoutRules().getExcludeRules())) {
// case when this root is "inside" the other root - we can't fix this using exclude, only report
// (TBD: another option is not to run clean at all)
myLogger
.warning("Two VCS roots shouldn't be checked out into the same folder: performing git clean for " + myRoot.getName() +
" may remove files checked out for " + otherRoot.getVcsRoot().getName() +
". Please configure checkout to separate folders using Checkout rules.");
}
} else if (to.startsWith(targetPath + "/")) {
clashingPaths.add(to.substring(targetPath.length() + 1));
}
}
final List<String> result = new ArrayList<>();
clashingPaths.forEach(path -> {
// here we preserve more common paths
if (result.isEmpty() || !path.startsWith(result.get(result.size() - 1) + "/")) result.add(path);
});
if (result.isEmpty() || CleanCommandUtil.isCleanCommandSupportsExclude(myPluginConfig.getGitVersion())) {
return result;
}
myLogger
.warning("git version " + myPluginConfig.getGitVersion() + " doesn't support --exclude option for clean command: performing git clean for " + myRoot.getName() +
" will remove files checked out for " + otherRoot.getVcsRoot().getName() +
" and vice versa. Please either update git executable to a version above " + GitVersion.DEPRECATED + " or configure checkout to separate folders using Checkout rules.");
return Collections.emptyList();
}