Skip to content

Commit f7be4d5

Browse files
committed
Replace gem Rugged with Git
Rugged incurs a very high cost at install time due to the compilation of libgit2. It takes way too long and can have annoying errors. octocatalog-diff requires almost nothing from Git, therefore use a much lighter weight approach and shell out to Git with a different gem.
1 parent 59d46a6 commit f7be4d5

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

lib/octocatalog-diff/catalog-util/git.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'rugged'
3+
require 'git'
44

55
require_relative '../errors'
66
require_relative '../util/scriptrunner'
@@ -64,8 +64,8 @@ def self.branch_sha(options = {})
6464
if dir.nil? || !File.directory?(dir)
6565
raise Errno::ENOENT, "Git directory #{dir.inspect} does not exist"
6666
end
67-
repo = Rugged::Repository.new(dir)
68-
repo.branches[branch].target_id
67+
repo = ::Git.open(dir)
68+
repo.branch(branch).gcommit.sha
6969
end
7070
end
7171
end

octocatalog-diff.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ EOF
2929
s.add_runtime_dependency 'httparty', '>= 0.21.0'
3030
s.add_runtime_dependency 'hashdiff', '>= 0.3.0'
3131
s.add_runtime_dependency 'parallel', '>= 1.12.0'
32-
s.add_runtime_dependency 'rugged', '>= 0.25.0b2'
32+
s.add_runtime_dependency 'git', '~> 4'
3333
s.add_runtime_dependency 'puppet', '>= 5.5.0'
3434
s.add_development_dependency 'puppet', '>= 5.5.0'
3535
s.add_development_dependency 'rspec', '~> 3.4.0'

rake/doc.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'erb'
22
require 'optparse'
3-
require 'rugged'
43

54
require_relative '../lib/octocatalog-diff/cli/options'
65
require_relative '../lib/octocatalog-diff/version'

spec/octocatalog-diff/tests/catalog-util/cached_master_directory_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
require OctocatalogDiff::Spec.require_path('/catalog-util/cached_master_directory')
55

66
require 'fileutils'
7+
require 'git'
78
require 'json'
89
require 'open3'
9-
require 'rugged'
1010
require 'tmpdir'
1111

1212
describe OctocatalogDiff::CatalogUtil::CachedMasterDirectory do
@@ -66,9 +66,9 @@
6666

6767
it 'should have the expected SHA returned by rugged' do
6868
pending 'repository checkout fixture missing' unless File.directory?(@default_options[:basedir])
69-
repo = Rugged::Repository.new(@default_options[:basedir])
70-
test_rugged_sha = repo.branches['master'].target_id
71-
expect(test_rugged_sha).to eq(@master_sha)
69+
repo = Git.open(@default_options[:basedir])
70+
test_git_sha = repo.branch('master').gcommit.sha
71+
expect(test_git_sha).to eq(@master_sha)
7272
end
7373
end
7474

spec/octocatalog-diff/tests/catalog-util/git_spec.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@logger, @logger_str = OctocatalogDiff::Spec.setup_logger
1414
allow(File).to receive(:'directory?').with('/tmp/foo').and_return(false)
1515
allow(File).to receive(:'directory?').with('/tmp/bar').and_return(true)
16+
allow(File).to receive(:'directory?').with('.').and_return(true)
1617
end
1718

1819
describe '#check_out_git_archive' do
@@ -93,14 +94,10 @@
9394
end
9495

9596
context 'with valid directory' do
96-
it 'should return the sha from rugged' do
97-
opts = { branch: 'foo', basedir: '/tmp/bar' }
98-
expect(Rugged::Repository).to receive(:new).with('/tmp/bar')
99-
.and_return(OpenStruct.new(branches: {
100-
'foo' => OpenStruct.new(target_id: 'abcdef012345')
101-
}))
97+
it 'should return the sha' do
98+
opts = { branch: 'master', basedir: '.' }
10299
result = described_class.branch_sha(opts)
103-
expect(result).to eq('abcdef012345')
100+
expect(result).to match(/^[0-9a-f]+$/)
104101
end
105102
end
106103
end

0 commit comments

Comments
 (0)