Skip to content

fix: exclude symlinks-to-directories from repo map file listing#4891

Open
yshch wants to merge 1 commit intoAider-AI:mainfrom
yshch:exclude-symlinks-to-directories-from-repo-map-file-listing
Open

fix: exclude symlinks-to-directories from repo map file listing#4891
yshch wants to merge 1 commit intoAider-AI:mainfrom
yshch:exclude-symlinks-to-directories-from-repo-map-file-listing

Conversation

@yshch
Copy link

@yshch yshch commented Mar 7, 2026

Problem

In repositories that contain symlinks pointing to directories, aider's repo map would incorrectly include these symlink paths as if they were regular files. This caused warnings like:

Repo-map can't include /path/to/repo/path/to/directory
Has it been deleted from the file system but not from git?

Git tracks symlinks as blob objects (storing the symlink target as content), so they appear alongside regular files when enumerating the repository. However, when Python resolves these paths, Path.is_file() returns False because the resolved target is a directory, not a file.

How to reproduce the problem

Create new git repository with symlink-to-directory

$ mkdir example-repo
$ cd example-repo
$ git init
Initialized empty Git repository in /***/example-repo/.git/
$ mkdir some-dir
$ touch some-dir/some-file
$ mkdir some-other-dir
$ cd some-other-dir && ln -s ../some-dir symlink-to-some-dir && cd ..
$ git add .
$ git commit -m "Initial commit"
[main (root-commit) e19b059] Initial commit
 2 files changed, 1 insertion(+)
 create mode 100644 some-dir/some-file
 create mode 120000 some-other-dir/symlink-to-some-dir

Run aider and refresh repomap

$ aider
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Aider v0.86.2
Model: ***
Git repo: .git with 2 files
Repo-map: using 4096 tokens, auto refresh
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> /map-refresh

Repo-map can't include /***/example-repo/some-dir
Has it been deleted from the file system but not from git?
The repo map has been refreshed, use /map to view it.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> /map

Here are summaries of some files present in my git repository.
Do not propose changes to these files, treat them as *read-only*.
If you need to edit any of these files, ask me to *add them to the chat* first.

some-dir

some-dir/some-file

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Root Cause

GitRepo.get_tracked_files() collects files from two sources:

1 Committed files — via commit.tree.traverse(), filtering for blob.type == "blob"
2 Staged files — via index.entries.keys()

Neither path checked whether a blob/entry was a symlink pointing to a directory. These entries were passed to the repo map, which then failed the Path(fname).is_file() check and emitted the misleading warning.

Fix

Added a check in both code paths within get_tracked_files(): if a path is a symlink, it is only included if it resolves to a file (not a directory).

full_path = Path(self.root) / path
if not full_path.is_symlink() or full_path.is_file():
    files.add(path)

This correctly:

• Includes regular files (not symlinks) — is_symlink() is False, so the condition passes
• Includes symlinks to files — is_symlink() is True but is_file() is also True
• Excludes symlinks to directories — is_symlink() is True and is_file() is False

Co-authored-by: aider (claude-opus-4.6) <aider@aider.chat>
@CLAassistant
Copy link

CLAassistant commented Mar 7, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants