isCodeFile reads the wrong repo's .gitattributes when the path goes through a symlink

Open Beginner friendly
#2,888 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bun, typescript
Domain
backend, devtools

Research direction

Start in LifeOS/install/LIFEOS/TOOLS/IsaGoverning.ts, especially repoRootOf and isCodeFile, and compare their path handling with governingIsa. Run the Bun reproduction in the issue first; done means both direct and symlink paths return false for the documentation file, with the relative path checked against the real repository.

Written by the indexing model from the issue text.

Description

isCodeFile (LifeOS/install/LIFEOS/TOOLS/IsaGoverning.ts:61-63) finds the repo root by walking up the path as given. When a file is reached through a symlink to a folder inside another repository, the walk never meets the real repository's .git, stops at the outer one, and checks that repository's .gitattributes. A path marked linguist-documentation in the real repository is then treated as code, and IsaCodeSyncGate demands an ISA write for every data file edited through the link.

Reproduce on main (94bd8f25), from the clone root:

bun -e '
const fs = require("fs"), os = require("os"), p = require("path");
const { isCodeFile } = require(p.resolve("LifeOS/install/LIFEOS/TOOLS/IsaGoverning.ts"));
const t = fs.mkdtempSync(p.join(os.tmpdir(), "ig-"));
fs.mkdirSync(p.join(t, "real/.git"), { recursive: true });
fs.mkdirSync(p.join(t, "real/USER/data"), { recursive: true });
fs.writeFileSync(p.join(t, "real/.gitattributes"), "USER/data/** linguist-documentation\n");
fs.writeFileSync(p.join(t, "real/USER/data/record.yaml"), "id: 1\n");
fs.mkdirSync(p.join(t, "other/.git"), { recursive: true });
fs.symlinkSync(p.join(t, "real/USER"), p.join(t, "other/USER"));
console.log("direct path:  ", isCodeFile(p.join(t, "real/USER/data/record.yaml")));
console.log("via symlink:  ", isCodeFile(p.join(t, "other/USER/data/record.yaml")));
fs.rmSync(t, { recursive: true, force: true });'

Output: direct path: false, via symlink: true. Both should be false.

Fix

Which repository a path belongs to is worked out twice in this file, against DRY: governingIsa (line 99) walks up from realish(path), while repoRootOf (line 46), which isCodeFile calls at line 61, walks up from the path as given, so the same file is judged by two different repositories. Starting repoRootOf from realish(path) and taking the relative path at line 63 from the same real path makes isCodeFile read the .gitattributes of the repository the file actually lives in, and the two walks can no longer disagree.

Dominant language
TypeScript
Stars
19.9k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from danielmiessler/LifeOS

All issues in danielmiessler/LifeOS

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.