Skip to content

Instantly share code, notes, and snippets.

@maltoe
Created May 26, 2013 16:23
Show Gist options
  • Save maltoe/5653245 to your computer and use it in GitHub Desktop.
Save maltoe/5653245 to your computer and use it in GitHub Desktop.
git submodule loop :(
require 'fileutils'
FileUtils.mkdir_p('test')
Dir.chdir('test') do
['1', '2'].each do |i|
FileUtils.mkdir_p(i)
Dir.chdir(i) do
`git init`
`touch repo_#{i} && git add repo_#{i} && git commit -m 'initial commit'`
end
end
Dir.chdir('1') { `git submodule add ../2 to_2 && git submodule init && git add to_2 .gitmodules && git commit -m 'add submodule'` }
Dir.chdir('2') { `git submodule add ../1 to_1 && git submodule init && git add to_1 .gitmodules && git commit -m 'add submodule'` }
Dir.chdir('1') do
Dir.chdir('to_2') { `git pull` }
`git add to_2 && git commit -m 'update submodule'`
end
Dir.chdir('2') do
Dir.chdir('to_1') { `git pull` }
`git add to_1 && git commit -m 'update submodule'`
end
FileUtils.mkdir_p('3')
Dir.chdir('3') do
`git init`
`git submodule add ../1 to_1 && git submodule update --init --recursive`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment