Class: OpenDelivery::SourceControl
- Inherits:
-
Object
- Object
- OpenDelivery::SourceControl
- Defined in:
- lib/opendelivery/source_control.rb
Instance Method Summary collapse
- #add(files) ⇒ Object
- #commit(message) ⇒ Object
- #conflicted(status) ⇒ Object
-
#initialize(dir) ⇒ SourceControl
constructor
A new instance of SourceControl.
- #log(lines = 10) ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #remove_missing_files(status) ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(dir) ⇒ SourceControl
Returns a new instance of SourceControl.
25 26 27 |
# File 'lib/opendelivery/source_control.rb', line 25 def initialize(dir) @dir = dir end |
Instance Method Details
#add(files) ⇒ Object
52 53 54 55 56 |
# File 'lib/opendelivery/source_control.rb', line 52 def add(files) Dir.chdir(@dir) do `git add #{files} -v` end end |
#commit(message) ⇒ Object
58 59 60 61 62 |
# File 'lib/opendelivery/source_control.rb', line 58 def commit() Dir.chdir(@dir) do `git commit -m "#{}"` end end |
#conflicted(status) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/opendelivery/source_control.rb', line 80 def conflicted(status) status.each_line do |stat| if stat.match(/^UU /) || stat.match(/^U /) || stat.match(/^U /) raise "You have file conflicts when trying to merge. Because this could end up horribly, we won't try to automatically fix these conflicts. Please go an manually merge the files!" end end end |
#log(lines = 10) ⇒ Object
29 30 31 32 33 |
# File 'lib/opendelivery/source_control.rb', line 29 def log(lines=10) Dir.chdir(@dir) do `git log --stat -n #{lines}` end end |
#pull ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/opendelivery/source_control.rb', line 70 def pull Dir.chdir(@dir) do @result = `git pull` end if $?.to_i != 0 raise "Your pull failed. Probably because of a merge conflict!" end @result end |
#push ⇒ Object
64 65 66 67 68 |
# File 'lib/opendelivery/source_control.rb', line 64 def push Dir.chdir(@dir) do `git push` end end |
#remove_missing_files(status) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/opendelivery/source_control.rb', line 41 def remove_missing_files(status) removed_files = [] files = find_removed_files(status) files.each do |file| Dir.chdir(@dir) do removed_files << `git rm -rf #{file}` end end removed_files end |
#status ⇒ Object
35 36 37 38 39 |
# File 'lib/opendelivery/source_control.rb', line 35 def status Dir.chdir(@dir) do `git status -sb` end end |