class Agita
Git commands / workflow helper.
Constants
- VERSION
Public Instance Methods
checkout(tagname)
click to toggle source
Checkout tag
# File lib/agita.rb, line 70 def checkout tagname run("git checkout --quiet #{Shellwords.escape(tagname)}") end
clean?(*paths)
click to toggle source
Returns true if path is clean (nothing to commit).
# File lib/agita.rb, line 53 def clean? *paths file_list = paths.map { |path| Shellwords.escape(path) } run("git status --porcelain #{file_list.join(' ')}") == '' end
commit(message, *paths)
click to toggle source
Commit path with message. If there is nothnig to be commited (git status is clean), returns false. Otherwise, does commit and returns true.
# File lib/agita.rb, line 43 def commit message, *paths return false if clean?(*paths) file_list = paths.map { |path| Shellwords.escape(path) } run "git add #{file_list.join(' ')}" run "git commit --quiet -m #{Shellwords.escape(message)}" run "git push --quiet" true end
ensure_checked_out(tagname)
click to toggle source
Raises RuntimeError unless checked out at tagname
# File lib/agita.rb, line 29 def ensure_checked_out tagname ensure_status( "HEAD detached at #{tagname}", "nothing to commit, working directory clean", ) end
ensure_master_updated_clean()
click to toggle source
Raise RuntimeError unless at branch master, up to date with ‘origin/master’ and clean.
# File lib/agita.rb, line 20 def ensure_master_updated_clean ensure_status( "On branch master", "Your branch is up-to-date with 'origin/master'.", "nothing to commit, working directory clean" ) end
ensure_status(*expected_status)
click to toggle source
Raise RuntimeError unless current status
is same as expected_status.
# File lib/agita.rb, line 7 def ensure_status *expected_status current_status = status unless current_status == expected_status raise RuntimeError.new( "Expected Git status to be:\n" + expected_status.map{|l| " #{l}"}.join("\n") + "\n" + "but it currently is:\n" + current_status.map{|l| " #{l}"}.join("\n") ) end end
status()
click to toggle source
Return Git status (git status –branch –porcelain –long) as an array.
# File lib/agita.rb, line 37 def status run('git status --branch --porcelain --long').split(/\n+/) end
tag(tagname, message)
click to toggle source
Creates and push an annotated tag
# File lib/agita.rb, line 64 def tag tagname, message run("git tag --annotate #{Shellwords.escape(tagname)} --message=#{Shellwords.escape(message)}") run("git push --quiet origin #{Shellwords.escape(tagname)}") end
Private Instance Methods
run(command)
click to toggle source
# File lib/agita.rb, line 76 def run command output = `#{command}` raise "#{command} returned non-zero status:\n#{output}" unless $?.exitstatus == 0 output end