Folder Origin & Destination
Folder-based origins and destinations work with the local filesystem, useful for testing and development.
folder.origin
Section titled “folder.origin”Read from a local directory by defining folder.origin() in your configuration:
origin = folder.origin()Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
materialize_outside_symlinks | Handle symlinks pointing outside the tree |
How It Works
Section titled “How It Works”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.
folder.destination
Section titled “folder.destination”Write to a local directory:
destination = folder.destination()Usage with —folder-dir
Section titled “Usage with —folder-dir”Specify the output directory:
java -jar copybara.jar migrate copy.bara.sky workflow --folder-dir /path/to/outputTesting Workflows
Section titled “Testing Workflows”The most common use case is testing transformations locally before deploying to real repositories.
Method 1: Using —to-folder (Recommended)
Section titled “Method 1: Using —to-folder (Recommended)”The easiest way to test any workflow locally is using the --to-folder flag:
# Force any workflow to write to a local folderjava -jar copybara.jar migrate copy.bara.sky export \ --to-folder \ --folder-dir /tmp/outputThis works with any workflow - you don’t need to modify your config.
Method 2: Dedicated Test Workflow
Section titled “Method 2: Dedicated Test Workflow”Create a workflow specifically for testing:
# Production workflowcore.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 destinationcore.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:
cd /path/to/sourcejava -jar copybara.jar migrate copy.bara.sky test \ --folder-dir /tmp/output \ --forceDevelopment Workflow
Section titled “Development Workflow”A typical development cycle:
-
Write or modify your workflow config
-
Test locally with —to-folder:
Terminal window java -jar copybara.jar migrate copy.bara.sky export \--to-folder \--folder-dir /tmp/preview -
Verify output:
Terminal window # Check file structurefind /tmp/preview -type f# Compare with expecteddiff -r /tmp/preview expected/# Check for sensitive contentgrep -r "INTERNAL\|SECRET" /tmp/preview -
Run production workflow when ready:
Terminal window java -jar copybara.jar migrate copy.bara.sky export
Preview Mode
Section titled “Preview Mode”Use --to-folder to preview what Copybara would produce without pushing to real destinations:
# Preview a Git-based workflowjava -jar copybara.jar migrate copy.bara.sky export \ --to-folder \ --folder-dir /tmp/preview
# Review the output before running production workflowls -la /tmp/previewcat /tmp/preview/README.mdLimitations
Section titled “Limitations”- 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-dirclears the target directory before writing
Examples
Section titled “Examples”Quick Preview
Section titled “Quick Preview”# See what files would be syncedjava -jar copybara.jar migrate copy.bara.sky export \ --to-folder \ --folder-dir /tmp/quick-preview
find /tmp/quick-preview -type fDebug Transformations
Section titled “Debug Transformations”# Preview with verbose outputjava -jar copybara.jar migrate copy.bara.sky export \ --to-folder \ --folder-dir /tmp/debug \ -v
# Compare before/afterdiff -r /original/file.txt /tmp/debug/file.txtVerify Security Filters
Section titled “Verify Security Filters”# Check that no secrets are leakedjava -jar copybara.jar migrate copy.bara.sky export \ --to-folder \ --folder-dir /tmp/security-check
# Search for sensitive patternsgrep -rE "API_KEY|SECRET|PASSWORD" /tmp/security-check# Should return no results if filters work correctly