Method: Daddy::Git#branches

Defined in:
lib/daddy/git.rb

#branches(remote = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/daddy/git.rb', line 5

def branches(remote = false)
  branches = []
  `git branch -a`.split("\n").each do |b|
    next unless b.index('remotes/origin/master') or b.index(/remotes\/origin\/p[0-9]+(\.[0-9]+)?/)
    
    if remote
      branches << b.strip
    else
      branches << b.strip.sub('remotes/origin/', '')
    end
  end
  
  branches.sort! do |a, b|
    if a == 'master' or a == 'remotes/origin/master'
      -1
    elsif b == 'master' or b == 'remotes/origin/master'
      1
    else
      if remote
        b.sub('remotes/origin/p', '').to_f <=> a.sub('remotes/origin/p', '').to_f
      else
        b.sub('p', '').to_f <=> a.sub('p', '').to_f
      end
    end
  end
  
  branches
end