Skip to content

Erroneous/broken core.move in public -> private import #122

Closed
@sudoforge

Description

@sudoforge

I'm working on a copybara demo for my team, and am running into an issue that's left me scratching my head.

In this example private repository, I have a tree structure like:

internal-monorepo
├── BUILD
├── README.md
├── WORKSPACE
├── experimental
    ├── copy.bara.sky
    └── exercises
        └── go
            └── hello-world
                ├── BUILD
                ├── README.md
                ├── go.mod
                ├── hello_world.go
                └── hello_world_test.go

The copy.bara.sky workflows are fairly straightforward:

public = "https://github.com/someuser/experimental"
private = "https://github.com/someuser/internal-monorepo"

core.workflow(
    name = "export",
    mode = "ITERATIVE",

    origin = git.origin(
        url = private,
        ref = "master",
    ),

    destination = git.github_destination(
        url = public,
        push = "master",
        fetch = "master",
    ),

    origin_files = glob([
        "experimental/**",
    ], exclude = [
        "experimental/copy.bara.sky",
        "experimental/**/BUILD",
    ]),

    destination_files = glob(["**"]),

    authoring = authoring.pass_thru("Copybara Bot <[email protected]>"),

    transformations = [
        core.move("experimental", ""),
        metadata.scrubber('(^|\n)INTERNAL-ONLY:(.|\n)*'),
        metadata.restore_author(
          label = "ORIGINAL_AUTHOR",
          search_all_changes = True,
        ),
    ],
)

core.workflow(
    name = "import",
    mode = "CHANGE_REQUEST",
    set_rev_id = False,

    origin = git.github_pr_origin(
        url = public,
    ),

    destination = git.github_pr_destination(
        url = private,
        destination_ref = "master",
    ),

    origin_files = glob([
        "**",
    ]),

    destination_files = glob([
        "experimental/**"
    ], exclude = [
        "experimental/copy.bara.sky",
        "experimental/**/BUILD",
    ]),

    authoring = authoring.whitelisted(
        default = "Copybara Bot <[email protected]>",
        whitelist = [
            "[email protected]",
        ],
    ),

    transformations = [
        core.move("", "experimental"),
        metadata.save_author(),
        metadata.expose_label("COPYBARA_INTEGRATE_REVIEW"),
        metadata.expose_label("GITHUB_PR_NUMBER", new_name = "closes", separator = '#'),
    ],
)

export works beautifully.

In internal repository has a single, initial commit. Running the export workflow works as expected:

$ copybara experimental/copy.bara.sky export --init-history --force
...

# The new public repository looks exactly as expected!

$ tree
<public-repo>
└── exercises
    └── go
        └── hello-world
            ├── README.md
            ├── go.mod
            ├── hello_world.go
            └── hello_world_test.go

import fails due to a conflict.

I'm testing the PR workflow, so I create an issue in <public-repo>, create a new branch, and push it up. The new tree looks like this:

$ tree
<public-repo-branch>
├── README.md
└── exercism
    └── go
        └── hello-world
            ├── README.md
            ├── go.mod
            ├── hello_world.go
            └── hello_world_test.go

Switching back to my internal repo (where the workflow file lives), I now run the import workflow. It fails due to a conflict (the reference is refs/pull/2/head because the branch has been submitted as a PR):

➜ copybara experimental/copy.bara.sky import refs/pull/2/head
Apr 01, 2020 9:12:55 PM com.google.copybara.Main configureLog
INFO: Setting up LogManager
Copybara source mover (Version: Unknown version)
Task: Integrating change from https://github.com/someuser/experimental/pull/2 from someuser:1/add-readme c4b5ef92771760d076a036620adb2d74e2a4bea0
WARN: Removing previous rebase failure lock: /home/myuser/copybara/cache/git_repos/https%3A%2F%2Fgithub%2Ecom%2Fsomeuser%2Finternal-monorepo/rebase-merge
ERROR: Conflict detected while rebasing /home/myuser/copybara/temp/workdir1539881038528199439/checkout to 30785368de6889c04aa194754821ec6e9da062c0. Please sync or update the change in the origin and retry. Git output was:
CONFLICT (add/add): Merge conflict in README.md
Auto-merging README.md

In looking at the working directory, I'm seeing a weird duplication of the exercises directory -- it looks like the core.move transformation is copying the origin files in the import workflow rather than merging them:

~/copybara/temp/workdir1539881038528199439
➜ tree
.
├── checkout
│   ├── BUILD
│   ├── README.md
│   ├── WORKSPACE
│   ├── exercises
│   │   └── go
│   │       └── hello-world
│   │           ├── README.md
│   │           ├── go.mod
│   │           ├── hello_world.go
│   │           └── hello_world_test.go
│   ├── experimental
│       ├── copy.bara.sky
│       └── exercises
│           └── go
│               └── hello-world
│                   ├── BUILD
│                   ├── README.md
│                   ├── go.mod
│                   ├── hello_world.go
│                   └── hello_world_test.go
│
├── origin
│   ├── README.md
│   └── exercises
│       └── go
│           └── hello-world
│               ├── README.md
│               ├── go.mod
│               ├── hello_world.go
│               └── hello_world_test.go
└── reverse
    ├── README.md
    └── exercises
        └── go
            └── hello-world
                ├── README.md
                ├── go.mod
                ├── hello_world.go
                └── hello_world_test.go

From the documentation (and other examples found in issues in this repository), it appears that my core.move usage is correct, and should result in the github_pr_origin files being moved into a subdirectory. What am I doing wrong? Your help is greatly appreciated -- thanks for maintaining a great tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions