Class: Braid::Operations::GitClone

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/braid/operations.rb

Instance Method Summary collapse

Instance Method Details

#add_gitignore(path) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/braid/operations.rb', line 150

def add_gitignore(path)
  # remove mirror from .gitignore file
  in_rep_root_check
  if File.exists?(".gitignore") 
    f = File.open( '.gitignore', 'r+') 
    path_ignored = nil
    f.each { |line| 
      if line == path+"\n"
        path_ignored = line
      end 
    }
    f.rewind
    f.close
    
    if ! path_ignored
      date_str = Date.new.to_s
      f = File.open( '.gitignore', 'r+') 
      n = File.new(".gitignore-#{date_str}",  "w+")
      f.each { |line| n.puts line }
      n.puts path+"\n"
      n.close            
      f.close
      File.rename( ".gitignore-#{date_str}", ".gitignore" )
      Git.instance.add(".gitignore")
    end
  end        
end

#in_rep_root_checkObject



144
145
146
147
148
# File 'lib/braid/operations.rb', line 144

def in_rep_root_check
  if ! File.exists?(".git") 
    raise("Not in root repository.")
  end        
end

#remove_gitignore(path) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/braid/operations.rb', line 178

def remove_gitignore(path)
  # remove mirror from .gitignore file
  in_rep_root_check
  if File.exists?(".gitignore") 
    f = File.open( '.gitignore', 'r+') 
    path_ignored = nil
    f.each { |line| 
      if line == path+"\n"
        path_ignored = line
      end 
    }
    f.rewind
    f.close

    if path_ignored
      date_str= Date.new.to_s
      f = File.open( '.gitignore', 'r+') 
      n = File.new(".gitignore-#{date_str}",  "w+")
      f.each { |line| 
        n.puts line unless line == path_ignored
      }
      n.close            
      f.close
      File.rename( ".gitignore-#{date_str}", ".gitignore" )
      Git.instance.add(".gitignore")
    end
  end        
end