Commit in-progress work to request sanity check

This commit is contained in:
Alhadis
2018-04-13 22:54:18 +10:00
parent f34c741c29
commit 6669270e84
9 changed files with 458 additions and 245 deletions

View File

@@ -1,21 +1,7 @@
#!/usr/bin/env ruby
require "optparse"
ROOT = File.expand_path "../../", __FILE__
# Extract and sort a list of submodules
def sort_entries(file_data)
submodules = []
file_data.scan(/(^\[submodule[^\n]+\n)((?:\t[^\n]+\n)+)/).each do |head, body|
path = body.match(/^\tpath\s*=\s*\K(.+)$/)[0]
submodules << [path, head + body]
end
submodules.sort! { |a,b| a[0] <=> b[0] }
submodules.collect { |i| i[1] }
end
require_relative "./helpers/submodule"
usage = <<-EOH
Usage:
@@ -28,6 +14,7 @@ Examples:
EOH
$testing = false
OptionParser.new do |opts|
opts.banner = usage
opts.on("-h", "--help") do
@@ -39,12 +26,11 @@ OptionParser.new do |opts|
end
end.parse!
unsorted = File.read("#{ROOT}/.gitmodules")
sorted = sort_entries(unsorted).join
unsorted = read ".gitmodules"
sorted = Submodule.list.join
if $testing
exit unsorted == sorted
else
File.write "#{ROOT}/.gitmodules", sorted
write ".gitmodules", sorted
end