Skip to content

Commit 3dda040

Browse files
authored
#branch name should default to current branch instead of master (#638)
Signed-off-by: James Couball <jcouball@yahoo.com>
1 parent d33d563 commit 3dda040

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/git/base/factory.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ module Git
33
class Base
44

55
module Factory
6-
76
# @return [Git::Branch] an object for branch_name
8-
def branch(branch_name = 'master')
7+
def branch(branch_name = self.current_branch)
98
Git::Branch.new(self, branch_name)
109
end
1110

@@ -93,7 +92,6 @@ def merge_base(*args)
9392
shas = self.lib.merge_base(*args)
9493
shas.map { |sha| gcommit(sha) }
9594
end
96-
9795
end
9896

9997
end

tests/units/test_branch.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ def setup
1414
@branches = @git.branches
1515
end
1616

17+
test 'Git::Lib#branch with no args should return current branch' do
18+
in_temp_dir do
19+
git = Git.init('.', initial_branch: 'my_branch')
20+
File.write('file.txt', 'hello world')
21+
git.add('file.txt')
22+
git.commit('Initial commit')
23+
24+
b = git.branch
25+
assert_equal('my_branch', b.name)
26+
end
27+
end
28+
1729
def test_branches_all
1830
assert(@git.branches[:master].is_a?(Git::Branch))
1931
assert(@git.branches.size > 5)

0 commit comments

Comments
 (0)