Skip to content

Instantly share code, notes, and snippets.

@kibiz0r
Created February 15, 2013 22:43
Show Gist options
  • Save kibiz0r/4964186 to your computer and use it in GitHub Desktop.
Save kibiz0r/4964186 to your computer and use it in GitHub Desktop.
An SVN script to fix obstructed directories by copying their contents to a temporary directory, restoring the original directory through SVN, and then overlaying the desired contents.
#!/usr/bin/env ruby
require 'fileutils'
require 'tmpdir'
def ignored?(entry)
['.', '..', '.svn'].include? entry
end
def replicate_dir_contents(old_dir, new_dir)
unless File.directory? new_dir
Dir.mkdir new_dir
end
Dir.entries(old_dir).each do |entry|
next if ignored? entry
from = "#{old_dir}/#{entry}"
to = "#{new_dir}/#{entry}"
if File.directory? from
replicate_dir_contents from, to
else
FileUtils.cp from, to
end
end
Dir.entries(new_dir).each do |entry|
next if ignored? entry
from = "#{old_dir}/#{entry}"
to = "#{new_dir}/#{entry}"
unless File.exists? from
FileUtils.rm_rf to
end
end
end
obstructed_dirs = `svn st`.lines.map do |line|
if line =~ /^~\s*(\S*)/
$1
end
end.compact
obstructed_dirs.each do |dir|
Dir.mktmpdir do |tmpdir|
replicate_dir_contents dir, tmpdir
FileUtils.rm_rf dir
system "svn up #{dir}"
replicate_dir_contents tmpdir, dir
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment