mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add script to alphabetise submodule list (#4054)
This commit is contained in:
1458
.gitmodules
vendored
1458
.gitmodules
vendored
File diff suppressed because it is too large
Load Diff
@@ -112,4 +112,5 @@ end
|
|||||||
|
|
||||||
log "Updating grammar documentation in vendor/README.md"
|
log "Updating grammar documentation in vendor/README.md"
|
||||||
command('bundle', 'exec', 'rake', 'samples')
|
command('bundle', 'exec', 'rake', 'samples')
|
||||||
|
command('script/sort-submodules')
|
||||||
command('script/list-grammars')
|
command('script/list-grammars')
|
||||||
|
|||||||
50
script/sort-submodules
Executable file
50
script/sort-submodules
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
|
||||||
|
usage = <<-EOH
|
||||||
|
Usage:
|
||||||
|
#{$0} [-t|--test] [-h|--help]
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
#{$0} # Update .gitmodules file in-place
|
||||||
|
#{$0} --help # Display this help message
|
||||||
|
#{$0} --test # Exit with an error code if .gitmodules needs sorting
|
||||||
|
EOH
|
||||||
|
|
||||||
|
$testing = false
|
||||||
|
OptionParser.new do |opts|
|
||||||
|
opts.banner = usage
|
||||||
|
opts.on("-h", "--help") do
|
||||||
|
puts usage
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
opts.on("-t", "--test", "Don't update file; only test if it's unsorted") do
|
||||||
|
$testing = true
|
||||||
|
end
|
||||||
|
end.parse!
|
||||||
|
|
||||||
|
|
||||||
|
unsorted = File.read("#{ROOT}/.gitmodules")
|
||||||
|
sorted = sort_entries(unsorted).join
|
||||||
|
|
||||||
|
if $testing
|
||||||
|
exit unsorted == sorted
|
||||||
|
else
|
||||||
|
File.write "#{ROOT}/.gitmodules", sorted
|
||||||
|
end
|
||||||
@@ -44,6 +44,11 @@ class TestPedantic < Minitest::Test
|
|||||||
assert_sorted tests
|
assert_sorted tests
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_submodules_are_sorted
|
||||||
|
system(File.expand_path("../../script/sort-submodules", __FILE__) + " -t")
|
||||||
|
assert $?.success?
|
||||||
|
end
|
||||||
|
|
||||||
def assert_sorted(list)
|
def assert_sorted(list)
|
||||||
list.each_cons(2) do |previous, item|
|
list.each_cons(2) do |previous, item|
|
||||||
flunk "#{previous} should come after #{item}" if previous > item
|
flunk "#{previous} should come after #{item}" if previous > item
|
||||||
|
|||||||
Reference in New Issue
Block a user