def get_modified_files files_raw = `git status | grep modified` files_raw .gsub(/\n/,"#") .gsub(/[\t\n]/,"") #remove unwanted elements .split('#').reject{|element| element.length < 2} # get each line for the file .map{|file| file.split(":").last.strip } # git the file name end def copy_files_to_project files files.each do |file| %x[ cp #{file} #{file.sub(/localNeeded\//,"")} ] end end if Dir.exist? "localNeeded" current_modifid_files = get_modified_files #Check if some of files have changed by git now include files from the folder then stop else we will loose changes to files. #http://stackoverflow.com/questions/2370702/one-liner-to-recursively-list-directories-in-ruby all_files_in_folder = Dir["localNeeded/**/*"].reject{|file| File.directory? file} #for macthing only files_names_trimmed = all_files_in_folder.map{|name| name.sub /localNeeded\//,""} # !> ambiguous first argument; put parentheses or even spaces need_assistance = files_names_trimmed & current_modifid_files if need_assistance.any? p "Can't procceed as there are changes needed to be taken care of in following files" need_assistance.each do |file| p "- "+file end else copy_files_to_project all_files_in_folder p "Done!!" end else p "There in no folder to add patched files" end