-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Optional explicit directory names (#3)
for handling repo name collisions (e.g org1/repo-name vs org2/repo-name) See also: discourse/all-the-themes#45
- Loading branch information
Showing
1 changed file
with
23 additions
and
17 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,7 @@ def prefixed_puts(str) | |
# Clone or update a repo with the given URL | ||
# On failure, return the repo url | ||
# On success, return nil | ||
def update_repo(repo_url) | ||
dir_name = File.basename(repo_url, ".git") | ||
def update_repo(repo_url, dir_name) | ||
if Dir.exist?(dir_name) | ||
prefixed_puts "Updating #{dir_name}..." | ||
|
||
|
@@ -70,35 +69,42 @@ def self.mass_clone(repo_base_dir:, repo_list:) | |
false | ||
end | ||
|
||
all_repos = repo_list.map(&:strip).filter { |l| l.length > 0 } | ||
if all_repos.size === 0 | ||
prefixed_puts "No plugin URLs supplied" | ||
all_entries = repo_list.map(&:strip).filter { |l| l.length > 0 } | ||
if all_entries.size === 0 | ||
prefixed_puts "No git repository URLs supplied" | ||
exit 1 | ||
end | ||
|
||
all_repos = | ||
all_repos.map do |repo| | ||
if !repo.match?(%r{\A[\w-]+/[\w-]+\z}) | ||
repo # Full URL, leave untouched | ||
elsif use_ssh | ||
"[email protected]:#{repo}" | ||
else | ||
"https://github.com/#{repo}" | ||
end | ||
all_entries = | ||
all_entries.map do |entry| | ||
repo, dir_name = entry.split(" ") | ||
|
||
repo_url = | ||
if !repo.match?(%r{\A[\w-]+/[\w-]+\z}) | ||
repo # Full URL, leave untouched | ||
elsif use_ssh | ||
"[email protected]:#{repo}" | ||
else | ||
"https://github.com/#{repo}" | ||
end | ||
|
||
dir_name ||= File.basename(repo_url, ".git") | ||
|
||
[repo_url, dir_name] | ||
end | ||
|
||
Dir.mkdir(repo_base_dir) if !Dir.exist?(repo_base_dir) | ||
|
||
Dir.chdir(repo_base_dir) do | ||
failures = | ||
Parallel | ||
.map(all_repos, in_threads: ENV["PARALLEL"]&.to_i || 10) do |repo_url| | ||
update_repo(repo_url) | ||
.map(all_entries, in_threads: ENV["PARALLEL"]&.to_i || 10) do |repo_url, dir_name| | ||
update_repo(repo_url, dir_name) | ||
end | ||
.reject(&:nil?) | ||
|
||
final_dirs = Dir.glob("*") | ||
expected_dirs = Set.new(all_repos.map { |r| File.basename(r, ".git") }) | ||
expected_dirs = Set.new(all_entries.map { |_, dir_name| dir_name }) | ||
to_delete = final_dirs.reject { |dir| expected_dirs.include?(dir) } | ||
|
||
if to_delete.any? | ||
|