Glob Patterns
Glob Patterns
Section titled “Glob Patterns”Globs are used throughout Copybara to match files and directories.
Basic Syntax
Section titled “Basic Syntax”glob(["pattern1", "pattern2"])Pattern Characters
Section titled “Pattern Characters”| Pattern | Matches |
|---|---|
* | Any characters except / |
** | Any characters including / (recursive) |
? | Single character |
[abc] | Character class |
[!abc] | Negated character class |
Examples
Section titled “Examples”Match All Files
Section titled “Match All Files”glob(["**"])Match by Extension
Section titled “Match by Extension”# Single extensionglob(["**/*.py"])
# Multiple extensionsglob(["**/*.py", "**/*.pyi"])
# Or with bracesglob(["**/*.{py,pyi}"])Match Directory
Section titled “Match Directory”# All files in src/glob(["src/**"])
# Only immediate childrenglob(["src/*"])
# Specific subdirectoryglob(["src/lib/**"])Match Specific Files
Section titled “Match Specific Files”# Exact fileglob(["README.md"])
# Files in any directoryglob(["**/README.md"])
# File patternglob(["**/test_*.py"])Include and Exclude
Section titled “Include and Exclude”glob( include = ["**"], exclude = ["**/internal/**"],)Common Patterns
Section titled “Common Patterns”# Everything except testsglob( include = ["**"], exclude = ["**/*_test.go", "**/test_*.go"],)
# Source files onlyglob( include = ["src/**"], exclude = [ "**/internal/**", "**/testdata/**", "**/*.test.ts", ],)
# Documentationglob( include = ["docs/**", "*.md"], exclude = ["docs/internal/**"],)Usage Contexts
Section titled “Usage Contexts”origin_files
Section titled “origin_files”What to read from origin:
core.workflow( origin_files = glob( include = ["src/**", "docs/**"], exclude = ["**/internal/**"], ), ...)destination_files
Section titled “destination_files”What Copybara can modify:
core.workflow( destination_files = glob( include = ["**"], exclude = ["README.md", ".github/**"], ), ...)Transformation Paths
Section titled “Transformation Paths”Filter where transforms apply:
core.replace( before = "old", after = "new", paths = glob(["**/*.md"]),)
core.remove(glob(["**/*.bak"]))Precedence
Section titled “Precedence”Exclude patterns take precedence over include:
glob( include = ["src/**"], # Include all of src/ exclude = ["src/internal/**"], # But not internal/)# Result: src/* except src/internal/*Order Independence
Section titled “Order Independence”Include patterns are combined (union):
# These are equivalent:glob(["src/**", "docs/**"])glob(include = ["src/**", "docs/**"])Exclude patterns are also combined:
glob( include = ["**"], exclude = ["*.tmp", "*.bak"], # Excludes both)Special Cases
Section titled “Special Cases”Root Files Only
Section titled “Root Files Only”glob(["*"]) # Only files in rootSpecific Depth
Section titled “Specific Depth”glob(["src/*"]) # One level deepglob(["src/*/*"]) # Two levels deepglob(["src/**"]) # Any depthHidden Files
Section titled “Hidden Files”glob(["**/.*"]) # Hidden filesglob(["**/.git/**"]) # Git directoryCommon Exclusions
Section titled “Common Exclusions”# Build artifactsexclude = [ "**/node_modules/**", "**/dist/**", "**/build/**", "**/__pycache__/**", "**/target/**",]
# IDE filesexclude = [ "**/.idea/**", "**/.vscode/**", "**/*.iml",]
# Internal contentexclude = [ "**/internal/**", "**/*.internal.*", "**/INTERNAL_*",]
# Testsexclude = [ "**/*_test.go", "**/test_*.py", "**/*.test.ts", "**/testdata/**",]Debugging Globs
Section titled “Debugging Globs”Test which files match:
# Use folder destination to see resultsjava -jar copybara.jar migrate copy.bara.sky workflow \ --folder-destination /tmp/output
# List the filesfind /tmp/output -type f