Skip to content

Commit

Permalink
Adds command line option for branch name on initial clone so that :ge…
Browse files Browse the repository at this point in the history
…t_shallow_clone option works with branches
  • Loading branch information
cannikin committed Dec 14, 2012
1 parent 3100b91 commit b8ce59c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/capistrano/recipes/deploy/scm/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def checkout(revision, destination)
git = command
remote = origin

args = []
args = []

# Add an option for the branch name so :git_shallow_clone works with branches
args << "-b #{variable(:branch)}" unless variable(:branch).nil?
args << "-o #{remote}" unless remote == 'origin'
if depth = variable(:git_shallow_clone)
args << "--depth #{depth}"
Expand Down
10 changes: 10 additions & 0 deletions test/deploy/scm/git_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,21 @@ def test_sync_with_remote
def test_shallow_clone
@config[:repository] = "git@somehost.com:project.git"
@config[:git_shallow_clone] = 1
@config[:branch] = nil
dest = "/var/www"
rev = 'c2d9e79'
assert_equal "git clone -q --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
end

def test_shallow_clone_with_branch
@config[:repository] = "git@somehost.com:project.git"
@config[:git_shallow_clone] = 1
@config[:branch] = 'foobar'
dest = "/var/www"
rev = 'c2d9e79'
assert_equal "git clone -q -b foobar --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
end

def test_remote_clone
@config[:repository] = "git@somehost.com:project.git"
@config[:remote] = "username"
Expand Down

0 comments on commit b8ce59c

Please sign in to comment.