База знаний
Скрипт для переноса пустых папок из SVN в git

Баг: .gitignore заставляет гит игнорировать вложенные категории. Потому надо создавать пустой .gitignore и потом вручную прописывать игнор там, где надо

#!/usr/bin/ruby
#
# script to extract empty dir messages from git-svn log and create the missing directories
# Leonid Shevtsov <leonid@shevtsov.me
#
# TODO parameterize the script
# TODO make it edit revisions instead of just creating directories in the current commit

prefix = 'trunk/' # TODO make this a parameter
branch = 'trunk'  # TODO make this a parameter

dirs = []
`grep empty_dir < .git/svn/#{branch}/unhandled.log`.each do |str|
  matchdata = /(\+|-)empty_dir: #{prefix}(.+)/.match str

  if matchdata[1] == '+'
    dirs <<  matchdata[2]
  else
    dirs.delete matchdata[2]
  end
end

dirs.uniq!

dirs.each do |dir|
  curdir = '.'
  dir.each('/') do |subdir|
    subdir.chomp!('/')
    curdir += '/'+subdir
    next if File.directory? curdir
    if File.file? curdir
      puts "#{curdir}: is a file and cannot be created as a directory" 
    else
      Dir.mkdir curdir
      File.open curdir+'/.gitignore','w' do |f|
        f.write "*\n!.gitignore\n" 
      end
      puts "#{curdir}/.gitignore: created" 
    end
  end
end

puts "Done! Now run git status and check which files need to be kept"