Class: GitUtilities
- Inherits:
-
Object
- Object
- GitUtilities
- Defined in:
- lib/cookbook-release/git-utilities.rb
Instance Attribute Summary collapse
-
#no_prompt ⇒ Object
Returns the value of attribute no_prompt.
Instance Method Summary collapse
- #choose_remote ⇒ Object
- #clean_index! ⇒ Object
- #clean_index? ⇒ Boolean
- #compute_changelog(since) ⇒ Object
- #compute_last_release ⇒ Object
-
#initialize(options = {}) ⇒ GitUtilities
constructor
A new instance of GitUtilities.
- #push_tag(version) ⇒ Object
- #reset_command(new_version) ⇒ Object
- #tag(version) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GitUtilities
Returns a new instance of GitUtilities.
10 11 12 |
# File 'lib/cookbook-release/git-utilities.rb', line 10 def initialize(={}) @tag_prefix = ['tag_prefix'] || '' end |
Instance Attribute Details
#no_prompt ⇒ Object
Returns the value of attribute no_prompt.
8 9 10 |
# File 'lib/cookbook-release/git-utilities.rb', line 8 def no_prompt @no_prompt end |
Instance Method Details
#choose_remote ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cookbook-release/git-utilities.rb', line 62 def choose_remote cmd = Mixlib::ShellOut.new("git remote") cmd.run_command cmd.error! remotes = cmd.stdout.split("\n") if remotes.size == 1 || @no_prompt puts "Choosing remote #{remotes.first}" if @no_prompt remotes.first else choose(*remotes) end end |
#clean_index! ⇒ Object
26 27 28 |
# File 'lib/cookbook-release/git-utilities.rb', line 26 def clean_index! raise "All changes must be committed!" unless clean_index? end |
#clean_index? ⇒ Boolean
18 19 20 21 22 23 24 |
# File 'lib/cookbook-release/git-utilities.rb', line 18 def clean_index? clean_index = Mixlib::ShellOut.new("git diff --exit-code") clean_index.run_command clean_staged = Mixlib::ShellOut.new("git diff --exit-code --cached") clean_staged.run_command !clean_index.error? && !clean_staged.error? end |
#compute_changelog(since) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cookbook-release/git-utilities.rb', line 41 def compute_changelog(since) # TODO use whole commit message instead of title only log_cmd = Mixlib::ShellOut.new("git log --pretty='format:%an <%ae>::%s::%h' #{since}..HEAD") log_cmd.run_command log = log_cmd.stdout log.split("\n").map do |entry| , subject, hash = entry.chomp.split("::") Commit.new({ author: , subject: subject, hash: hash }) end.reject { |commit| commit[:subject] =~ /^Merge branch (.*) into/i } end |
#compute_last_release ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cookbook-release/git-utilities.rb', line 30 def compute_last_release tag = Mixlib::ShellOut.new([ 'git describe', "--tags", "--match \"#{@tag_prefix}[0-9]\.[0-9]*\.[0-9]*\"" ].join " ") tag.run_command tag.stdout.split('-').first.to_version end |
#push_tag(version) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/cookbook-release/git-utilities.rb', line 75 def push_tag(version) remote = choose_remote cmd = Mixlib::ShellOut.new("git push #{remote} #{@tag_prefix}#{version}") cmd.run_command cmd.error! end |
#reset_command(new_version) ⇒ Object
14 15 16 |
# File 'lib/cookbook-release/git-utilities.rb', line 14 def reset_command(new_version) "git reset --hard HEAD^ && git tag -d #{new_version}" end |
#tag(version) ⇒ Object
56 57 58 59 60 |
# File 'lib/cookbook-release/git-utilities.rb', line 56 def tag(version) cmd = Mixlib::ShellOut.new("git tag #{@tag_prefix}#{version}") cmd.run_command cmd.error! end |