Skip to content

Instantly share code, notes, and snippets.

@lokeshjain2008
Created March 4, 2015 10:48
Show Gist options
  • Save lokeshjain2008/8ecad5f8aad77ee5f67f to your computer and use it in GitHub Desktop.
Save lokeshjain2008/8ecad5f8aad77ee5f67f to your computer and use it in GitHub Desktop.
apply patched files to the project
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment