8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gitmirror/backend/base.rb', line 8
def mirror url, local_repo_path, credential=nil
unless File.exists? local_repo_path
FileUtils.mkdir_p local_repo_path
git({}, "init", "--bare", local_repo_path) git({}, "--git-dir", local_repo_path, "remote", "add", "origin", "--mirror=fetch", url) end
if credential
case url
when /^https:\/\//
u = URI.parse(url)
if u.user
u.password = credential
else
u.user = credential
end
git({}, "--git-dir", local_repo_path, "remote", "set-url", "origin", u.to_s)
git({"GIT_ASKPASS"=> "/bin/echo"}, "--git-dir" ,local_repo_path, "fetch", "origin")
else
Tempfile.open("ssh-key") do |file|
file.write(credential)
file.close
git({"GIT_SSH_COMMAND"=> "ssh -o BatchMode=yes -i #{file.path}"}, "--git-dir" ,local_repo_path, "fetch", "origin")
end
end
else
git({}, "--git-dir" ,local_repo_path, "fetch", "origin")
end
local_repo_path
end
|