Class: MGit::FFMergeCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/mgit/commands/ffmerge.rb

Instance Method Summary collapse

Methods inherited from Command

#check_arity, execute, instance_each, list, load_commands, register_alias, register_command

Methods included from Output

#perror, #pinfo, #ptable, #pwarn

Instance Method Details

#arityObject



28
29
30
# File 'lib/mgit/commands/ffmerge.rb', line 28

def arity
  [nil, 0]
end

#descriptionObject



36
37
38
# File 'lib/mgit/commands/ffmerge.rb', line 36

def description
  'merge all upstream tracking branches that can be fast-forwarded'
end

#execute(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mgit/commands/ffmerge.rb', line 3

def execute(args)
  Registry.chdir_each do |repo|

    bs = repo.remote_tracking_branches.select do |branch, upstream|
      !repo.unmerged_commits(branch, upstream).empty?
    end.map { |b, u| b }

    next if bs.empty?

    if repo.dirty?
      pwarn "Skipping repository #{repo.name} since it's dirty."
      next
    end 

    pinfo "Fast-forward merging branches in repository #{repo.name}..."

    cb = repo.current_branch
    bs.each do |b|
      `git checkout -q #{b}`
      `git merge --ff-only @{u}`
    end
    `git checkout -q #{cb}`
  end
end

#usageObject



32
33
34
# File 'lib/mgit/commands/ffmerge.rb', line 32

def usage
  'ffmerge'
end