Class: Homebrew::DevCmd::BumpRevision

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/bump-revision.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'dev-cmd/bump-revision.rb', line 30

def run
  # As this command is simplifying user-run commands then let's just use a
  # user path, too.
  ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s

  args.named.to_formulae.each do |formula|
    current_revision = formula.revision
    new_revision = current_revision + 1

    if args.dry_run?
      unless args.quiet?
        old_text = "revision #{current_revision}"
        new_text = "revision #{new_revision}"
        if current_revision.zero?
          ohai "add #{new_text.inspect}"
        else
          ohai "replace #{old_text.inspect} with #{new_text.inspect}"
        end
      end
    else
      Homebrew.install_bundler_gems!(groups: ["ast"])
      require "utils/ast"

      formula_ast = Utils::AST::FormulaAST.new(formula.path.read)
      if current_revision.zero?
        formula_ast.add_stanza(:revision, new_revision)
      else
        formula_ast.replace_stanza(:revision, new_revision)
      end
      formula_ast.remove_stanza(:bottle) if args.remove_bottle_block?
      formula.path.atomic_write(formula_ast.process)
    end

    message = "#{formula.name}: revision bump #{args.message}"
    if args.dry_run?
      ohai "git commit --no-edit --verbose --message=#{message} -- #{formula.path}"
    elsif !args.write_only?
      formula.path.parent.cd do
        safe_system "git", "commit", "--no-edit", "--verbose",
                    "--message=#{message}", "--", formula.path
      end
    end
  end
end