Skip to content

#branch name should default to current branch instead of master #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/git/base/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module Git
class Base

module Factory

# @return [Git::Branch] an object for branch_name
def branch(branch_name = 'master')
def branch(branch_name = self.current_branch)
Git::Branch.new(self, branch_name)
end

Expand Down Expand Up @@ -93,7 +92,6 @@ def merge_base(*args)
shas = self.lib.merge_base(*args)
shas.map { |sha| gcommit(sha) }
end

end

end
Expand Down
12 changes: 12 additions & 0 deletions tests/units/test_branch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ def setup
@branches = @git.branches
end

test 'Git::Lib#branch with no args should return current branch' do
in_temp_dir do
git = Git.init('.', initial_branch: 'my_branch')
File.write('file.txt', 'hello world')
git.add('file.txt')
git.commit('Initial commit')

b = git.branch
assert_equal('my_branch', b.name)
end
end

def test_branches_all
assert(@git.branches[:master].is_a?(Git::Branch))
assert(@git.branches.size > 5)
Expand Down