Scaffold Gitattributes Guard is a Composer plugin that protects custom .gitattributes rules from being overwritten by drupal/core-composer-scaffold.

Drupal's Composer scaffold process generates a .gitattributes file during composer install and composer update. This can overwrite project-specific rules, such as Git LFS mappings, merge strategies, or linguist settings.

This plugin preserves the project's tracked .gitattributes file while moving Drupal's generated attributes to the local .git/info/attributes file.

How it works

The plugin listens to the Drupal Composer scaffold events:

  • Before scaffolding, it backs up the existing .gitattributes file.
  • After scaffolding, it moves the generated attributes to .git/info/attributes.
  • It restores the original tracked .gitattributes file.

As a result:

  • Custom project rules remain tracked in .gitattributes.
  • Drupal's scaffold rules continue to apply locally.
  • Drupal core updates do not create unnecessary changes to .gitattributes.
  • Drupal-generated attributes remain local to the checkout and are not committed to Git.

Git gives the working-tree .gitattributes file higher precedence than .git/info/attributes, so project-specific rules take precedence over scaffold-generated rules.

Installation

Install the plugin as a development dependency:

composer require --dev drupal/scaffold_gitattributes_guard

When Composer asks for permission to execute the plugin, allow it.

Requirements

  • PHP 8.2 or later
  • Composer 2.x
  • drupal/core-composer-scaffold 9.x, 10.x, or 11.x

Usage

No configuration is required. After installation, the plugin runs automatically whenever Drupal's Composer scaffold process runs.

For example, the following tracked .gitattributes file remains unchanged:

# Project-specific rules *.po merge=po-merge docs/* linguist-documentation

Drupal's generated attributes are stored locally in:

.git/info/attributes

Project information

Releases