🐙 git
🐙 git
Clone and synchronize git repositories on the target system.
⚡ Actions
| Action | Description |
|---|---|
:sync |
Clone or update the repository (default) |
:nothing |
Do nothing (use with notifications) |
📋 Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
destination |
String | Resource name | Local path for the repository (auto-set from resource name) |
repository |
String | required ⚠️ | Git repository URL |
revision |
String | — | Branch, tag, or commit SHA to checkout |
recursive |
Boolean | false |
Clone with --recursive (include submodules) |
depth |
Integer | — | Shallow clone depth (--depth N) |
🔍 How It Works
The :sync action uses a deploy branch strategy:
- ✅ Verifies
gitis available on the target system - 📂 If the destination is empty, clones the repository (with
--recursiveand--depthif set) - 🔍 Resolves the target revision to a commit SHA
- 📊 Compares with the current HEAD
- 🔄 If different, creates a
deploybranch pointing to the target revision:- Renames existing
deploybranch todeploy-old - Fetches from origin
- Checks out the target as a new
deploybranch - Cleans up
deploy-old
- Renames existing
💡 The fetch from origin is memoized — only runs once per resource execution regardless of how many resolution steps are needed.
🔬 Dry-Run Behavior
Destination directory existence is verified. The repository is not cloned, fetched, or checked out.
📖 Examples
Clone a repository
git '/opt/app' do
repository 'https://github.com/user/app.git'
end
Clone a specific branch/tag
git '/opt/app' do
repository 'https://github.com/user/app.git'
revision 'v2.0'
end
Shallow clone (faster) ⏩
git '/opt/app' do
repository 'https://github.com/user/app.git'
depth 1
end
Recursive clone with submodules
git '/opt/app' do
repository 'https://github.com/user/app.git'
revision 'main'
recursive true
end
Notify on update 🔔
git '/opt/app' do
repository 'https://github.com/user/app.git'
revision 'main'
notifies :run, 'execute[bundle install]', :immediately
end
execute 'bundle install' do
action :nothing
command 'cd /opt/app && bundle install'
user 'deploy'
end
Clone as a specific user
git '/home/deploy/app' do
repository 'https://github.com/user/app.git'
revision 'main'
user 'deploy'
end