Module: OpenGit::Git

Defined in:
lib/open_git/git.rb

Defined Under Namespace

Classes: InvalidRemoteError, NoGitRepoError, NoRemoteError

Class Method Summary collapse

Class Method Details

.branchObject



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

def self.branch
  return `git rev-parse --abbrev-ref HEAD`.strip
end

.is_git_repoObject

asserting that rest of git commands will work



13
14
15
16
# File 'lib/open_git/git.rb', line 13

def self.is_git_repo
  # only returns true if in git repo and not in the .git folder itself
  `git rev-parse --is-inside-work-tree`.strip == "true"
end

.remoteObject



30
31
32
33
34
# File 'lib/open_git/git.rb', line 30

def self.remote
  lines = `git remote`.lines
  raise OpenGit::Git::NoRemoteError if lines.size == 0
  lines[-1].strip
end

.remote_url(remote_name) ⇒ Object



18
19
20
# File 'lib/open_git/git.rb', line 18

def self.remote_url(remote_name)
  `git ls-remote --get-url #{remote_name}`.strip
end

.url(name = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/open_git/git.rb', line 22

def self.url(name = nil)
  remote_name = name || self.remote
  url = self.remote_url(remote_name)
  # git returns the remote id instead of link if it is not valid
  raise OpenGit::Git::InvalidRemoteError if url == remote_name
  url
end