Class: Piston::Git::Repository

Inherits:
Repository show all
Defined in:
lib/piston/git/repository.rb

Instance Attribute Summary collapse

Attributes inherited from Repository

#url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Repository

#==, add_handler, guess, handlers, logger, #logger, #to_s

Constructor Details

#initialize(url) ⇒ Repository

Returns a new instance of Repository.



38
39
40
41
# File 'lib/piston/git/repository.rb', line 38

def initialize(url)
  @branchname = url.split("?")[1]
  super(url.sub(/\?.+$/, ""))
end

Instance Attribute Details

#branchnameObject (readonly)

Returns the value of attribute branchname.



36
37
38
# File 'lib/piston/git/repository.rb', line 36

def branchname
  @branchname
end

Class Method Details

.clientObject



23
24
25
# File 'lib/piston/git/repository.rb', line 23

def client
  @@client ||= Piston::Git::Client.instance
end

.git(*args) ⇒ Object



27
28
29
# File 'lib/piston/git/repository.rb', line 27

def git(*args)
  client.git(*args)
end

.repository_typeObject



31
32
33
# File 'lib/piston/git/repository.rb', line 31

def repository_type
  'git'
end

.understands_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/piston/git/repository.rb', line 10

def understands_url?(url)
  uri = URI.parse(url) rescue nil
  return true if uri && %w(git).include?(uri.scheme)

  begin
    response = git("ls-remote", "--heads", url.sub(/\?.+$/, ""))
    return false if response.nil? || response.strip.chomp.empty?
    !!(response =~ /[a-f\d]{40}\s/)
  rescue Piston::Git::Client::CommandError
    false
  end
end

Instance Method Details

#at(commit) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/piston/git/repository.rb', line 47

def at(commit)
  case commit
  when Hash
    Piston::Git::Commit.new(self, commit[Piston::Git::COMMIT])
  when :head
    Piston::Git::Commit.new(self, "HEAD")
  else
    Piston::Git::Commit.new(self, commit)
  end
end

#basenameObject



58
59
60
# File 'lib/piston/git/repository.rb', line 58

def basename
  self.url.split("/").last.sub(".git", "")
end

#git(*args) ⇒ Object



43
44
45
# File 'lib/piston/git/repository.rb', line 43

def git(*args)
  self.class.git(*args)
end