Metadata Transformations
Metadata Transformations
Section titled “Metadata Transformations”Metadata transformations modify commit messages, author information, and other Git metadata.
metadata.squash_notes
Section titled “metadata.squash_notes”Customize the commit message when squashing:
metadata.squash_notes( prefix = "Sync from internal:\n\n", show_author = True, show_description = True,)Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
prefix | Text before the notes |
show_author | Include original authors |
show_description | Include original commit messages |
oldest_first | Order by oldest first (default: newest) |
max | Maximum number of notes to include |
compact | Use compact format |
Examples
Section titled “Examples”# Full detailsmetadata.squash_notes( prefix = "Changes imported from internal:\n\n", show_author = True, show_description = True, oldest_first = True,)
# Compact formatmetadata.squash_notes( compact = True, max = 10,)Output Example
Section titled “Output Example”Changes imported from internal:
- Alice <alice@example.com>: Fix validation bug- Bob <bob@example.com>: Add user authentication- Alice <alice@example.com>: Update tests
GitOrigin-RevId: abc123def456metadata.add_header
Section titled “metadata.add_header”Add text to commit messages:
metadata.add_header("Synced-From: internal-repo")Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
text | Text to add |
new_line | Add newline before header (default: True) |
ignore_label_not_found | Don’t fail if label missing |
Examples
Section titled “Examples”# Simple headermetadata.add_header("Synced-From: internal")
# With label referencemetadata.add_header( text = "Reviewed-By: ${REVIEWED_BY}", ignore_label_not_found = True,)
# Multiple headerstransformations = [ metadata.add_header("Synced-From: internal"), metadata.add_header("Sync-Bot: copybara"),]metadata.expose_label
Section titled “metadata.expose_label”Make commit message labels available for use:
metadata.expose_label("Bug")metadata.expose_label("Reviewed-by")Common Labels
Section titled “Common Labels”transformations = [ # Standard Git trailers metadata.expose_label("Co-authored-by"), metadata.expose_label("Signed-off-by"), metadata.expose_label("Reviewed-by"),
# GitHub keywords metadata.expose_label("Closes"), metadata.expose_label("Fixes"), metadata.expose_label("Resolves"),]metadata.map_author
Section titled “metadata.map_author”Remap author email addresses:
metadata.map_author({ "internal@corp.com": "external@example.com", "alice.internal@corp.com": "alice@example.com",})Examples
Section titled “Examples”# Map multiple authorsmetadata.map_author({ "alice@internal.corp": "alice@public.example.com", "bob@internal.corp": "bob@public.example.com", "service@internal.corp": "bot@public.example.com",})metadata.replace_message
Section titled “metadata.replace_message”Replace the entire commit message:
metadata.replace_message("Automated sync from internal repository")With Template
Section titled “With Template”metadata.replace_message("""\Sync: ${COPYBARA_CONTEXT_REFERENCE}
This commit was automatically synced from the internal repository.
Original commit: ${COPYBARA_CONTEXT_REFERENCE}""")metadata.remove_label
Section titled “metadata.remove_label”Remove a label from commit messages:
metadata.remove_label("Internal-Bug")metadata.restore_author
Section titled “metadata.restore_author”Restore original author from a label:
metadata.restore_author( label = "ORIGINAL_AUTHOR", search_all_changes = True,)Combining Metadata Transformations
Section titled “Combining Metadata Transformations”transformations = [ # Preserve standard trailers metadata.expose_label("Co-authored-by"), metadata.expose_label("Signed-off-by"),
# Map internal emails metadata.map_author({ "internal@corp.com": "external@example.com", }),
# Add sync metadata metadata.add_header("Synced-From: internal"), metadata.add_header("Sync-Time: ${COPYBARA_CURRENT_TIME}"),
# Squash with notes metadata.squash_notes( prefix = "Imported changes:\n\n", show_author = True, show_description = True, ),]ITERATIVE Mode Specifics
Section titled “ITERATIVE Mode Specifics”In ITERATIVE mode, each commit retains its individual message:
# Only add header, don't squashtransformations = [ metadata.add_header("GitOrigin-RevId: ${COPYBARA_CONTEXT_REFERENCE}"),]Commit Message Format
Section titled “Commit Message Format”Copybara adds state tracking to commit messages:
Original commit message here.
GitOrigin-RevId: abc123def456789This allows Copybara to track what’s been synced.