Class: Agita
- Inherits:
-
Object
- Object
- Agita
- Defined in:
- lib/agita.rb,
lib/agita/version.rb
Overview
Git commands / workflow helper.
Constant Summary collapse
- VERSION =
'0.4.0'
Instance Method Summary collapse
-
#checkout(tagname) ⇒ Object
Checkout tag.
-
#clean?(*paths) ⇒ Boolean
Returns true if path is clean (nothing to commit).
-
#commit(message, *paths) ⇒ Object
Commit path with message.
-
#ensure_checked_out(tagname) ⇒ Object
Raises RuntimeError unless checked out at tagname.
-
#ensure_master_updated_clean ⇒ Object
Raise RuntimeError unless at branch master, up to date with ‘origin/master’ and clean.
-
#ensure_status(*expected_status) ⇒ Object
Raise RuntimeError unless current #status is same as expected_status.
-
#status ⇒ Object
Return Git status (git status –branch –porcelain –long) as an array.
-
#tag(tagname, message) ⇒ Object
Creates and push an annotated tag.
-
#tags ⇒ Object
Returns list of all tags.
Instance Method Details
#checkout(tagname) ⇒ Object
Checkout tag
70 71 72 |
# File 'lib/agita.rb', line 70 def checkout tagname run("git checkout --quiet #{Shellwords.escape(tagname)}") end |
#clean?(*paths) ⇒ Boolean
Returns true if path is clean (nothing to commit).
53 54 55 56 |
# 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) ⇒ Object
Commit path with message. If there is nothnig to be commited (git status is clean), returns false. Otherwise, does commit and returns true.
43 44 45 46 47 48 49 50 |
# File 'lib/agita.rb', line 43 def commit , *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) ⇒ Object
Raises RuntimeError unless checked out at tagname
29 30 31 32 33 34 |
# 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 ⇒ Object
Raise RuntimeError unless at branch master, up to date with ‘origin/master’ and clean.
20 21 22 23 24 25 26 |
# 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) ⇒ Object
Raise RuntimeError unless current #status is same as expected_status.
7 8 9 10 11 12 13 14 15 16 17 |
# 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 ⇒ Object
Return Git status (git status –branch –porcelain –long) as an array.
37 38 39 |
# File 'lib/agita.rb', line 37 def status run('git status --branch --porcelain --long').split(/\n+/) end |
#tag(tagname, message) ⇒ Object
Creates and push an annotated tag
64 65 66 67 |
# File 'lib/agita.rb', line 64 def tag tagname, run("git tag --annotate #{Shellwords.escape(tagname)} --message=#{Shellwords.escape(message)}") run("git push --quiet origin #{Shellwords.escape(tagname)}") end |
#tags ⇒ Object
Returns list of all tags
59 60 61 |
# File 'lib/agita.rb', line 59 def run('git tag -l').split("\n") end |