Skip to content

Commit 50d80b6

Browse files
Merge branch 'NotDaveLane-master'
2 parents 55dae73 + eece801 commit 50d80b6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/git/lib.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def init(opts={})
4747
#
4848
# accepts options:
4949
# :remote:: name of remote (rather than 'origin')
50+
# :branch:: name of branch to track (rather than 'master')
5051
# :bare:: no working directory
5152
# :recursive:: after the clone is created, initialize all submodules within, using their default settings.
5253
# :depth:: the number of commits back to pull
@@ -58,6 +59,7 @@ def clone(repository, name, opts = {})
5859
clone_dir = opts[:path] ? File.join(@path, name) : name
5960

6061
arr_opts = []
62+
arr_opts << "-b" << opts[:branch] if opts[:branch]
6163
arr_opts << "--bare" if opts[:bare]
6264
arr_opts << "--recursive" if opts[:recursive]
6365
arr_opts << "-o" << opts[:remote] if opts[:remote]

tests/units/test_init.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ def test_git_clone
6767
end
6868
end
6969

70+
def test_git_clone_with_branch
71+
in_temp_dir do |path|
72+
g = Git.clone(@wbare, 'clone-branch', :branch => 'test')
73+
assert_equal(g.current_branch, 'test')
74+
end
75+
end
76+
7077
def test_git_clone_bare
7178
in_temp_dir do |path|
7279
g = Git.clone(@wbare, 'bare.git', :bare => true)

0 commit comments

Comments
 (0)