Sync Strategies
Understanding symlink vs copy strategies for config syncing
Sync Strategies
Pact supports two strategies for applying configurations to your system.
Symlink (Default)
Creates a symbolic link from the target location to the source file in your .pact/ directory.
{
"source": "./shell/zshrc",
"target": "~/.zshrc",
"strategy": "symlink"
}How It Works
~/.zshrc → ~/.pact/shell/zshrcThe target (~/.zshrc) is a symlink pointing to the actual file in your pact repo.
Advantages
- Instant updates: Changes in
.pact/are immediately reflected - Easy tracking:
git statusin.pact/shows all changes - Bidirectional: Edit either location, changes appear in both
- Space efficient: Only one copy of the file exists
When to Use
- Most configuration files
- When you want changes to be immediately available
- When the application follows symlinks
Example
$ ls -la ~/.zshrc
lrwxr-xr-x 1 user staff 25 Dec 10 10:00 .zshrc -> .pact/shell/darwin.zshrcCopy
Copies the file from your .pact/ directory to the target location.
{
"source": "./shell/zshrc",
"target": "~/.zshrc",
"strategy": "copy"
}How It Works
~/.pact/shell/zshrc → (copied to) → ~/.zshrcThe target is a separate file with the same contents as the source.
Advantages
- Application compatibility: Works with apps that don't follow symlinks
- Independence: Target can be modified without affecting source
- Permissions: Target can have different permissions than source
When to Use
- Windows PowerShell profiles (execution policy issues)
- Applications that don't follow symlinks
- When you need the target to be a real file
Disadvantages
- Manual re-sync: Changes require running
pact syncagain - Two copies: Source and target are separate files
- Drift risk: Target can diverge from source
When using copy strategy, remember to run pact sync after editing files in .pact/ to update the target.
Choosing a Strategy
| Scenario | Recommended Strategy |
|---|---|
| Shell configs (macOS/Linux) | symlink |
| PowerShell profile (Windows) | copy |
| Neovim config | symlink |
| VS Code settings | symlink |
| Applications with symlink issues | copy |
| Frequently edited configs | symlink |
Default Strategy
If no strategy is specified, Pact uses symlink:
{
"source": "./shell/zshrc",
"target": "~/.zshrc"
// strategy defaults to "symlink"
}Directory Syncing
Both strategies work with directories:
Symlink (Directory)
{
"source": "./editor/nvim/",
"target": "~/.config/nvim",
"strategy": "symlink"
}Creates a symlink to the entire directory.
Copy (Directory)
{
"source": "./editor/nvim/",
"target": "~/.config/nvim",
"strategy": "copy"
}Recursively copies all files and subdirectories.
Mixed Strategies
You can use different strategies for different modules:
{
"modules": {
"shell": {
"darwin": {
"source": "./shell/darwin.zshrc",
"target": "~/.zshrc",
"strategy": "symlink"
},
"windows": {
"source": "./shell/windows.ps1",
"target": "~/Documents/PowerShell/profile.ps1",
"strategy": "copy"
}
}
}
}Troubleshooting
Symlink not working
- Check permissions: You need write access to the target directory
- Check if target exists: Pact removes existing files before creating symlinks
- Check application support: Some apps don't follow symlinks
Copy not updating
- Run sync again:
pact sync <module> - Check for conflicts: Target may have been modified
File permissions
Symlinks preserve the source file's permissions. Copies inherit permissions from the copy operation.
# Check symlink target
ls -la ~/.zshrc
# Check actual permissions
ls -la ~/.pact/shell/darwin.zshrc