1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Cleaning up git shallow clone and adding tests

This commit is contained in:
Patrick Waters 2015-08-10 18:47:31 -05:00
parent 6b9bc88f3a
commit 6c8a23b443
3 changed files with 13 additions and 9 deletions

View file

@ -4,6 +4,8 @@ Reverse Chronological Order:
## master ## master
* Added support for git shallow clone
https://github.com/capistrano/capistrano/compare/v3.4.0...HEAD https://github.com/capistrano/capistrano/compare/v3.4.0...HEAD
* Remove 'vendor/bundle' from default :linked_dirs (@ojab) * Remove 'vendor/bundle' from default :linked_dirs (@ojab)

View file

@ -22,16 +22,17 @@ class Capistrano::Git < Capistrano::SCM
end end
def clone def clone
if fetch(:git_shallow_clone) if depth = fetch(:git_shallow_clone)
git :clone, '--mirror', '--depth 1', repo_url, repo_path git :clone, '--mirror', '--depth', depth, '--no-single-branch', repo_url, repo_path
else else
git :clone, '--mirror', repo_url, repo_path git :clone, '--mirror', repo_url, repo_path
end end
end end
def update def update
if fetch(:git_shallow_clone) # Note: Requires git version 1.9 or greater
git :fetch, '--depth 1', '--update-shallow', "origin #{fetch(:branch)}" if depth = fetch(:git_shallow_clone)
git :fetch, '--depth', depth, 'origin', fetch(:branch)
else else
git :remote, :update git :remote, :update
end end

View file

@ -48,10 +48,11 @@ module Capistrano
end end
it "should run git clone in shallow mode" do 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_url).returns(:url)
context.expects(:repo_path).returns(:path) 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 subject.clone
end end
@ -66,9 +67,9 @@ module Capistrano
end end
it "should run git update in shallow mode" do 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(: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 subject.update
end end