Module: Loca::Git::Common

Included in:
BranchCreator, BranchDeleter
Defined in:
lib/loca/git/common.rb

Instance Method Summary collapse

Instance Method Details

#branchesObject



16
17
18
# File 'lib/loca/git/common.rb', line 16

def branches
  git("for-each-ref refs/heads/ --format='%(refname:short)'").split("\n")
end

#git(cmd) ⇒ Object



9
10
11
12
13
14
# File 'lib/loca/git/common.rb', line 9

def git(cmd)
  shellout = Mixlib::ShellOut.new "git #{cmd}"
  shellout.run_command
  shellout.error!
  shellout.stdout
end

#git_urls_match?(git, http) ⇒ Boolean

Example

git_urls_match?(“github.com/smoll/loca.git”, “github.com/smoll/loca/”) # note trailing slash

> true

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/loca/git/common.rb', line 24

def git_urls_match?(git, http)
  git_uri = Addressable::URI.parse git
  http_uri = Addressable::URI.parse http
  http_uri.host == git_uri.host && http_uri.path.chomp("/").chomp(".git") == git_uri.path.chomp("/").chomp(".git")
end

#run_git_checkersObject



4
5
6
7
# File 'lib/loca/git/common.rb', line 4

def run_git_checkers
  ensure_git_repo
  ensure_no_unstashed_files
end