Source Control · Chapter 3 of 3 · 3 min

Keeping a Repository Tidy

A layout that tests enforce, one-off scripts in a folder Git ignores, hooks that catch mistakes, and docs that cannot go stale.

Why tidiness is an operations concern

A messy repository is not just ugly. Stray files get copied into images, picked up by tests, and confuse the next person, which on a solo project is you in three months. Tidiness is cheapest when a machine enforces it.

A layout that a test enforces

This site keeps every section in the same named folder across layers: content/<section>, routes/<section>, views/<section>, lib/<section>. A layout test fails when:

The first time each rule fired, it felt fussy. Each one prevents a real class of drift: half the code using the new layout and half the old.

One-off scripts

Every project accumulates scripts that ran once: a migration, a bulk fix, an import. They are dangerous to keep in the main scripts folder, because someone may run them again. The rule here: throwaway scripts go in scripts/_local/, which Git ignores. Scripts that stay are listed, with a line saying what they do, and they follow a safe pattern:

Hooks

A Git hook is a script Git runs at a moment such as before a commit. This repository keeps its hooks in a tracked .githooks folder, so every clone can use the same ones:

git config core.hooksPath .githooks

The pre-commit hook here runs a small cleanup that removes *.bak files and makes sure .gitignore covers common noise. Keep hooks fast and forgiving: a hook that takes a minute or blocks commits for trivial reasons gets switched off, and then protects nothing.

Docs that cannot go stale

Documentation rots when it holds status: "done", "in progress", "next week". This site's docs rule:

Local clutter

Even with all of that, a working folder collects untracked files: downloads, picture choices, test reports. git status shows them as ??. Once a week:

git status --short
git clean -n        # list untracked files, delete nothing

git clean -n is a dry run. Read the list, move anything worth keeping to its proper place, and only then remove the rest.

Try it yourself

Pick one rule your project keeps "by convention", for example where new files go, and turn it into a test that fails when the rule is broken. Conventions are forgotten; failing tests are not.