Class: RSpec::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/braid/rspec_git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/braid/rspec_git.rb', line 4

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/braid/rspec_git.rb', line 4

def path
  @path
end

#urlObject (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_remotesObject



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/braid/rspec_git.rb', line 98

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

#commitObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/braid/rspec_git.rb', line 72

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_resetObject



90
91
92
93
94
95
96
# File 'lib/braid/rspec_git.rb', line 90

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

Returns:

  • (Boolean)


16
17
18
# File 'lib/braid/rspec_git.rb', line 16

def plugins_fetched?
  submodules.all? {|s| File.directory?(s[:path]) }
end

#pushObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/braid/rspec_git.rb', line 59

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

#statusObject



52
53
54
55
56
57
# File 'lib/braid/rspec_git.rb', line 52

def status
  repos.each do |r|
    msg "\n** #{r[:name]} status"
    system "cd #{r[:path]} && git status"
  end
end

#tagObject



110
111
112
113
114
115
116
117
118
119
# File 'lib/braid/rspec_git.rb', line 110

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
42
43
44
45
46
47
48
49
50
# 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 
      unless target == "master"
        unless system "cd #{r[:path]} && git checkout -b #{target} origin/#{target}"
          msg "Error checking out branch #{target}"
          exit 1
        end 
      end
      msg "*** repo #{r[:name]} created successfully ***"
    end
    
  end
  msg "*** all repos updated successfully ***"
end