module OpenGit::Git

Public Class Methods

branch() click to toggle source
# File lib/open_git/git.rb, line 36
def self.branch
  `git rev-parse --abbrev-ref HEAD`.strip
end
is_git_repo() click to toggle source

asserting that rest of git commands will work

# 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
remote() click to toggle source
# 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) click to toggle source
# File lib/open_git/git.rb, line 18
def self.remote_url(remote_name)
  `git ls-remote --get-url #{remote_name}`.strip
end
upstream() click to toggle source
# File lib/open_git/git.rb, line 40
def self.upstream
  up = `git rev-parse --abbrev-ref --symbolic-full-name @{u}`.strip
  # ignore output if error code 128, no upstream error
  up = '' if $CHILD_STATUS == 128
  up
end
url(name = nil) click to toggle source
# 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