Skip to content

Folder Origin & Destination

Folder-based origins and destinations work with the local filesystem, useful for testing and development.

Read from a local directory by defining folder.origin() in your configuration:

origin = folder.origin()
ParameterDescription
materialize_outside_symlinksHandle symlinks pointing outside the tree

When using folder.origin(), Copybara reads files from the current working directory. You can also set a specific directory for output using the --folder-dir flag.

Write to a local directory:

destination = folder.destination()

Specify the output directory:

Terminal window
java -jar copybara.jar migrate copy.bara.sky workflow --folder-dir /path/to/output

The most common use case is testing transformations locally before deploying to real repositories.

Section titled “Method 1: Using —to-folder (Recommended)”

The easiest way to test any workflow locally is using the --to-folder flag:

Terminal window
# Force any workflow to write to a local folder
java -jar copybara.jar migrate copy.bara.sky export \
--to-folder \
--folder-dir /tmp/output

This works with any workflow - you don’t need to modify your config.

Create a workflow specifically for testing:

copy.bara.sky
# Production workflow
core.workflow(
name = "export",
origin = git.origin(url = "https://github.com/org/repo", ref = "main"),
destination = git.destination(url = "https://github.com/org/public", push = "main"),
authoring = authoring.pass_thru("Bot <bot@example.com>"),
transformations = [
core.move("src/", "lib/"),
core.replace("old", "new"),
],
)
# Test workflow - same transformations, local destination
core.workflow(
name = "test",
origin = folder.origin(),
destination = folder.destination(),
authoring = authoring.overwrite("Test <test@example.com>"),
transformations = [
core.move("src/", "lib/"),
core.replace("old", "new"),
],
)

Run the test workflow:

Terminal window
cd /path/to/source
java -jar copybara.jar migrate copy.bara.sky test \
--folder-dir /tmp/output \
--force

A typical development cycle:

  1. Write or modify your workflow config

  2. Test locally with —to-folder:

    Terminal window
    java -jar copybara.jar migrate copy.bara.sky export \
    --to-folder \
    --folder-dir /tmp/preview
  3. Verify output:

    Terminal window
    # Check file structure
    find /tmp/preview -type f
    # Compare with expected
    diff -r /tmp/preview expected/
    # Check for sensitive content
    grep -r "INTERNAL\|SECRET" /tmp/preview
  4. Run production workflow when ready:

    Terminal window
    java -jar copybara.jar migrate copy.bara.sky export

Use --to-folder to preview what Copybara would produce without pushing to real destinations:

Terminal window
# Preview a Git-based workflow
java -jar copybara.jar migrate copy.bara.sky export \
--to-folder \
--folder-dir /tmp/preview
# Review the output before running production workflow
ls -la /tmp/preview
cat /tmp/preview/README.md
  • No state tracking: Folder operations don’t track what’s been synced
  • No Git history: Output is just files, no commits
  • No incremental sync: Each run processes all files
  • Directory cleared: --folder-dir clears the target directory before writing
Terminal window
# See what files would be synced
java -jar copybara.jar migrate copy.bara.sky export \
--to-folder \
--folder-dir /tmp/quick-preview
find /tmp/quick-preview -type f
Terminal window
# Preview with verbose output
java -jar copybara.jar migrate copy.bara.sky export \
--to-folder \
--folder-dir /tmp/debug \
-v
# Compare before/after
diff -r /original/file.txt /tmp/debug/file.txt
Terminal window
# Check that no secrets are leaked
java -jar copybara.jar migrate copy.bara.sky export \
--to-folder \
--folder-dir /tmp/security-check
# Search for sensitive patterns
grep -rE "API_KEY|SECRET|PASSWORD" /tmp/security-check
# Should return no results if filters work correctly