Class: RSpec::Git
- Inherits:
-
Object
- Object
- RSpec::Git
- Defined in:
- lib/braid/rspec_git.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #add_remotes ⇒ Object
- #commit ⇒ Object
- #hard_reset ⇒ Object
-
#initialize(name, path, url) ⇒ Git
constructor
A new instance of Git.
- #msg(str) ⇒ Object
- #plugins_fetched? ⇒ Boolean
- #push ⇒ Object
- #status ⇒ Object
- #tag ⇒ Object
- #update(target) ⇒ Object
Constructor Details
#initialize(name, path, url) ⇒ Git
Returns a new instance of Git.
6 7 8 9 10 |
# File 'lib/braid/rspec_git.rb', line 6 def initialize(name, path, url) @name = name @path = path @url = url end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/braid/rspec_git.rb', line 4 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/braid/rspec_git.rb', line 4 def path @path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/braid/rspec_git.rb', line 4 def url @url end |
Instance Method Details
#add_remotes ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/braid/rspec_git.rb', line 89 def add_remotes if ENV['REPO_PREFIX'].nil? || ENV['NAME'].nil? msg "You must pass a prefix and name. Try it again with (e.g.):\n" + "rake git:add_remotes REPO_PREFIX='git://github.com/dchelimsky' NAME='dc'" return end repos.each do |r| system "cd #{r[:path]} && git remote add #{ENV['NAME']} #{r[:url]}" end end |
#commit ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/braid/rspec_git.rb', line 63 def commit if ENV['MESSAGE'].nil? msg "You must pass a commit message. Try it again with:\n" + "rake git:commit MESSAGE='commit message here'" return end repos.each do |r| output = `cd #{r[:path]} && git status` unless output.include?('On branch master') msg "*** #{r[:name]} is not on the master branch. Skipping" next end msg "** Committing #{r[:name]}" system "cd #{r[:path]} && git commit -a -m #{ENV['MESSAGE'].inspect}" end end |
#hard_reset ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/braid/rspec_git.rb', line 81 def hard_reset repos.each do |r| msg "\n** Resetting #{r[:name]}" system "cd #{r[:path]} && git add . && git reset --hard" end msg end |
#msg(str) ⇒ Object
12 13 14 |
# File 'lib/braid/rspec_git.rb', line 12 def msg(str) puts "RSpec: #{str}" end |
#plugins_fetched? ⇒ Boolean
16 17 18 |
# File 'lib/braid/rspec_git.rb', line 16 def plugins_fetched? submodules.all? {|s| File.directory?(s[:path]) } end |
#push ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/braid/rspec_git.rb', line 50 def push check_for_clean_repos "Unable to push" repos.each do |r| msg "** push #{r[:name]}" unless system("cd #{r[:path]} && git push && git push --tags") msg "Error pushing #{r[:name]}" exit 1 end end msg "Successfully pushed changes to github" end |
#status ⇒ Object
43 44 45 46 47 48 |
# File 'lib/braid/rspec_git.rb', line 43 def status repos.each do |r| msg "\n** #{r[:name]} status" system "cd #{r[:path]} && git status" end end |
#tag ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/braid/rspec_git.rb', line 101 def tag if ENV['TAG'].nil? msg "You must pass a tag. Try again like so:\n" + " TAG=1.1.4 rake git:tag" return end repos.each do |r| system "cd #{r[:path]} && git tag #{ENV['TAG']}" end end |
#update(target) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/braid/rspec_git.rb', line 20 def update(target) check_for_clean_repos "Unable to update" repos.each do |r| if File.exist?(r[:path]) msg "** Updating #{r[:name]}" target = target ? target : "master" # unless system("cd #{r[:path]} && git pull --rebase #{target}") unless system("cd #{r[:path]} && git pull --rebase #{r[:url]} #{target}") msg "Error updating #{r[:name]}" exit 1 end else msg "** Fetching #{r[:name]}" unless system "git clone #{r[:url]} #{r[:path]}" msg "Error cloning #{r[:url]}" exit 1 end end end msg "*** all repos updated successfully ***" end |