GithubHelp home page GithubHelp logo

isabella232 / copybara Goto Github PK

View Code? Open in Web Editor NEW

This project forked from google/copybara

0.0 0.0 0.0 10.75 MB

Copybara: A tool for transforming and moving code between repositories.

License: Apache License 2.0

Perl 0.04% Shell 1.35% Java 95.87% Dockerfile 0.05% Starlark 2.67% Raku 0.02%

copybara's Introduction

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 <[email protected]>"),
    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 an executable uberjar.
  • Tests: bazel test //... if you want to ensure you are not using a broken version.

System packages

These packages can be installed using the appropriate package manager for your system.

Arch Linux

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*.

copybara's People

Contributors

adonovan avatar ajsecord avatar androbin avatar benjaminp avatar chriscrisscross avatar cpovirk avatar darthhater avatar denian avatar dimo414 avatar durin42 avatar gmngeoffrey avatar hagbard avatar hsudhof avatar ittaiz avatar jessieliu1 avatar joseferminj avatar joshgoldman-google avatar kluever avatar kruton avatar matvore avatar mikelalcon avatar mlbileschi avatar ovidiugrigore avatar phiesel avatar pivanof avatar qfc avatar simontoens avatar vladmos avatar williamfreitag avatar yannic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.