Skip to content

Pre‐commit checks for Unity

Ivan Šachov edited this page Nov 13, 2024 · 2 revisions

Pre-commit Checks for Unity

In Unity projects, pre-commit checks ensure a cleaner, more stable repository by preventing common issues before they enter version control. This page outlines the two main pre-commit checks: detecting unsaved changes in Unity and identifying empty folders with .meta files.

Unsaved Changes Check

Description

When committing, Rider communicates with Unity to verify if there are any unsaved changes. If changes are detected, Rider prompts the user with a dialog.

Why This Matters

This check prevents unintended issues caused by unsaved changes in Unity that could affect team members pulling from the repository. Unsaved changes may include modified scenes and scriptable objects.

How It Works

When a commit attempt is made, Rider queries Unity for any unsaved modifications. If Unity reports unsaved changes, Rider displays a dialog, encouraging users to save their work before proceeding.

Empty Folder with .meta File Check

Description Unity automatically generates a .meta file for each new folder, even if the folder is empty. This check detects any .meta files for empty folders when committing and prompts the user with an alert.

Why This Matters

Git does not track empty folders, but it does track .meta files. If a .meta file is committed without the corresponding folder, Unity will delete it on other machines that do not have the folder, leading to an unnecessary cycle of adding and removing the file in version control. This creates a "commit ping-pong," where .meta files for empty folders are continuously added and removed across commits, cluttering the commit history.

How It Works

Before completing the commit, Rider scans for any .meta files corresponding to empty folders. If it finds any, Rider alerts the user, who can then choose to either commit anyway or cancel and fix the issues manually.

Clone this wiki locally