Claudenw commented on code in PR #746:
URL: https://github.com/apache/creadur-rat/pull/746#discussion_r4250408093
##########
apache-rat-core/src/main/java/org/apache/rat/config/exclusion/fileprocessors/GitIgnoreBuilder.java:
##########
@@ -147,16 +147,23 @@ protected Optional<String> modifyEntry(final
Consumer<MatcherSet> matcherSetCons
/**
* The global gitignore file to process, based on the
- * {@link EnvVar#RAT_NO_GIT_GLOBAL_IGNORE},
- * {@link EnvVar#XDG_CONFIG_HOME} and
- * {@link EnvVar#HOME} environment
+ * {@link EnvVar#RAT_NO_GIT_GLOBAL_IGNORE}, the git configuration
+ * ({@code core.excludesFile} including {@code [include] path} directives)
+ * and the {@link EnvVar#XDG_CONFIG_HOME} and {@link EnvVar#HOME}
environment
* variables.
*/
protected Optional<File> globalGitIgnore() {
if (EnvVar.RAT_NO_GIT_GLOBAL_IGNORE.isSet()) {
return Optional.empty();
}
+ Optional<File> fromConfig = new GitConfig().coreExcludesFile();
Review Comment:
Can you run a test for me please.
As per your notes, the GitConfig code resolves relative files against the
current working directory (CWD).
Please configure a systems such that your GitConfig code will resolve the
file against the CWD.
Create a directory tree something like this.
CWD
+ the relative file
+---> subdirectory
+ .gitignore file
+ same relative file name different contents
When the git ignore is processed in the CWD it shoujld decend and find the
.gitignore in the subdirectory. Does the relative file name get reresolved
since the CWD has changed?
See https://git-scm.com/docs/gitignore command line execution.
##########
apache-rat-core/src/main/java/org/apache/rat/config/exclusion/fileprocessors/GitConfig.java:
##########
@@ -0,0 +1,394 @@
+/*
+ * 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.rat.config.exclusion.fileprocessors;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.Set;
+
+import org.apache.rat.api.EnvVar;
+
+/**
+ * Reads the global git configuration files to resolve the file configured
+ * for {@code core.excludesFile}.
+ * <p>
+ * The configuration files are read in git order: {@code
$XDG_CONFIG_HOME/git/config}
+ * first and {@code ~/.gitconfig} second. The last value found for
+ * {@code core.excludesFile} wins.
+ * </p>
+ * <p>
+ * {@code [include] path} directives are supported and the included files are
expanded
+ * in place, recursively. The relative paths of included files are resolved
against the
+ * directory of the including file, {@code ~/} is expanded to the home
directory and a
+ * depth limit of {@value #MAX_INCLUDE_DEPTH} is enforced like git does.
+ * </p>
+ * <p>
+ * {@code includeIf} directives, the system configuration ({@code
/etc/gitconfig}) and the
+ * repository configuration ({@code .git/config}) are not supported.
+ * </p>
+ * <p>
+ * When {@code core.excludesFile} is not configured the default location next
to the XDG
+ * configuration ({@code $XDG_CONFIG_HOME/git/ignore} or {@code
$HOME/.config/git/ignore})
+ * is used.
+ * </p>
+ */
+public class GitConfig {
+ /** The name of the 'core' section. */
+ private static final String CORE_SECTION = "core";
+ /** The name of the 'include' section. */
+ private static final String INCLUDE_SECTION = "include";
+ /** The key of the core section holding the global ignore file. */
+ private static final String EXCLUDES_FILE_KEY = "excludesfile";
+ /** The key of the include section holding the file to include. */
+ private static final String INCLUDE_PATH_KEY = "path";
+ /** The maximum depth of nested includes, matching the git limit. */
+ private static final int MAX_INCLUDE_DEPTH = 10;
+ /** The home directory prefix of a path. */
+ private static final String HOME_PREFIX = "~/";
Review Comment:
What is the HOME_PREFIX on a windows machine?
--
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]