mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Store and revert changes made to vendor/README.md
This commit is contained in:
		| @@ -47,10 +47,9 @@ def command(*args) | |||||||
|   log "$ #{args.join(' ')}" |   log "$ #{args.join(' ')}" | ||||||
|   output, status = Open3.capture2e(*args) |   output, status = Open3.capture2e(*args) | ||||||
|   if !status.success? |   if !status.success? | ||||||
|     output.each_line do |line| |     warn "Command failed. Aborting." | ||||||
|       log "  > #{line}" |     error.output = output.each_line { |line| "  > #{line}" } | ||||||
|     end |     raise { output: output, status: status } | ||||||
|     raise "Command failed. Aborting." |  | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -65,7 +64,6 @@ EOH | |||||||
|  |  | ||||||
| $replace = nil | $replace = nil | ||||||
| $verbose = true | $verbose = true | ||||||
| $compile = false |  | ||||||
|  |  | ||||||
| OptionParser.new do |opts| | OptionParser.new do |opts| | ||||||
|   opts.banner = usage |   opts.banner = usage | ||||||
| @@ -75,9 +73,6 @@ OptionParser.new do |opts| | |||||||
|   opts.on("-rSUBMODULE", "--replace=SUBMODDULE", "Replace an existing grammar submodule.") do |name| |   opts.on("-rSUBMODULE", "--replace=SUBMODDULE", "Replace an existing grammar submodule.") do |name| | ||||||
|     $replace = name |     $replace = name | ||||||
|   end |   end | ||||||
|   opts.on("-C", "--compile", "Compile grammar using the new grammar-compiler.") do |  | ||||||
|     $compile = true |  | ||||||
|   end |  | ||||||
| end.parse! | end.parse! | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -90,14 +85,13 @@ unless $url | |||||||
| end | end | ||||||
|  |  | ||||||
| # Flags to track which changes should be reverted on an error | # Flags to track which changes should be reverted on an error | ||||||
| did_remove? = false | $gitmodules  = File.read("#{ROOT}/.gitmodules") | ||||||
| did_add?    = false | $git_config  = File.read("#{ROOT}/.git/config") | ||||||
| gitmodules  = File.read("#{ROOT}/.gitmodules") | $vendor_list = File.read("#{ROOT}/vendor/README.md") | ||||||
| git_config  = File.read("#{ROOT}/.git/config") |  | ||||||
|  |  | ||||||
| def restore_configs | def restore_configs | ||||||
|   File.write("#{ROOT}/.gitmodules", gitmodules) |   File.write("#{ROOT}/.gitmodules", $gitmodules) | ||||||
|   File.write("#{ROOT}/.git/config", git_config) |   File.write("#{ROOT}/.git/config", $git_config) | ||||||
| end | end | ||||||
|  |  | ||||||
| begin | begin | ||||||
| @@ -115,14 +109,12 @@ begin | |||||||
|  |  | ||||||
|   if repo_old |   if repo_old | ||||||
|     log "Deregistering: #{repo_old}" |     log "Deregistering: #{repo_old}" | ||||||
|     removed = repo_old |  | ||||||
|     command('git', 'submodule', 'deinit', repo_old) |     command('git', 'submodule', 'deinit', repo_old) | ||||||
|     command('git', 'rm', '-rf', repo_old) |     command('git', 'rm', '-rf', repo_old) | ||||||
|     command('script/grammar-compiler', 'update', '-f') |     command('script/grammar-compiler', 'update', '-f') | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   log "Registering new submodule: #{repo_new}" |   log "Registering new submodule: #{repo_new}" | ||||||
|   added = repo_new |  | ||||||
|   command('git', 'submodule', 'add', '-f', https, repo_new) |   command('git', 'submodule', 'add', '-f', https, repo_new) | ||||||
|   command('script/grammar-compiler', 'add', repo_new) |   command('script/grammar-compiler', 'add', repo_new) | ||||||
|  |  | ||||||
| @@ -138,19 +130,17 @@ begin | |||||||
|   command('script/sort-submodules') |   command('script/sort-submodules') | ||||||
|   command('script/list-grammars') |   command('script/list-grammars') | ||||||
| rescue => ex | rescue => ex | ||||||
|   if did_add? |   if repo_new | ||||||
|     `git submodule deinit #{repo_new}` |     `git submodule deinit #{repo_new}` | ||||||
|     `rm -rf #{repo_new}` |     `rm -rf #{repo_new}` | ||||||
|     `rm -rf .git/modules/#{repo_new}/` |     `rm -rf .git/modules/#{repo_new}/` | ||||||
|   end |  | ||||||
|   restore_configs() |  | ||||||
|   if did_remove? |  | ||||||
|     `rm -rf #{repo_old}` |  | ||||||
|     `git submodule add -f "#{https}", "#{repo_old}"` |  | ||||||
|      |  | ||||||
|     # Revert twice. Make no assumpsions about |  | ||||||
|     # badly-mangled the working tree is. |  | ||||||
|     restore_configs() |     restore_configs() | ||||||
|   end |   end | ||||||
|  |   if repo_old | ||||||
|  |     `rm -rf #{repo_old}` | ||||||
|  |     `git submodule add -f "#{https}", "#{repo_old}"` | ||||||
|  |     restore_configs() | ||||||
|  |   end | ||||||
|  |   File.write("#{ROOT}/vendor/README.md", $vendor_list) | ||||||
|   exit 1 |   exit 1 | ||||||
| end | end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user