Verified Commit ef384c7f authored by Robert Speicher's avatar Robert Speicher 🇲🇽

Remove LocalRepository and its Fixture

parent af7fcf75
......@@ -58,7 +58,6 @@ require 'release_tools/helm_chart_version'
require 'release_tools/helm_gitlab_version'
require 'release_tools/issuable'
require 'release_tools/issue'
require 'release_tools/local_repository'
require 'release_tools/merge_request'
require 'release_tools/monthly_issue'
require 'release_tools/omnibus_gitlab_version'
......
# frozen_string_literal: true
module ReleaseTools
class LocalRepository
def self.ready?
new.ready?
end
def ready?
master_branch? && up_to_date?
end
private
def master_branch?
run_git('rev-parse --abbrev-ref HEAD').chomp == 'master'
end
def up_to_date?
!run_git('pull --ff-only').nil?
end
def run_git(command)
out, err, st = Open3.capture3('git ' + command)
raise ScriptError.new(err) unless st.success?
out
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe ReleaseTools::LocalRepository, :silence_stdout do
let(:fixture) { LocalRepositoryFixture.new }
let(:repo_path) { File.join('/tmp', fixture.class.repository_name) }
let(:repo_url) { "file://#{fixture.fixture_path}" }
let(:repo) { ReleaseTools::RemoteRepository.get(origin: repo_url) }
before do
fixture.rebuild_fixture!
end
context 'up to date repository' do
context 'master branch' do
it 'returns true' do
ensure_branch_exists('master')
in_repo_path do
expect(described_class.ready?).to be true
end
end
end
context 'different branch' do
it 'returns false' do
ensure_branch_exists('new-branch')
in_repo_path do
expect(described_class.ready?).to be false
end
end
end
end
context 'outdated repository' do
before do
ensure_branch_exists('master')
in_repo_path do
repo.write_file('test', 'test')
repo.commit('test', message: 'test commit')
end
end
context 'master branch' do
it 'returns true if fast-forward' do
in_repo_path do
expect(described_class.ready?).to be true
end
end
end
context 'master branch' do
it 'returns false if non fast-forward' do
st = double('st', success?: false)
expect(Open3).to receive(:capture3).with('git rev-parse --abbrev-ref HEAD').and_call_original
expect(Open3).to receive(:capture3).with('git pull --ff-only').and_return(['', 'error', st])
in_repo_path do
expect { described_class.ready? }.to raise_error(ScriptError)
end
end
end
context 'different branch' do
it 'returns false' do
ensure_branch_exists('new-branch')
in_repo_path do
expect(described_class.ready?).to be false
end
end
end
end
def ensure_branch_exists(branch)
repo.ensure_branch_exists(branch)
end
def in_repo_path
Dir.chdir(repo_path) do
yield
end
end
end
# frozen_string_literal: true
require 'fileutils'
require 'rugged'
require_relative 'repository_fixture'
class LocalRepositoryFixture
include RepositoryFixture
def self.repository_name
'repo'
end
def build_fixture(options = {})
commit_blob(
path: 'README.md',
content: 'Sample README.md',
message: 'Add empty README.md'
)
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment