A tool for mirroring branches across Git repositories
Перейти к файлу
microsoft-github-policy-service[bot] adcb99dee5
Microsoft mandatory file
2023-01-24 16:42:37 +00:00
k8s Adding a rudimentary file to deploy to k8s. 2017-12-21 14:50:14 -08:00
mirrorcat Fixing typo MIRROCAT_GITHUB_AUTH_USERNAME to MIRRORCAT_GITHUB_AUTH_USERNAME 2018-10-10 11:58:29 -07:00
testdata Reorganizing to improve test surface. 2017-12-07 14:54:10 -08:00
.gitignore Adding explicit "github-auth-username" option 2018-10-10 10:56:13 -07:00
.travis.yml Fix golint path 2018-10-25 13:40:04 -07:00
Dockerfile Adding a rudimentary Dockerfile (#1) 2017-12-12 13:11:12 -08:00
Gopkg.lock Fixing typo MIRROCAT_GITHUB_AUTH_USERNAME to MIRRORCAT_GITHUB_AUTH_USERNAME 2018-10-10 11:58:29 -07:00
Gopkg.toml Removing refs to `github.com/marstr/randname` 2017-12-08 11:01:23 -08:00
LICENSE Initial progress. 2017-12-07 14:53:38 -08:00
README.md README grammar and links. 2017-12-22 13:43:11 -08:00
SECURITY.md Microsoft mandatory file 2023-01-24 16:42:37 +00:00
merge_finder.go Adding MirrorFinder which combines output of two children. (#3) 2017-12-20 13:46:06 -08:00
merge_finder_test.go Fixing race condition in Example 2017-12-21 11:32:04 -08:00
mirror_finder.go Changing github response to include mention of the actual pushes that it made. 2017-12-08 21:57:05 -08:00
mirror_finder_test.go Adding MirrorFinder which combines output of two children. (#3) 2017-12-20 13:46:06 -08:00
push.go Reducing the size of the `clone` operation. (#8) 2018-03-06 15:48:24 -08:00
push_test.go Moving to use `cobra` 2017-12-08 21:18:51 -08:00
redis_finder.go Add redis mirror finder (#4) 2017-12-21 11:06:28 -08:00
redis_finder_test.go Add redis mirror finder (#4) 2017-12-21 11:06:28 -08:00

README.md

GoDoc

MirrorCat

Tired of manually keeping branches up-to-date with one another across repositories? Are Git Hooks not enough for you for some reason? Deploy your instance of MirrorCat to expose a web service which will push your commits around to where they are needed.

Acquire

Docker

You can run MirrorCat in a container, however/where ever you want, using Docker images. You can find the most up-to-date images here: https://cloud.docker.com/swarm/marstr/repository/docker/marstr/mirrorcat/general

Built from Source

Note: To do this, you'll need the most recent version of the Go Programming Language installed on your machine. It also helps to have dep installed.

The simplest, albeit least stable, way to install mirrorcat is to use go get as seen below:

go get -u github.com/Azure/mirrorcat/mirrorcat

A somewhat more stable way to install is to separately fetch the source and build it yourself, as below:

go get -d github.com/Azure/mirrorcat
cd $GOPATH/src/github.com/Azure/mirrorcat
dep ensure
go install -ldflags "-X github.com/Azure/mirrorcat/mirrorcat/cmd.commit=$(git rev-parse HEAD)" ./mirrorcat

or if you're a PowerShell-type-person:

go get -d github.com/Azure/mirrorcat
cd $env:GOPATH\src\github.com\Azure\mirrorcat
dep ensure
go install -ldflags "-X github.com/Azure/mirrorcat/mirrorcat/cmd.commit=$(git rev-parse HEAD)" .\mirrorcat

Configure

You'll need to tell MirrorCat which branches to mirror, and where. There are a couple of ways of doing that. The best part? You don't even need to choose between them. A MirrorCat looks around when it starts up to see what is available to it.

Available Options

Flag Config File Key Environment Variable Default Usage
--config N/A MIRRORCAT_CONFIG ~/.mirrorcat.yml The configuration file that should be used for all of the following settings.
--port port MIRRORCAT_PORT 8080 The TCP port that should be used to serve this instance of MirrorCat
--redis-connection redis-connection MIRRORCAT_REDIS_CONNECTION None The connection string MirrorCat to use while looking for branch mappings in a Redis cache.
--clone-depth clone-depth MIRRORCAT_CLONE_DEPTH Infinity The number of commits that should be cloned while moving commits between repositories.
N/A mirrors N/A None A mapping of which branches are to be copied from one repository to another.

Using a Config File

In addition to specifying administrative stuff, you can provide lists of where to copy each branch using either JSON or YAML. MirrorCat watches the file that was used as start-up, if the file changes MirrorCat will attempt to reconfigure itself while running.

.mirrorcat.yml

port: 8080
redis-connection: redis://localhost:6379/0
mirrors:
  https://github.com/Azure/mirrorcat.git:
    master:
      https://github.com/marstr/mirrorcat.git:
      - master
  https://github.com/Azure/azure-sdk-for-go.git:
    master:
      https://github.com/Azure/azure-sdk-for-go.git:
      - dev

.mirrorcat.json

{
  "port": 8080,
  "redis-connection": "redis://localhost:6379/0",
  "mirrors": {
    "https://github.com/Azure/mirrorcat.git": {
      "master": {
        "https://github.com/marstr/mirrorcat.git": [
          "master"
        ]
      }
    },
    "https://github.com/Azure/azure-sdk-for-go.git": {
      "master": {
        "https://github.com/Azure/azure-sdk-for-go.git": [
          "dev"
        ]
      }
    }
  }
}

Using Redis

Sometimes, you may want to introduce some dynamicism into how MirrorCat behaves. For example, you may want to have a website where users can declare a branch they've been working on in a lieutenant repository ready for the big time. Redis is a great way to enable this. Just point MirrorCat at a Redis instance by passing it a Redis connection string.

The expected schema of the Redis instance is to have Sets of mappings between branch/repository pairs separated by the rune ':'.

For example, a Redis instance where the following commands had been run would result in MirrorCat behaving the same as a MirrorCat using the config files from above.

SADD master:https://github.com/Azure/mirrorcat.git master:https://github.com/marstr/mirrorcat.git
SADD master:https://github.com/Azure/azure-sdk-for-go.git dev:https://github.com/Azure/azure-sdk-for-go.git

Using Environment Variables

Any flag that you can provide the mirrorcat start command can be provided in the config file mentioned above. However, you can also speficy it by setting an environment variable prefixed with the name "mirrorcat" and all hyphensreplaced with underscores ('-' -> '_').

Priority

MirrorCat, being a project written in Go, uses the really awesome libraries github.com/spf13/cobra and github.com/spf13/viper to easily deal with flags and configuration. As such, MirrorCat uses the following priority list when looking at the configuration handed to it:

  1. Command Line Arguments
  2. Environment Variables
  3. Configuration File
  4. Default Values

Contribute

Conduct

If you would like to become an active contributor to this project please follow the instructions provided in Microsoft Azure Projects Contribution Guidelines.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Requirements

You'll need the following tools to build and test MirrorCat:

The easiest way to get a hold of MirrorCat's source is using go get:

go get -d -t github.com/Azure/mirrorcat

Running Tests

Once you've acquired the source, you can run MirrorCat's tests with the following command:

go test -race -cover -v github.com/Azure/mirrorcat/...

Attribution

The gopher image at the top of this README was created by Ashley McNamara. You can find this image, and many others like it, at https://github.com/ashleymcnamara/gophers