Skip to content

Repository files navigation

Mirror|rorriM

Motivation

How many Git repos do you have? I have over 100 (but most of them are stale). Even in the last two weeks (when this was made), I'd edited over 10 different ones. They also rely on multiple configuration files that I frequently update (see all the ones in the root of this repo). How do I manage them all? I mirror them from a centralized config repo (https://github.com/George-Ogden/config).

What is Mirror|rorriM?

Mirror|rorriM is a tool for syncing files between git repos. Assume you have a working repo and you're mirroring files from a source repo. It works with all the files in the config, but I'll illustrate with a pytest.ini. Consider you have this config after you install mirror:

[pytest]
version = 9.0
markers =
    slow: affects the runtime of the test suite

Now you make the following changes:

Mirror SourceWorking Repo
[pytest]
version = 9.1
markers =
    slow: affects the runtime of the test suite
    local: skip on the remote test server
[pytest]
version = 9.0
markers =
    custom: only used in this repo
    slow: affects the runtime of the test suite

When you run mirror sync, the changes (as a diff) are applied to your working version:

Remote DiffUpdated Working Repo
 [pytest]
-version = 9.0
+version = 9.1
 markers =
 ...
     slow: affects the runtime of the test suite
+    local: skip on the remote test server
[pytest]
version = 9.1
markers =
    custom: only used in this repo
    slow: affects the runtime of the test suite
    local: skip on the remote test server

All changes are kept! (You'll see a merge conflict if not.)

Usage

Just follow these three steps:

  1. Install from GitHub:
uv pip install git+https://github.com/George-Ogden/mirror-rorrim

(miss off the uv if you're still using pip).

  1. Make a configuration file called .mirror.yaml in the root of your repository (skip this step if you already have a config you want to use):
repos:
  - source: <location of config files> # anything you can git clone ...
    files:
      - mypy.ini # shorthand for mypy.ini: mypy.ini
      - pytest.ini: pytest.ini # format is target: source
      - ruff.toml

    # add more sources in the same format to sync from multiple repos
  - source: https://github.com/github/gitignore
    files:
      - .gitignore: Python.gitignore

  - source: https://github.com/licenses/license-templates
    files:
      - LICENSE: templates/mit.txt

If you save this config, you can make it easy to setup your mirror again next time.

  1. Install the mirror (make sure you've already run git init):
mirror install

For more advanced options, including using a remote config, see the help text:

mirror install --help

After installing, it's a good idea to commit.

  1. Periodically, sync your config files:
mirror sync

The updates in the repos you're syncing from are copied to your working repo. You can still edit your local files manually, but you may need to resolve conflicts when you sync.

Pre-Commit

If you use, pre-commit or prek, consider adding this repo as a hook to check for updates:

default_install_hook_types: [pre-commit, post-commit, pre-push]

- repo: https://github.com/George-Ogden/mirror-rorrim/
  rev: v0.4.10
  hooks:
    - id: mirror-check

It runs as a post-commit and pre-push hook, so don't forget to add the default_install_hook_types section at the top.

Contributing

Use GitHub for bugs/feature requests.

About

Sync configuration files across repos

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages