depot/third_party/copybara
Default email 65671b0004 Project import generated by Copybara.
GitOrigin-RevId: b578e69f18a543889ded9c57a8f0dffacdb103d8
2020-05-16 15:14:58 +01:00
..
.docker Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
ci/ubuntu Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
copybara/integration Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
docs Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
java/com/google/copybara Project import generated by Copybara. 2020-05-16 15:14:58 +01:00
javatests/com/google/copybara Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
patches third_party/copybara: add meta-copybara config, and patch to add working-enough Mercurial support 2020-05-16 15:15:23 +01:00
scripts Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
third_party Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
.bazelproject Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
.bazelrc Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
.gitignore Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
AUTHORS Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
cibuild.sh Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
cloudbuild.sh Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
cloudbuild.yaml Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
CONTRIBUTING.md Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
copy.bara.sky third_party/copybara: add meta-copybara config, and patch to add working-enough Mercurial support 2020-05-16 15:15:23 +01:00
Dockerfile Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
LICENSE Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
README.md Project import generated by Copybara. 2020-05-15 16:19:19 -04:00
WORKSPACE Project import generated by Copybara. 2020-05-15 16:19:19 -04:00

Copybara

A tool for transforming and moving code between repositories.

Copybara is a tool used internally at Google. It transforms and moves code between repositories.

Often, source code needs to exist in multiple repositories, and Copybara allows you to transform and move source code between these repositories. A common case is a project that involves maintaining a confidential repository and a public repository in sync.

Copybara requires you to choose one of the repositories to be the authoritative repository, so that there is always one source of truth. However, the tool allows contributions to any repository, and any repository can be used to cut a release.

The most common use case involves repetitive movement of code from one repository to another. Copybara can also be used for moving code once to a new repository.

Examples uses of Copybara include:

  • Importing sections of code from a confidential repository to a public repository.

  • Importing code from a public repository to a confidential repository.

  • Importing a change from a non-authoritative repository into the authoritative repository. When a change is made in the non-authoritative repository (for example, a contributor in the public repository), Copybara transforms and moves that change into the appropriate place in the authoritative repository. Any merge conflicts are dealt with in the same way as an out-of-date change within the authoritative repository.

Currently, the only supported type of repository is Git. Copybara also supports reading from Mercurial repositories, but the feature is still experimental. Support for other repositories types will be added in the future.

Example

core.workflow(
    name = "default",
    origin = git.github_origin(
      url = "https://github.com/google/copybara.git",
      ref = "master",
    ),
    destination = git.destination(
        url = "file:///tmp/foo",
    ),

    # Copy everything but don't remove a README_INTERNAL.txt file if it exists.
    destination_files = glob(["third_party/copybara/**"], exclude = ["README_INTERNAL.txt"]),

    authoring = authoring.pass_thru("Default email <default@default.com>"),
    transformations = [
        core.replace(
                before = "//third_party/bazel/bashunit",
                after = "//another/path:bashunit",
                paths = glob(["**/BUILD"])),
        core.move("", "third_party/copybara")
    ],
)

Run:

$ (mkdir /tmp/foo ; cd /tmp/foo ; git init --bare)
$ copybara copy.bara.sky

Getting Started using Copybara

Copybara doesn't have a release process yet, so you need to compile from HEAD. In order to do that you need:

  • Install JDK 8.
  • Install Bazel.
  • Clone the copybara source locally:
    • git clone https://github.com/google/copybara.git
  • Build:
    • bazel build //java/com/google/copybara.
    • bazel build //java/com/google/copybara:copybara_deploy.jar to create a executable uberjar.
  • Tests: bazel test //... if you want to ensure you are not using a broken version.

Using Intellij with Bazel plugin

If you use Intellij and the Bazel plugin, use this project configuration:

directories:
  copybara/integration
  java/com/google/copybara
  javatests/com/google/copybara
  third_party

targets:
  //copybara/integration/...
  //java/com/google/copybara/...
  //javatests/com/google/copybara/...
  //third_party/...

Note that configuration files can be stored in any place, even in a local folder. We recommend to use a VCS (like git) to store them; treat them as source code.

Using Docker to build and run Copybara

NOTE: Docker use is currently experimental, and we encourage feedback or contributions.

You can build copybara using Docker like so

docker build --rm -t copybara .

Once this has finished building you can run the image like so from the root of the code you are trying to use Copybara on:

docker run -it -v "$(pwd)":/usr/src/app copybara copybara

A few environment variables exist to allow you to change how you run copybara:

  • COPYBARA_CONFIG=copy.bara.sky
    • allows you to specify a path to a config file, defaults to root copy.bara.sky
  • COPYBARA_SUBCOMMAND=migrate
    • allows you to change the command run, defaults to migrate
  • COPYBARA_OPTIONS=''
    • allows you to specify options for copybara, defaults to none
  • COPYBARA_WORKFLOW=default
    • allows you to specify the workflow to run, defaults to default
  • COPYBARA_SOURCEREF=''
    • allows you to specify the sourceref, defaults to none
docker run
       -e COPYBARA_CONFIG='other.config.sky'
       -e COPYBARA_SUBCOMMAND='validate'
       -v "$(pwd)":/usr/src/app
       -it copybara copybara

Git Config and Credentials

There are a number of ways by which to share your git config and ssh credentials with the docker container, an example with OS X is below:

docker run
       -v ~/.ssh:/root/.ssh
       -v ~/.gitconfig:/root/.gitconfig
       -v "$(pwd)":/usr/src/app
       -it copybara copybara

Documentation

We are still working on the documentation. Here are some resources:

Contact us

If you have any questions about how Copybara works please contact us at our mailing list

Optional tips

  • If you want to see the test errors in Bazel, instead of having to cat the logs, add this line to your ~/.bazelrc: *test --test_output=streamed*.