ottlinger commented on code in PR #746:
URL: https://github.com/apache/creadur-rat/pull/746#discussion_r4259881353


##########
apache-rat-core/src/main/java/org/apache/rat/api/EnvVar.java:
##########
@@ -45,6 +64,15 @@ public enum EnvVar {
      * Defines the user HOME.
      */
     HOME("The current user's home directory."),
+    /**
+     * The Windows user profile directory.
+     */
+    USERPROFILE("The user profile directory on Windows, used as a fallback 
home directory when HOME is not set."),

Review Comment:
   Shouldn't this be USER_PROFILE to remain consistency with the other 
Variables?



##########
apache-rat-core/src/main/java/org/apache/rat/config/exclusion/fileprocessors/GitIgnoreBuilder.java:
##########
@@ -147,29 +146,56 @@ 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
-     * variables.
+     * {@link EnvVar#RAT_NO_GIT_GLOBAL_IGNORE} and {@link 
EnvVar#RAT_GIT_GLOBAL_IGNORE}
+     * environment variables, the git configuration ({@code core.excludesFile} 
including
+     * {@code [include] path} directives and {@code GIT_CONFIG_GLOBAL}) and the
+     * {@link EnvVar#XDG_CONFIG_HOME} and {@link EnvVar#HOME} environment 
variables.
+     * <p>
+     * The global ignore file is read exactly once, anchored at the scan 
{@code root}, and its
+     * relative {@code core.excludesFile} path is resolved against the process 
working directory.
+     * It is not re-resolved when the scan descends into subdirectories, 
matching git where
+     * patterns from {@code core.excludesFile} are treated as if specified at 
the root of the
+     * working tree.
+     * </p>
+     * <p>
+     * {@link EnvVar#RAT_NO_GIT_GLOBAL_IGNORE} takes precedence over {@link 
EnvVar#RAT_GIT_GLOBAL_IGNORE}.
+     * When {@link EnvVar#RAT_GIT_GLOBAL_IGNORE} is {@code off} or an explicit 
path, the scan result does
+     * not depend on the machine the audit runs on, which is recommended for 
reproducible CI/release builds.
+     * </p>
      */
     protected Optional<File> globalGitIgnore() {
         if (EnvVar.RAT_NO_GIT_GLOBAL_IGNORE.isSet()) {
             return Optional.empty();
         }
+        return resolveGlobalGitIgnore(EnvVar.RAT_GIT_GLOBAL_IGNORE.getValue());
+    }
 
-        String xdgConfigHome = EnvVar.XDG_CONFIG_HOME.getValue();
-        String filename;
-        if (xdgConfigHome != null && !xdgConfigHome.isEmpty()) {
-            filename = xdgConfigHome + File.separator + "git" + File.separator 
+ "ignore";
-        } else {
-            String home = StringUtils.defaultIfEmpty(EnvVar.HOME.getValue(), 
"");
-            filename = home + File.separator + ".config" + File.separator + 
"git" + File.separator + "ignore";
-        }
-        File file = new File(filename);
-        if (file.exists()) {
-            return Optional.of(file);
-        } else {
-            return Optional.empty();
+    /**
+     * Resolves the global ignore file honoring the {@code 
RAT_GIT_GLOBAL_IGNORE} override value.
+     * <p>
+     * A {@code null} or {@code on} value falls back to the git configuration 
resolution. An
+     * {@code off} value disables the global ignore. Any other value is 
treated as an explicit
+     * global ignore path and, when it exists, is used as is so the scan 
result does not depend on
+     * the machine the audit runs on.
+     * </p>
+     * @param override the raw value of the {@code RAT_GIT_GLOBAL_IGNORE} 
environment variable or
+     *        {@code null} if it is not set.
+     * @return the resolved global ignore file or an empty Optional if none 
must be used.
+     */
+    static Optional<File> resolveGlobalGitIgnore(final String override) {
+        if (override != null) {
+            String value = override.strip();
+            if ("off".equalsIgnoreCase(value)) {

Review Comment:
   true/false would also be more consistent with the other configuration 
options.



##########
apache-rat-core/src/main/java/org/apache/rat/api/EnvVar.java:
##########
@@ -31,7 +31,26 @@ public enum EnvVar {
     /**
      * Ignore Git Global ignore file.
      */
-    RAT_NO_GIT_GLOBAL_IGNORE("Ignore global ignore file when processing GIT 
ignore files."),
+    RAT_NO_GIT_GLOBAL_IGNORE("Ignore the global ignore file when processing 
GIT ignore files."),
+    /**
+     * Controls how the global GIT ignore file is resolved for reproducible 
builds and audits.
+     * <p>
+     * The value may be one of:
+     * <ul>
+     *   <li>{@code off} - never read the machine global git ignore 
(equivalent to setting

Review Comment:
   Apart from the syntax problems with broken HTML (using <p> instead of <br/> 
to get paragraphs) I'd prefer to not introduce on/off but use boolean values 
instead.
   
   The GHA script uses "true" while the docs use on/off.



-- 
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]

Reply via email to