Class: SCM
- Inherits:
-
Object
- Object
- SCM
- Defined in:
- lib/version50/scm.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#branch(b) ⇒ Object
create a branch.
-
#checkout(b) ⇒ Object
checkout a branch.
-
#commit(options = {}) ⇒ Object
commit changes without pushing.
-
#config(info) ⇒ Object
configure the repo with the user’s info.
- #download(url, path = '') ⇒ Object
-
#init ⇒ Object
initialize a new repo.
-
#initialize(version50) ⇒ SCM
constructor
A new instance of SCM.
-
#log ⇒ Object
view the project history.
-
#present ⇒ Object
return to the present.
- #pull ⇒ Object
-
#push ⇒ Object
push existing commits.
-
#recover(path) ⇒ Object
recover a path from a warp.
- #reset ⇒ Object
-
#save(commit_options = {}) ⇒ Object
shortcut for commit and push.
-
#status ⇒ Object
view changed files.
-
#warp(revision = nil) ⇒ Object
warp to a specific revision.
Constructor Details
#initialize(version50) ⇒ SCM
Returns a new instance of SCM.
5 6 7 |
# File 'lib/version50/scm.rb', line 5 def initialize(version50) @version50 = version50 end |
Instance Method Details
#branch(b) ⇒ Object
create a branch
10 11 |
# File 'lib/version50/scm.rb', line 10 def branch b end |
#checkout(b) ⇒ Object
checkout a branch
14 15 16 |
# File 'lib/version50/scm.rb', line 14 def checkout b self.save({ :quiet => true }) end |
#commit(options = {}) ⇒ Object
commit changes without pushing
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/version50/scm.rb', line 19 def commit( = {}) # make sure we're not in a warp config = @version50.parse_config if config['warp'] puts "\033[31mYou cannot commit any changes until you warp back to the present!\033[0m" return end # check if we have anything to commit files = self.status if files[:added].length == 0 && files[:modified].length == 0 && files[:deleted].length == 0 if ![:quiet] puts "Nothing has changed since your last save!" end # prompt for commit message else puts "\033[34mWhat changes have you made since your last save?\033[0m " = $stdin.gets.chomp end return end |
#config(info) ⇒ Object
configure the repo with the user’s info
44 45 |
# File 'lib/version50/scm.rb', line 44 def config info end |
#download(url, path = '') ⇒ Object
47 48 |
# File 'lib/version50/scm.rb', line 47 def download(url, path = '') end |
#init ⇒ Object
initialize a new repo
51 52 |
# File 'lib/version50/scm.rb', line 51 def init end |
#log ⇒ Object
view the project history
55 56 |
# File 'lib/version50/scm.rb', line 55 def log end |
#present ⇒ Object
return to the present
59 60 |
# File 'lib/version50/scm.rb', line 59 def present end |
#pull ⇒ Object
62 63 |
# File 'lib/version50/scm.rb', line 62 def pull end |
#push ⇒ Object
push existing commits
66 67 |
# File 'lib/version50/scm.rb', line 66 def push end |
#recover(path) ⇒ Object
recover a path from a warp
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/version50/scm.rb', line 70 def recover path # determine what warp we're in config = @version50.parse_config if !config['warp'] puts "\033[31mYou have to warp to another revision before you can recover anything!\033[0m" return end # make sure file exists if Dir.glob(path).empty? puts "\033[31mSpecify a valid path to recover!\033[0m" return end # copy all files in path into warps folder warp = config['warp'] files = Dir.glob path root = @version50.root files.each do |f| FileUtils.mkdir_p(root + '/.version50-warps/' + File.dirname(f)) FileUtils.cp(f, root + '/.version50-warps/' + File.dirname(f)) end # display which files were recovered if files.length == 1 puts "\033[032mRecovered #{files[0]}!\033[0m" else puts "\033[032mRecovered:\n" files.each do |f| puts "* #{f}" end puts "\033[0m" end end |
#reset ⇒ Object
105 106 |
# File 'lib/version50/scm.rb', line 105 def reset end |
#save(commit_options = {}) ⇒ Object
shortcut for commit and push
109 110 111 112 |
# File 'lib/version50/scm.rb', line 109 def save( = {}) self.commit self.push end |
#status ⇒ Object
view changed files
115 116 |
# File 'lib/version50/scm.rb', line 115 def status end |
#warp(revision = nil) ⇒ Object
warp to a specific revision
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/version50/scm.rb', line 119 def warp revision = nil # warp back to the present if revision == 'present' puts "\033[032mWarped back to the present!\033[0m" self.present # remove warp number from .version50 config = @version50.parse_config config.delete 'warp' File.open(@version50.root + '/.version50', 'w') do |f| f.write config.to_yaml end # move files from warps folder root = @version50.root FileUtils.mv(Dir.glob(root + '/.version50-warps/*'), root) return false end # save before doing anything self.save({ :quiet => true }) # prompt for revision if not given if !revision print "\033[34mWhat version would you like to warp to?\033[0m " revision = $stdin.gets.chomp.to_i(10) else revision = revision.to_i(10) end # get revision from numerical index revisions = self.log r = revisions[revisions.length - revision] # record where we warped config = @version50.parse_config config['warp'] = revision File.open(@version50.root + '/.version50', 'w') do |f| f.write config.to_yaml end puts "\033[032mWarped to revision ##{revision}!\033[0m" # add numerical index to return value r[:revision] = revision return r end |