1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Fix a bug with the script not detecting non-empty

directories properly. It was looking for a relative path,
but the base path would change across invocations of clone_submodules().
This commit is contained in:
King_DuckZ 2016-07-15 16:55:06 +01:00
parent 29c71c9222
commit 2467f2f12d
2 changed files with 28 additions and 9 deletions

2
.gitmodules vendored
View file

@ -9,7 +9,7 @@
url = https://github.com/aantron/better-enums url = https://github.com/aantron/better-enums
[submodule "lib/duckhandy"] [submodule "lib/duckhandy"]
path = lib/duckhandy path = lib/duckhandy
url = https://github.com/KingDuckZ/duckhandy.git url = ../duckhandy.git
[submodule "lib/incredis"] [submodule "lib/incredis"]
path = lib/incredis path = lib/incredis
url = ../incredis.git url = ../incredis.git

View file

@ -30,6 +30,7 @@ For more information, please refer to <http://unlicense.org/>
require 'shellwords' require 'shellwords'
require 'pathname' require 'pathname'
require 'yaml' require 'yaml'
require 'uri'
GIT="git" GIT="git"
@ -55,6 +56,7 @@ def call_git(parTokens, parCaptureStdout=true, work_dir: nil)
raise ScriptError, "Invalid parTokens received in call_git() function" raise ScriptError, "Invalid parTokens received in call_git() function"
end end
#puts "#{GIT}#{git_c_param} #{command_line}"
if parCaptureStdout then if parCaptureStdout then
return `#{GIT}#{git_c_param} #{command_line}`.chomp return `#{GIT}#{git_c_param} #{command_line}`.chomp
else else
@ -79,6 +81,16 @@ def current_remote_url()
return remote_url return remote_url
end end
def make_git_address(parBaseRemoteUrl, parSuffix)
regex_protocol = /^\w+:\/\//
m = regex_protocol.match(parBaseRemoteUrl)
if m then
URI.join(parBaseRemoteUrl + "/", parSuffix).to_s
else
Pathname.new(File.join(parBaseRemoteUrl, parSuffix)).cleanpath.to_s
end
end
def submodules_info(parBaseRemoteUrl) def submodules_info(parBaseRemoteUrl)
regex_submodule = /^submodule\.(.+?)\.([^.]+)$/ regex_submodule = /^submodule\.(.+?)\.([^.]+)$/
submodules = Hash.new{ |hash, key| hash[key] = SubmoduleInfo.new } submodules = Hash.new{ |hash, key| hash[key] = SubmoduleInfo.new }
@ -89,7 +101,7 @@ def submodules_info(parBaseRemoteUrl)
new_value = call_git(["config", "--file", ".gitmodules", sanitized(line)]) new_value = call_git(["config", "--file", ".gitmodules", sanitized(line)])
case m[2] case m[2]
when "url" then when "url" then
submodules[m[1]].url = is_absolute_url?(new_value) ? new_value : File.join(parBaseRemoteUrl, new_value) submodules[m[1]].url = is_absolute_url?(new_value) ? new_value : make_git_address(parBaseRemoteUrl, new_value)
submodules[m[1]].name = File.basename(new_value, ".git") submodules[m[1]].name = File.basename(new_value, ".git")
when "path" then when "path" then
submodules[m[1]].path = new_value submodules[m[1]].path = new_value
@ -123,7 +135,6 @@ class FlatGit
end end
@clone_dir_abs = Pathname.new(parCloneDir).realpath @clone_dir_abs = Pathname.new(parCloneDir).realpath
@clone_dir = parCloneDir
end end
def clone_submodules() def clone_submodules()
@ -139,13 +150,12 @@ class FlatGit
submodules_info(current_remote_url()).each_value do |submod| submodules_info(current_remote_url()).each_value do |submod|
next unless submod.status == "-" next unless submod.status == "-"
guessed_clone_dir = File.join(@clone_dir, submod.name)
abs_guessed_clone_dir = File.join(@clone_dir_abs, submod.name) abs_guessed_clone_dir = File.join(@clone_dir_abs, submod.name)
if inplace_submodules.include?(submod.name) then if inplace_submodules.include?(submod.name) then
success = call_git(["submodule", "update", "--init", sanitized(submod.path)], false) success = call_git(["submodule", "update", "--init", sanitized(submod.path)], false)
return false unless success return false unless success
else else
if !File.exists?(guessed_clone_dir) || Dir.entries(guessed_clone_dir).empty? then if !File.exists?(abs_guessed_clone_dir) || (File.directory?(abs_guessed_clone_dir) && Dir.entries(abs_guessed_clone_dir).empty?) then
success = call_git(["clone", sanitized(submod.url)], false, work_dir: sanitized(@clone_dir_abs)) success = call_git(["clone", sanitized(submod.url)], false, work_dir: sanitized(@clone_dir_abs))
return false unless success return false unless success
@ -171,9 +181,18 @@ class FlatGit
end end
end end
def main(parArgv)
unless ARGV.length == 1 then unless ARGV.length == 1 then
$stderr.puts "Wrong number of arguments" $stderr.puts "Wrong number of arguments"
exit 2 exit 2
end end
exit(FlatGit.new(ARGV[0]).clone_submodules() ? 1 : 0) flat_git = FlatGit.new(ARGV[0])
if flat_git.clone_submodules() then
return 0
else
return 1
end
end
exit(main(ARGV))