google / copybara

Copybara: A tool for transforming and moving code between repositories.
Apache License 2.0
2.14k stars 263 forks source link

How to preserve private lines of code #304

Open oldgiova opened 3 days ago

oldgiova commented 3 days ago

Hi, I have a private and a public repository that share part of the codebase. The workflow is one-way only: it syncs from the public to the private repository.

core.workflow(
  name = "pull",
  origin = git.github_origin(
    url = sourceUrl,
    ref = "main",
  ),
  destination = git.github_pr_destination(
    url = destUrl,
    destination_ref = "main",
    pr_branch = "copybara_from_public_repo",
    title = "Copybara - code sync from public repo",
    body = "This PR is auto-generated by Copybara.",
    integrates = [],
  ),

  origin_files = glob(
    include = filesToSync,
    exclude = excludedFiles
  ),

  destination_files = glob(
    include = filesToSync,
    exclude = excludedFiles
  ),

  authoring = authoring.pass_thru("author <author@example.com>"),
  transformations = [
    metadata.restore_author("ORIGINAL_AUTHOR", search_all_changes = True),
    metadata.use_last_change(author=True, message=True, default_message=None),
  ],
  mode = ITERATIVE
)

The issue arises when a private function is added to the private codebase. Copybara tries to delete it because it is not present in the public codebase, and the file is included in the sync.

How can I preserve the private codebase while keeping the file in sync?

Thanks!

hsudhof commented 3 days ago

Generally: patches or transforms, but you can also use merge_mode

oldgiova commented 2 days ago

Thanks @hsudhof ! Do you have some more information regarding the merge_mode? I can't find it in the reference.

About patches, I've already excluded them because we don't want to generate a diff file in advance for every files we're maintaining, since the drift between the private and the public repo is quite huge.