Class: GitCompound::Repository::GitRepository
- Inherits:
-
Object
- Object
- GitCompound::Repository::GitRepository
show all
- Defined in:
- lib/git_compound/repository/git_repository.rb
Overview
Git repository base class
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GitRepository.
6
7
8
|
# File 'lib/git_compound/repository/git_repository.rb', line 6
def initialize(source)
@source = source
end
|
Instance Method Details
#branch?(branch) ⇒ Boolean
43
44
45
46
|
# File 'lib/git_compound/repository/git_repository.rb', line 43
def branch?(branch)
matching = refs.select { |refs| refs.include?(branch.to_s) }
matching.any?
end
|
#branches ⇒ Object
28
29
30
|
# File 'lib/git_compound/repository/git_repository.rb', line 28
def branches
refs_select('heads')
end
|
#clone(destination, options = nil, source = @source) ⇒ Object
10
11
12
13
14
|
# File 'lib/git_compound/repository/git_repository.rb', line 10
def clone(destination, options = nil, source = @source)
args = "#{source} #{destination}"
args.prepend(options + ' ') if options
GitCommand.new(:clone, args).execute
end
|
#file_contents(_file, _ref) ⇒ Object
62
63
64
|
# File 'lib/git_compound/repository/git_repository.rb', line 62
def file_contents(_file, _ref)
raise NotImplementedError
end
|
#file_exists?(_file, _ref) ⇒ Boolean
66
67
68
|
# File 'lib/git_compound/repository/git_repository.rb', line 66
def file_exists?(_file, _ref)
raise NotImplementedError
end
|
#files_contents(files, ref) ⇒ Object
Returns contents of first file found
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/git_compound/repository/git_repository.rb', line 50
def files_contents(files, ref)
files.each do |file|
begin
return file_contents(file, ref)
rescue FileNotFoundError
next
end
end
raise FileNotFoundError,
"Couldn't find any of #{files} files"
end
|
#refs ⇒ Object
21
22
23
24
25
26
|
# File 'lib/git_compound/repository/git_repository.rb', line 21
def refs
@refs ||= GitCommand.new('ls-remote', @source).execute
@refs.scan(%r{^(\b[0-9a-f]{5,40}\b)\srefs\/(heads|tags)\/(.+)})
rescue GitCommandError => e
raise RepositoryUnreachableError, "Could not reach repository: #{e.message}"
end
|
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/git_compound/repository/git_repository.rb', line 32
def tags
all = refs_select('tags')
annotated = all.select { |tag, _| tag =~ /\^\{\}$/ }
annotated.each_pair do |annotated_tag, annotated_tag_sha|
tag = annotated_tag.sub(/\^\{\}$/, '')
all.delete(annotated_tag)
all[tag] = annotated_tag_sha
end
all
end
|
#versions ⇒ Object
16
17
18
19
|
# File 'lib/git_compound/repository/git_repository.rb', line 16
def versions
git_versions = tags.map { |tag, sha| GitVersion.new(tag, sha) }
git_versions.select(&:valid?)
end
|