Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#diff_all_branhces_with_master(options) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'bin/github_branch_list', line 97

def diff_all_branhces_with_master options

  if options[:just_remote_branches]
    `git fetch origin`
    title_block "REMOTE BRANCHES"
    branches = remote_branches(true)
    branches.each do |br|
      diff_branches "origin/master", br, options
    end
  end

  options[:just_remote_branches] = false
  if options[:just_local_branches]
    `git fetch origin`
    title_block "LOCAL BRANCHES"
    branches = remote_branches(false)
    branches.each do |br|
      diff_branches "master", br, options
    end
  end

end

#diff_branches(br1, br2, options) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'bin/github_branch_list', line 61

def diff_branches br1, br2, options

  name1 = br1.gsub /origin\//, ""
  name2 = br2.gsub /origin\//, ""


  return if name1 == name2

  ahead = `git rev-list #{br1}..#{br2} | wc -l`.strip
  behind = `git rev-list #{br2}..#{br1} | wc -l`.strip

  display = true
  if (options.include?(:to_delete) || options.include?(:to_delete_with_proposal)) && (ahead.to_i != 0)
    display = false 
  end

  if display == true
    puts 
    puts "#{name2} from #{name1} is #{ahead} ahead "
    puts "#{name2} from #{name1} is #{behind} behind "
    if options.include?(:to_delete_with_proposal)
      puts "Do you want to delete the remote branch #{name2}? [y/N]"
      r = STDIN.gets
      if r.strip == "y"
        if options[:just_remote_branches]
          `git push origin :#{name2}`
        else 
          `git br -D #{name2}`
        end
      end
    end
    
  end

end

#remote_branches(remotes = false) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'bin/github_branch_list', line 45

def remote_branches remotes=false
  branches = []
  if remotes
    output = `git branch -r`
  else
    output = `git branch`
  end
  output.each_line do |line|
    unless line =~ /HEAD/
      branches << line.strip.gsub(/\* /,"")
    end
  end
  branches.delete_at(0)
  branches
end

#title_block(text = "") ⇒ Object



120
121
122
123
124
125
# File 'bin/github_branch_list', line 120

def title_block text=""
  puts
  puts "========================================"
  puts text
  puts "========================================"
end