Module: Hoe::Git

Defined in:
lib/hoe/git.rb

Overview

This module is a Hoe plugin. You can set its attributes in your Rakefile Hoe spec, like this:

Hoe.plugin :git

Hoe.spec "myproj" do
  self.git_release_tag_prefix = "REL_"
  self.git_remotes << "myremote"
end

Constant Summary collapse

VERSION =

Duh.

"1.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#git_release_tag_prefixObject

What do you want at the front of your release tags?

default: "v"


21
22
23
# File 'lib/hoe/git.rb', line 21

def git_release_tag_prefix
  @git_release_tag_prefix
end

#git_remotesObject

Which remotes do you want to push tags, etc. to?

default: %w(origin)


26
27
28
# File 'lib/hoe/git.rb', line 26

def git_remotes
  @git_remotes
end

Instance Method Details

#define_git_tasksObject

:nodoc:



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
74
75
76
77
# File 'lib/hoe/git.rb', line 33

def define_git_tasks #:nodoc:

  desc "Print the current changelog."
  task "git:changelog" do
    tags  = `git tag -l '#{git_release_tag_prefix}*'`.split "\n"
    tag   = ENV["FROM"] || tags.last
    range = [tag, "HEAD"].compact.join ".."
    cmd   = "git log #{range} '--format=tformat:%s|||%cN|||%cE'"

    changes = `#{cmd}`.split("\n").map do |line|
      msg, author, email = line.split("|||").map { |e| e.empty? ? nil : e }

      developer = author.include?(author) || email.include?(email)
      change    = [msg]
      change   << "[#{author || email}]" unless developer

      change.join " "
    end

    puts "=== #{ENV["VERSION"] || 'NEXT'} / #{Time.new.strftime '%Y-%m-%d'}"
    puts

    changes.each { |change| puts "* #{change}" }
  end

  desc "Create and push a TAG " +
       "(default #{git_release_tag_prefix}#{version})."

  task "git:tag" do
    tag   = ENV["TAG"]
    tag ||= "#{git_release_tag_prefix}#{ENV["VERSION"] || version}"

    sh "git tag -f #{tag}"
    git_remotes.each { |remote| sh "git push -f #{remote} tag #{tag}" }
  end

  task :release_sanity do
    unless `git status` =~ /^nothing to commit/
      abort "Won't release: Dirty index or untracked files present!"
    end
  end

  task :release => "git:tag"

end

#initialize_gitObject

:nodoc:



28
29
30
31
# File 'lib/hoe/git.rb', line 28

def initialize_git #:nodoc:
  self.git_release_tag_prefix = "v"
  self.git_remotes            = %w(origin)
end