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.
3 4 5 |
# File 'lib/opendelivery/source_control.rb', line 3 def initialize(dir) @dir = dir end |
Instance Method Details
#add(files) ⇒ Object
30 31 32 33 34 |
# File 'lib/opendelivery/source_control.rb', line 30 def add(files) Dir.chdir(@dir) do `git add #{files} -v` end end |
#commit(message) ⇒ Object
36 37 38 39 40 |
# File 'lib/opendelivery/source_control.rb', line 36 def commit() Dir.chdir(@dir) do `git commit -m "#{message}"` end end |
#conflicted(status) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/opendelivery/source_control.rb', line 58 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
7 8 9 10 11 |
# File 'lib/opendelivery/source_control.rb', line 7 def log(lines=10) Dir.chdir(@dir) do `git log --stat -n #{lines}` end end |
#pull ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/opendelivery/source_control.rb', line 48 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
42 43 44 45 46 |
# File 'lib/opendelivery/source_control.rb', line 42 def push Dir.chdir(@dir) do `git push` end end |
#remove_missing_files(status) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/opendelivery/source_control.rb', line 19 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
13 14 15 16 17 |
# File 'lib/opendelivery/source_control.rb', line 13 def status Dir.chdir(@dir) do `git status -sb` end end |