Created
July 22, 2019 02:30
-
-
Save mad-p/04e58c1076d2a19799e76f10507fc161 to your computer and use it in GitHub Desktop.
Find suitable git clone for repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Find suitable git clone for repositories | |
# Usage: ruby resolve_repos.rb | sh -x | |
dirs = Dir.glob("*") | |
dirs.each do |dir| | |
next unless File.directory?(dir) | |
git_remote = `cd #{dir}; git remote -v 2>&1 | egrep '\\(fetch\\)$|^fatal'` | |
next if /^fatal/ =~ git_remote | |
remotes = {} | |
git_remote.split(/\n/).each do |line| | |
name, url, = line.split | |
remotes[name] = url | |
end | |
if remotes['origin'] | |
mirror = /\.git$/ =~ dir ? "--mirror" : "" | |
puts "git clone #{mirror} #{remotes['origin']} #{dir}" | |
end | |
remotes.each do |k, v| | |
next if k == 'origin' | |
puts "(cd #{dir}; git remote add #{k} #{v})" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment