copier icon indicating copy to clipboard operation
copier copied to clipboard

fix: use .gitignore for exludes

Open tnijboer opened this issue 4 months ago • 3 comments

Fixes #2244.

Problem

Running copier update fails with OSError: [Errno 7] Argument list too long on projects with extensive .gitignore files or _skip_if_exists lists.

The cause is that copier builds the git apply command by adding an individual --exclude={pattern} argument for every exclusion. This exceeds the OS command-line argument length limit.

Solution

This patch refactors the exclusion handling for git apply:

  1. All exclusion patterns (from .gitignore, all_skip_if_exists, answers_relpath) are consolidated into a single list.
  2. This list is written to a temporary file.
  3. The git apply command is modified to use a single --exclude-from=<temp_file> argument, pointing to the new file.
  4. A try...finally block is used to guarantee the temporary file is cleaned up.

This change avoids the argument length limit and allows copier update to succeed on projects with many exclusions.

tnijboer avatar Oct 28 '25 15:10 tnijboer

Several tests are failing; it seems that git apply does not have an --exclude-from flag. :thinking:

sisp avatar Oct 29 '25 14:10 sisp

Yes, you're totally right. My bad, was confused with rsync. I updated the code to just check the .gitignore for folders, and if there are any files listed in git status --ignored --porcelain that are in an ignored folder just add the exclude for the folder instead so the list of excludes get way shorter.

tnijboer avatar Oct 30 '25 12:10 tnijboer

@sisp what do you think of this approach?

tnijboer avatar Nov 04 '25 16:11 tnijboer