diff --git a/CHANGELOG.md b/CHANGELOG.md index 237aba82..67c38aaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Reverse Chronological Order: ## master +* Added support for git shallow clone + https://github.com/capistrano/capistrano/compare/v3.4.0...HEAD * Remove 'vendor/bundle' from default :linked_dirs (@ojab) @@ -137,7 +139,7 @@ https://github.com/capistrano/capistrano/compare/v3.2.1...v3.3.3 This allows roles to specify properties common to all servers and then for individual servers to modify them, keeping things DRY - + * Enhancements (@Kriechi) * Added validate method to DSL to allow validation of certain values - validate values before assignment inside of `set(:key, value)` diff --git a/lib/capistrano/git.rb b/lib/capistrano/git.rb index 1a686d7b..c45c11e0 100644 --- a/lib/capistrano/git.rb +++ b/lib/capistrano/git.rb @@ -22,16 +22,17 @@ class Capistrano::Git < Capistrano::SCM end def clone - if fetch(:git_shallow_clone) - git :clone, '--mirror', '--depth 1', repo_url, repo_path + if depth = fetch(:git_shallow_clone) + git :clone, '--mirror', '--depth', depth, '--no-single-branch', repo_url, repo_path else git :clone, '--mirror', repo_url, repo_path end end def update - if fetch(:git_shallow_clone) - git :fetch, '--depth 1', '--update-shallow', "origin #{fetch(:branch)}" + # Note: Requires git version 1.9 or greater + if depth = fetch(:git_shallow_clone) + git :fetch, '--depth', depth, 'origin', fetch(:branch) else git :remote, :update end diff --git a/spec/lib/capistrano/git_spec.rb b/spec/lib/capistrano/git_spec.rb index 3a688142..1e1f3a33 100644 --- a/spec/lib/capistrano/git_spec.rb +++ b/spec/lib/capistrano/git_spec.rb @@ -48,10 +48,11 @@ module Capistrano end it "should run git clone in shallow mode" do - context.expects(:fetch).with(:git_shallow_clone).returns(true) + context.expects(:fetch).with(:git_shallow_clone).returns('1') context.expects(:repo_url).returns(:url) context.expects(:repo_path).returns(:path) - context.expects(:execute).with(:git, :clone, '--mirror', '--depth 1', :url, :path) + + context.expects(:execute).with(:git, :clone, '--mirror', "--depth", '1', '--no-single-branch', :url, :path) subject.clone end @@ -66,9 +67,9 @@ module Capistrano end it "should run git update in shallow mode" do - context.expects(:fetch).with(:git_shallow_clone).returns(true) + context.expects(:fetch).with(:git_shallow_clone).returns('1') context.expects(:fetch).with(:branch).returns(:branch) - context.expects(:execute).with(:git, :fetch, '--depth 1', '--update-shallow', "origin branch") + context.expects(:execute).with(:git, :fetch, "--depth", '1', "origin", :branch) subject.update end