Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sig committed Oct 15, 2024
1 parent 98214c5 commit 64c9bde
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/ohloh_scm/git/scm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def checkout_files(names)
run "cd #{url} && git checkout $(git ls-files #{filenames})"
end

def branch_name_or_default
branch_name || 'master'
end

private

def clone_or_fetch(remote_scm, callback)
Expand Down
10 changes: 2 additions & 8 deletions lib/ohloh_scm/git/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ def branch?(name = scm.branch_name)
end

def default_branch
return standard_default_branch unless exist?
return scm.branch_name_or_default unless exist?

name = run("git remote show '#{scm.url}' | grep 'HEAD branch' | awk '{print $3}'").strip
name.present? ? name : standard_default_branch
end

private

def standard_default_branch
'master'
name.present? ? name : scm.branch_name_or_default
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/helpers/repository_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# frozen_string_literal: true

module RepositoryHelper
%w[git svn git_svn cvs hg bzr].each do |scm_type|
%w[svn git_svn cvs hg bzr].each do |scm_type|
define_method("with_#{scm_type}_repository") do |name, branch_name = nil, &block|
with_repository(scm_type, name, branch_name) { |core| block.call(core) }
end
end

def with_git_repository(name, branch_name = 'master', &block)
with_repository('git', name, branch_name) { |core| block.call(core) }
end

private

def with_repository(scm_type, name, branch_name = nil)
Expand Down
8 changes: 4 additions & 4 deletions spec/ohloh_scm/git/activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@

it 'must commit all changes in the working directory' do
tmpdir do |dir|
core = OhlohScm::Factory.get_core(scm_type: :git, url: dir)
core = OhlohScm::Factory.get_core(scm_type: :git, branch_name: 'master', url: dir)

core.activity.send(:init_db)
refute core.activity.send(:anything_to_commit?)
Expand All @@ -356,7 +356,7 @@

it 'must test that no token returns nil' do
tmpdir do |dir|
core = OhlohScm::Factory.get_core(scm_type: :git, url: dir)
core = OhlohScm::Factory.get_core(scm_type: :git, branch_name: 'master', url: dir)
refute core.activity.read_token
core.activity.send(:init_db)
refute core.activity.read_token
Expand All @@ -365,7 +365,7 @@

it 'must test write and read token' do
tmpdir do |dir|
core = OhlohScm::Factory.get_core(scm_type: :git, url: dir)
core = OhlohScm::Factory.get_core(scm_type: :git, branch_name: 'master', url: dir)
core.activity.send(:init_db)
core.activity.send(:write_token, 'FOO')
refute core.activity.read_token # Token not valid until committed
Expand All @@ -376,7 +376,7 @@

it 'must test that commit_all includes write token' do
tmpdir do |dir|
core = OhlohScm::Factory.get_core(scm_type: :git, url: dir)
core = OhlohScm::Factory.get_core(scm_type: :git, branch_name: 'master', url: dir)
core.activity.send(:init_db)
c = OhlohScm::Commit.new
c.token = 'BAR'
Expand Down
2 changes: 1 addition & 1 deletion spec/ohloh_scm/git/scm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
it 'must test the basic conversion to git' do
with_cvs_repository('cvs', 'simple') do |src_core|
tmpdir do |dest_dir|
core = OhlohScm::Factory.get_core(scm_type: :git, url: dest_dir)
core = OhlohScm::Factory.get_core(scm_type: :git, branch_name: 'master', url: dest_dir)
refute core.status.scm_dir_exist?
core.scm.pull(src_core.scm, TestCallback.new)
assert core.status.scm_dir_exist?
Expand Down

0 comments on commit 64c9bde

Please sign in to comment.