Class: FlexmlsGems::GitHelper
- Inherits:
-
Object
- Object
- FlexmlsGems::GitHelper
- Includes:
- Grit
- Defined in:
- lib/flexmls_gems/git_helper.rb
Instance Attribute Summary collapse
-
#pwd ⇒ Object
readonly
Returns the value of attribute pwd.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #check_remote ⇒ Object
- #check_status ⇒ Object
- #check_tags ⇒ Object
- #cmd_add(file) ⇒ Object
- #cmd_add_tag ⇒ Object
- #cmd_changes ⇒ Object
- #cmd_commit(message) ⇒ Object
- #cmd_ls_remote ⇒ Object
- #cmd_push_master ⇒ Object
- #cmd_push_tags ⇒ Object
- #cmd_remote_list ⇒ Object
- #cmd_tags ⇒ Object
- #commit_version ⇒ Object
- #git ⇒ Object
-
#initialize(dir, version) ⇒ GitHelper
constructor
A new instance of GitHelper.
- #release ⇒ Object
- #tag ⇒ Object
Constructor Details
#initialize(dir, version) ⇒ GitHelper
Returns a new instance of GitHelper.
10 11 12 13 |
# File 'lib/flexmls_gems/git_helper.rb', line 10 def initialize(dir, version) @pwd = dir @version = version end |
Instance Attribute Details
#pwd ⇒ Object (readonly)
Returns the value of attribute pwd.
8 9 10 |
# File 'lib/flexmls_gems/git_helper.rb', line 8 def pwd @pwd end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
8 9 10 |
# File 'lib/flexmls_gems/git_helper.rb', line 8 def version @version end |
Instance Method Details
#check_remote ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/flexmls_gems/git_helper.rb', line 20 def check_remote if cmd_remote_list.include? "origin" matches = cmd_ls_remote if matches != "" raise GitError, "Git tag #{tag} already exists on the origin remote repository" end else raise GitError, "Git origin is missing, have you setup a remote repository?" end end |
#check_status ⇒ Object
15 16 17 18 |
# File 'lib/flexmls_gems/git_helper.rb', line 15 def check_status changes = cmd_changes raise GitError, "There are #{changes} outstanding changes in the repository. Run 'git status' to address before tagging" if changes > 0 end |
#check_tags ⇒ Object
35 36 37 38 39 |
# File 'lib/flexmls_gems/git_helper.rb', line 35 def if .include? tag raise GitError, "The tag #{tag} already exists locally" end end |
#cmd_add(file) ⇒ Object
61 62 63 |
# File 'lib/flexmls_gems/git_helper.rb', line 61 def cmd_add(file) git.add(file) end |
#cmd_add_tag ⇒ Object
77 78 79 |
# File 'lib/flexmls_gems/git_helper.rb', line 77 def cmd_add_tag `git tag -a #{tag} -m "Adding new tag '#{tag}'for release"` end |
#cmd_changes ⇒ Object
67 68 69 70 |
# File 'lib/flexmls_gems/git_helper.rb', line 67 def cmd_changes s = git.status changes = reject_ignores(s.changed).count + reject_ignores(s.added).count + s.deleted.count end |
#cmd_commit(message) ⇒ Object
64 65 66 |
# File 'lib/flexmls_gems/git_helper.rb', line 64 def cmd_commit() git.commit_index() end |
#cmd_ls_remote ⇒ Object
74 75 76 |
# File 'lib/flexmls_gems/git_helper.rb', line 74 def cmd_ls_remote `git ls-remote --tags origin #{tag}` end |
#cmd_push_master ⇒ Object
80 81 82 83 |
# File 'lib/flexmls_gems/git_helper.rb', line 80 def cmd_push_master raise GitError, "HEAD is not on the master branch" unless git.head.name == "master" `git push origin master` end |
#cmd_push_tags ⇒ Object
84 85 86 |
# File 'lib/flexmls_gems/git_helper.rb', line 84 def `git push origin --tags` end |
#cmd_remote_list ⇒ Object
87 88 89 |
# File 'lib/flexmls_gems/git_helper.rb', line 87 def cmd_remote_list git.remote_list end |
#cmd_tags ⇒ Object
71 72 73 |
# File 'lib/flexmls_gems/git_helper.rb', line 71 def git. end |
#commit_version ⇒ Object
50 51 52 53 54 |
# File 'lib/flexmls_gems/git_helper.rb', line 50 def commit_version cmd_add "VERSION" raise GitError, "Some uncommitted files are in the folder." unless cmd_changes == 1 cmd_commit "Bumped version #{tag}" end |
#git ⇒ Object
56 57 58 59 |
# File 'lib/flexmls_gems/git_helper.rb', line 56 def git @git = Repo.new(pwd) if @git.nil? return @git end |
#release ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/flexmls_gems/git_helper.rb', line 41 def release check_status check_remote cmd_add_tag cmd_push_master end |
#tag ⇒ Object
31 32 33 |
# File 'lib/flexmls_gems/git_helper.rb', line 31 def tag "v#{version.chomp}" end |