graphify icon indicating copy to clipboard operation
graphify copied to clipboard

Allow extracting git-ignored code: add `--no-gitignore` opt-out

Open JensD-git opened this issue 4 months ago • 4 comments

Summary

Since ignore files below the scan root are read live during the walk (#1206) and .gitignore is merged into the ignore logic (#1363), graphify extract now honors every .gitignore it encounters anywhere under the scan root. That is usually correct — but there is no way to turn it off, and it silently removes source files that are deliberately git-ignored yet are exactly what we want in the graph.

Concretely: a large body of transpiled/generated C# code lives in generated/ directories that the project's .gitignore excludes (generated output is conventionally not committed). That code is the behavior we analyze. On a version that only read the scan root's own ignore files this code was extracted; after upgrading, all of it disappears — no error, no warning, the files simply don't appear in the graph, so the loss is easy to miss.

Environment

  • graphifyy: a version that did not read nested .gitignore vs. current that does (0.9.13 → 0.9.18 in our case)
  • Windows 11, Python 3.14, C# corpus (nodes are _origin: ast)

Minimal reproduction (verified on 0.9.18)

mkdir -p root/proj/deep/generated
printf 'namespace N { public class Real { public void M(){} } }\n' > root/proj/Real.cs
printf 'namespace N { public class Keep { public void M(){} } }\n' > root/proj/deep/Keep.cs
printf 'namespace N { public class Gen  { public void M(){} } }\n' > root/proj/deep/generated/Gen.cs
printf 'generated/\n' > root/proj/.gitignore        # nested, BELOW the scan root

graphify extract root --out out                     # exits 0, no warning

Inspect source_file on the nodes in out/graphify-out/graph.json.

Observed (actual): only proj/Real.cs and proj/deep/Keep.cs are present. proj/deep/generated/Gen.cs is absent — silently pruned because proj/.gitignore excludes generated/.

Desired: a supported way to include Gen.cs despite the .gitignore exclusion (see request below).

On a real transpiled graph the aggregate impact is large: distinct .cs files 1200 → 936 (−264, all under generated/); AST nodes −13%; edges −29%.

What we ruled out while diagnosing

  • Not the parser: identical tree-sitter (0.25.2) / tree-sitter-c-sharp (0.23.5); the dropped files parse fine in isolation (extract_csharp(path) returns 45 nodes, no error).
  • Not dedup, not a file-size cap, not _SKIP_DIRS (there is no generated literal in the skip set).
  • Confirmed mechanism: detect._load_dir_own_ignore(proj) reads proj/.gitignore during the walk and returns the generated/ pattern, which prunes the directory. This function/behavior is only present in the newer version.

Only workaround we could find (verified on 0.9.18)

Place a .graphifyignore containing both !generated/ and !generated/** in the same directory as the offending .gitignore (root/proj/.graphifyignore). Re-running the repro then includes proj/deep/generated/Gen.cs.

  • This works because per-directory .graphifyignore is read after .gitignore (_load_dir_own_ignore), so the ! negation wins via last-match-wins and the directory is not pruned.
  • A re-include placed at the scan root does not work: the nested .gitignore is loaded later during the walk and wins. So the escape hatch must be co-located with each offending .gitignore, which is non-obvious and awkward to automate.

Questions / requests

  1. Is there an existing flag or config to disable honoring .gitignore (and $GIT_DIR/info/exclude) during extraction? We could not find one.
  2. If not, would you consider a --no-gitignore / --ignore-vcs-ignores opt-out? Honoring .gitignore is a sensible default, but generated/transpiled code that is git-ignored yet analysis-relevant is a real case (build output, codegen, transpiler targets), and there is currently no clean escape hatch.
  3. If the intended answer is "use a co-located .graphifyignore re-include", could the precedence (a nested .gitignore beats a scan-root .graphifyignore; only a co-located ! wins) be documented? It is currently surprising.

Either way, this project is great, and I'd like to thank everyone who's actively contributing to it. Have a great weekend. <3

JensD-git avatar Jul 17 '26 15:07 JensD-git

There is currently no flag or configuration to disable .gitignore or $GIT_DIR/info/exclude.

A co-located .graphifyignore re-include works because it is evaluated after that directory’s .gitignore. A scan root re-include cannot override a nested .gitignore, since the nested rules are loaded later.

I'd be happy to work on the issue!

Mzt00 avatar Jul 17 '26 18:07 Mzt00

Fixed on v8 (ships in 0.9.19) via #1979 (f17e2c5) + persistence follow-up (caa6f9e), thanks @mzt006. --no-gitignore indexes git-ignored code (keeping .graphifyignore and the secret screens), and the setting persists across flag-less re-extracts.

safishamsi avatar Jul 18 '26 11:07 safishamsi

@safishamsi you've got the wrong person.

ghost avatar Jul 18 '26 12:07 ghost

Apologies @MZT006 — wrong ping, that was my mistake. The fix (#1979) was authored by @Mzt00 and the report by @JensD-git; I mistyped the handle. Corrected in the changelog and the 0.9.19 release notes. Sorry for the noise.

safishamsi avatar Jul 18 '26 13:07 safishamsi