gitmirror 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/gitmirror.gemspec +1 -1
- data/lib/gitmirror/backend/base.rb +52 -0
- data/lib/gitmirror/backend/fork.rb +8 -26
- data/lib/gitmirror/backend/posix_spawn.rb +12 -4
- data/lib/gitmirror/repository.rb +2 -2
- data/lib/gitmirror/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ab530356b5440830facb43192ec2bdf2badc5d4867331bc280813081082ed66
|
4
|
+
data.tar.gz: eaed552df232e6eac6377a2d57573204da8f05b2c63894b49d132de679dd60ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0acc9ed869cb2f0fe0e42bb8e5e19c451159e4394c9bdbb2416c733965ab03b206ca62cf9508bc34791d1b5c52745039c870d6504c536b10f6457c496093c47
|
7
|
+
data.tar.gz: 7a9ed819dabeceac569ad99f4174262372b21e200795a237ce9996f11fbe1a88c9088ac9c01f02515a503300285b0d5df77994ae237cd9116e8c120abc994749
|
data/gitmirror.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
-
spec.add_development_dependency "rake", "
|
22
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.0"
|
24
24
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'fileutils'
|
4
|
+
module Gitmirror
|
5
|
+
module Backend
|
6
|
+
class Base
|
7
|
+
|
8
|
+
def mirror url, local_repo_path, credential=nil
|
9
|
+
|
10
|
+
#init bare repository
|
11
|
+
unless File.exists? local_repo_path
|
12
|
+
FileUtils.mkdir_p local_repo_path
|
13
|
+
git({}, "init", "--bare", local_repo_path) #idempotent, does not harm existing repos
|
14
|
+
git({}, "--git-dir", local_repo_path, "remote", "add", "origin", "--mirror=fetch", url) #raises an error
|
15
|
+
end
|
16
|
+
#fetch updates
|
17
|
+
if credential
|
18
|
+
case url
|
19
|
+
when /^https:\/\//
|
20
|
+
u = URI.parse(url)
|
21
|
+
if u.user
|
22
|
+
u.password = credential
|
23
|
+
else
|
24
|
+
u.user = credential
|
25
|
+
end
|
26
|
+
git({}, "--git-dir", local_repo_path, "remote", "set-url", "origin", u.to_s)
|
27
|
+
git({"GIT_ASKPASS"=> "/bin/echo"}, "--git-dir" ,local_repo_path, "fetch", "origin")
|
28
|
+
else
|
29
|
+
#assuming ssh protocol
|
30
|
+
Tempfile.open("ssh-key") do |file|
|
31
|
+
file.write(credential)
|
32
|
+
file.close
|
33
|
+
git({"GIT_SSH_COMMAND"=> "ssh -o BatchMode=yes -i #{file.path}"}, "--git-dir" ,local_repo_path, "fetch", "origin")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
# no auth, no problems
|
38
|
+
git({}, "--git-dir" ,local_repo_path, "fetch", "origin")
|
39
|
+
end
|
40
|
+
local_repo_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def checkout repo_path, workdir, rev
|
44
|
+
#checkout workdir
|
45
|
+
FileUtils.mkdir_p workdir
|
46
|
+
git({}, "--git-dir", repo_path, "--work-tree", workdir, "checkout", "-f", rev)
|
47
|
+
git({}, "--git-dir", repo_path, "rev-parse", rev).rstrip
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,35 +1,17 @@
|
|
1
|
+
require 'gitmirror/backend/base'
|
2
|
+
require 'open3'
|
1
3
|
module Gitmirror
|
2
4
|
module Backend
|
3
|
-
class Fork
|
5
|
+
class Fork <Base
|
4
6
|
include Gitmirror::Log
|
5
7
|
|
6
|
-
def mirror url, local_repo_path
|
7
|
-
#init bare repository
|
8
|
-
unless File.exists? local_repo_path
|
9
|
-
FileUtils.mkdir_p local_repo_path
|
10
|
-
git "init --bare #{local_repo_path}" #idempotent, does not harm existing repos
|
11
|
-
git "--git-dir=#{local_repo_path} remote add origin --mirror=fetch #{url}" #raises an error
|
12
|
-
end
|
13
|
-
#fetch updates
|
14
|
-
git "--git-dir=#{local_repo_path} fetch origin"
|
15
|
-
local_repo_path
|
16
|
-
end
|
17
|
-
|
18
|
-
def checkout repo_path, workdir, rev
|
19
|
-
#checkout workdir
|
20
|
-
FileUtils.mkdir_p workdir
|
21
|
-
git "--git-dir=#{repo_path} --work-tree #{workdir} checkout -f #{rev}"
|
22
|
-
git("--git-dir=#{repo_path} rev-parse #{rev}").rstrip
|
23
|
-
end
|
24
|
-
|
25
8
|
private
|
26
9
|
|
27
|
-
def git
|
28
|
-
command=
|
29
|
-
log.debug
|
30
|
-
|
31
|
-
|
32
|
-
raise GitError, "Executing [#{command}] failed: #{out}" if $?.exitstatus != 0
|
10
|
+
def git env, *args
|
11
|
+
command = ['git'].concat args
|
12
|
+
log.debug %{Executing #{env.map{|k,v| "#{k}=#{v}"}.join(" ")} #{command}}
|
13
|
+
out, status = Open3.capture2e(env, "git", *args)
|
14
|
+
raise GitError, "Executing [#{command}] failed: #{out}" if status.exitstatus != 0
|
33
15
|
out
|
34
16
|
end
|
35
17
|
|
@@ -1,10 +1,18 @@
|
|
1
|
-
require 'gitmirror/backend/
|
1
|
+
require 'gitmirror/backend/base'
|
2
2
|
require 'posix-spawn'
|
3
3
|
module Gitmirror
|
4
4
|
module Backend
|
5
|
-
class PosixSpawn <
|
6
|
-
|
7
|
-
|
5
|
+
class PosixSpawn < Base
|
6
|
+
include Gitmirror::Log
|
7
|
+
private
|
8
|
+
|
9
|
+
def git env, *args
|
10
|
+
command = ['git'].concat args
|
11
|
+
log.debug %{Executing #{env.map{|k,v| "#{k}=#{v}"}.join(" ")} #{command}}
|
12
|
+
child = POSIX::Spawn::Child.new(env, "git", *args)
|
13
|
+
raise GitError, "Executing [#{command.join(' ')}] failed: #{child.err} #{child.out}" if child.status.exitstatus != 0
|
14
|
+
child.err+child.out
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
10
18
|
end
|
data/lib/gitmirror/repository.rb
CHANGED
data/lib/gitmirror/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitmirror
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabian Ruff
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- exe/gitmirror
|
73
73
|
- gitmirror.gemspec
|
74
74
|
- lib/gitmirror.rb
|
75
|
+
- lib/gitmirror/backend/base.rb
|
75
76
|
- lib/gitmirror/backend/fork.rb
|
76
77
|
- lib/gitmirror/backend/posix_spawn.rb
|
77
78
|
- lib/gitmirror/log.rb
|
@@ -95,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
96
|
- !ruby/object:Gem::Version
|
96
97
|
version: '0'
|
97
98
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.5.2.3
|
99
|
+
rubygems_version: 3.0.3
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: gitmirror maintains mirrors of git repositories on the local system using
|