Method: Metaverse::Repo#current_branch

Defined in:
lib/metaverse/repo.rb

#current_branchObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/metaverse/repo.rb', line 50

def current_branch
  branch_name = ''

  Dir.chdir(@repo.workdir) do
    branch_name = `git branch | sed -n '/\* /s///p'`
    #TODO Look into why the command returns an empty string in a new repo
    if branch_name == ''
      branch_name = 'master'
    end
  end

  if branch_name.include? "detached"
    match = /[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+/.match(branch_name) 
    if not match.nil?
      return match[0]
    end
    return 'HEAD'
  end

  branch_name.strip
end