git-svn-mirror 0.1
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.
- data/LICENSE +4 -0
- data/README.md +98 -0
- data/TODO +2 -0
- data/bin/git-svn-mirror +5 -0
- data/git-svn-mirror.gemspec +46 -0
- data/lib/git-svn-mirror.rb +147 -0
- metadata +73 -0
data/LICENSE
ADDED
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
git-svn-mirror
|
2
|
+
--------------
|
3
|
+
|
4
|
+
A command-line tool that automates the task of creating a GIT mirror for a SVN
|
5
|
+
repo, and keeping it up-to-date.
|
6
|
+
|
7
|
+
Install
|
8
|
+
-------
|
9
|
+
|
10
|
+
This tool is packaged as a Ruby Gem, install it by running the following:
|
11
|
+
|
12
|
+
$ gem install git-svn-mirror
|
13
|
+
|
14
|
+
Configure the ‘workbench’
|
15
|
+
-------------------------
|
16
|
+
|
17
|
+
To mirror a SVN repo, first the local ‘workbench’ repo has to be configured.
|
18
|
+
This ‘workbench’ is the GIT repo where the SVN revisions will be stored and
|
19
|
+
from where these revisions will be pushed to the remote mirror GIT repo.
|
20
|
+
|
21
|
+
Start by creating the directory:
|
22
|
+
|
23
|
+
$ mkdir -p /path/to/workbench
|
24
|
+
|
25
|
+
Then initialize the ‘workbench’:
|
26
|
+
|
27
|
+
$ cd /path/to/workbench
|
28
|
+
$ git-svn-mirror init --from=http://svn-host/repo_root --to=git@git-host:user/mirror.git
|
29
|
+
|
30
|
+
This will create a ‘bare’ GIT repo, configure the SVN and GIT remotes, fetch
|
31
|
+
the revisions from the SVN remote, and compact the ‘workbench’ by running the
|
32
|
+
GIT garbage collector.
|
33
|
+
|
34
|
+
It can often be handy to supply an authors file, with the <tt>--authors-file</tt>
|
35
|
+
option, which is used to migrate user names to GIT names and email addresses.
|
36
|
+
The entries in this file should look like:
|
37
|
+
|
38
|
+
svn-user-name = User Name <user@example.com>
|
39
|
+
|
40
|
+
Update mirror
|
41
|
+
-------------
|
42
|
+
|
43
|
+
To push the latest changes from the SVN repo to the GIT repo, run the following
|
44
|
+
command from the ‘workbench’ repo:
|
45
|
+
|
46
|
+
$ git-svn-mirror update
|
47
|
+
|
48
|
+
Or by specifying the path(s) to one or more ‘workbench’ repos:
|
49
|
+
|
50
|
+
$ git-svn-mirror update /path/to/workbench1 /path/to/workbench2
|
51
|
+
|
52
|
+
You will probably normally not want to perform this step by hand. You can solve
|
53
|
+
this by adding this command as a cron job, in which case you can silence the
|
54
|
+
tool with the <tt>--silent</tt> option.
|
55
|
+
|
56
|
+
‘init’ help banner
|
57
|
+
----------------
|
58
|
+
|
59
|
+
Usage: git-svn-mirror init [mandatory options] [options]
|
60
|
+
|
61
|
+
Mandatory options are --from and --to.
|
62
|
+
|
63
|
+
--from URI The location of the SVN repository that is to be mirrored.
|
64
|
+
--to URI The location of the GIT repository that is the mirror.
|
65
|
+
--workbench PATH The location of the workbench repository. Defaults to the current work dir.
|
66
|
+
--authors-file PATH An optional authors file used to migrate SVN usernames to GIT's format.
|
67
|
+
-s, --silent Silent mode.
|
68
|
+
|
69
|
+
‘update’ help banner
|
70
|
+
--------------------
|
71
|
+
|
72
|
+
Usage: git-svn-mirror update [options] [workbench1] [workbench2] ...
|
73
|
+
|
74
|
+
Defaults to the current work dir if none is given.
|
75
|
+
|
76
|
+
-s, --silent Silent mode.
|
77
|
+
|
78
|
+
Contributing
|
79
|
+
------------
|
80
|
+
|
81
|
+
Once you've made your great commits:
|
82
|
+
|
83
|
+
1. [Fork][fk] git-svn-mirror
|
84
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
85
|
+
3. Push to your branch - `git push origin my_branch`
|
86
|
+
4. Create an [Issue][is] with a link to your branch
|
87
|
+
5. That’s it!
|
88
|
+
|
89
|
+
License In Three Lines (LITL)
|
90
|
+
-----------------------------
|
91
|
+
|
92
|
+
© Eloy Duran <eloy.de.enige@gmail.com>
|
93
|
+
You may use these works, ‘as is’, for anything.
|
94
|
+
If you include this plus copyright notice.
|
95
|
+
But without warranty.
|
96
|
+
|
97
|
+
[fk]: http://help.github.com/forking/
|
98
|
+
[is]: http://github.com/alloy/git-svn-mirror/issues
|
data/TODO
ADDED
data/bin/git-svn-mirror
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{git-svn-mirror}
|
8
|
+
s.version = "0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Eloy Duran"]
|
12
|
+
s.date = %q{2010-10-11}
|
13
|
+
s.default_executable = %q{git-svn-mirror}
|
14
|
+
s.description = %q{A command-line tool that automates the task of creating a GIT mirror for a SVN repo, and keeping it up-to-date.}
|
15
|
+
s.email = %q{eloy.de.enige@gmail.com}
|
16
|
+
s.executables = ["git-svn-mirror"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.md",
|
20
|
+
"TODO"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
"LICENSE",
|
24
|
+
"README.md",
|
25
|
+
"TODO",
|
26
|
+
"bin/git-svn-mirror",
|
27
|
+
"git-svn-mirror.gemspec",
|
28
|
+
"lib/git-svn-mirror.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/alloy/git-svn-mirror}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{A command-line tool that automates the task of creating a GIT mirror for a SVN repo, and keeping it up-to-date.}
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
|
+
else
|
42
|
+
end
|
43
|
+
else
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class GitSVNMirror
|
4
|
+
VERSION = "0.1"
|
5
|
+
|
6
|
+
attr_accessor :from, :to, :workbench, :authors_file, :silent
|
7
|
+
|
8
|
+
def self.run(argv)
|
9
|
+
mirror = new
|
10
|
+
status = case argv.shift
|
11
|
+
when 'init' then init(mirror, argv)
|
12
|
+
when 'update' then update(mirror, argv)
|
13
|
+
else
|
14
|
+
puts "Usage: git-svn-mirror [init|update]"
|
15
|
+
false
|
16
|
+
end
|
17
|
+
[mirror, status]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.option_parser(mirror, argv)
|
21
|
+
opts = OptionParser.new do |o|
|
22
|
+
yield(o)
|
23
|
+
o.on('-s', '--silent', 'Silent mode.') { mirror.silent = true }
|
24
|
+
o.on('-v', '--version', 'Print the version.') { puts VERSION; exit }
|
25
|
+
end
|
26
|
+
opts.parse!(argv)
|
27
|
+
opts
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.init(mirror, argv)
|
31
|
+
opts = option_parser(mirror, argv) do |o|
|
32
|
+
o.banner = "Usage: git-svn-mirror init [mandatory options] [options]"
|
33
|
+
o.separator "\n Mandatory options are --from and --to.\n\n"
|
34
|
+
o.on('--from URI', 'The location of the SVN repository that is to be mirrored.') { |uri| mirror.from = uri }
|
35
|
+
o.on('--to URI', 'The location of the GIT repository that is the mirror.') { |uri| mirror.to = uri }
|
36
|
+
o.on('--workbench PATH', 'The location of the workbench repository. Defaults to the current work dir.') { |wb| mirror.workbench = wb }
|
37
|
+
o.on('--authors-file PATH', 'An optional authors file used to migrate SVN usernames to GIT\'s format.') { |af| mirror.authors_file = af }
|
38
|
+
end
|
39
|
+
|
40
|
+
if mirror.from && mirror.to
|
41
|
+
if !File.exist?(mirror.workbench)
|
42
|
+
puts "[!] Given workbench path does not exist."
|
43
|
+
false
|
44
|
+
else
|
45
|
+
if mirror.authors_file && !File.exist?(mirror.authors_file)
|
46
|
+
puts "[!] Given authors file does not exist."
|
47
|
+
false
|
48
|
+
else
|
49
|
+
mirror.init
|
50
|
+
true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
else
|
54
|
+
puts opts
|
55
|
+
false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.update(mirror, argv)
|
60
|
+
opts = option_parser(mirror, argv) do |o|
|
61
|
+
o.banner = "Usage: git-svn-mirror update [options] [workbench1] [workbench2] ..."
|
62
|
+
o.separator "\n Defaults to the current work dir if none is given.\n\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
if argv.empty?
|
66
|
+
mirror.update
|
67
|
+
else
|
68
|
+
argv.each do |workbench|
|
69
|
+
mirror.workbench = workbench
|
70
|
+
mirror.update
|
71
|
+
end
|
72
|
+
end
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
def init
|
77
|
+
log "* Configuring mirror workbench at `#{workbench}'"
|
78
|
+
sh "git init --bare"
|
79
|
+
|
80
|
+
sh "git svn init --stdlayout --prefix=svn/ #{from}"
|
81
|
+
sh "git config --add svn.authorsfile '#{authors_file}'" if authors_file
|
82
|
+
|
83
|
+
sh "git remote add origin #{to}"
|
84
|
+
sh "git config --add remote.origin.push 'refs/remotes/svn/*:refs/heads/*'"
|
85
|
+
|
86
|
+
fetch
|
87
|
+
log "* Running garbage collection"
|
88
|
+
sh "git gc"
|
89
|
+
|
90
|
+
log "The mirror workbench has been configured. To push to the remote GIT repo,",
|
91
|
+
"and possibly as a cron job, run the following command:",
|
92
|
+
"",
|
93
|
+
" $ git-svn-mirror update '#{workbench}'"
|
94
|
+
end
|
95
|
+
|
96
|
+
def update
|
97
|
+
fetch
|
98
|
+
push
|
99
|
+
end
|
100
|
+
|
101
|
+
def fetch
|
102
|
+
log "* Fetching from SVN repo at `#{from}'"
|
103
|
+
sh "git svn fetch"
|
104
|
+
end
|
105
|
+
|
106
|
+
def push
|
107
|
+
log "* Pushing to GIT repo at `#{to}'"
|
108
|
+
sh "git push origin"
|
109
|
+
end
|
110
|
+
|
111
|
+
def from
|
112
|
+
@from ||= config("svn-remote.svn.url")
|
113
|
+
end
|
114
|
+
|
115
|
+
def to
|
116
|
+
@to ||= config("remote.origin.url")
|
117
|
+
end
|
118
|
+
|
119
|
+
def workbench=(path)
|
120
|
+
@workbench = File.expand_path(path)
|
121
|
+
end
|
122
|
+
|
123
|
+
def workbench
|
124
|
+
@workbench ||= Dir.pwd
|
125
|
+
end
|
126
|
+
|
127
|
+
def authors_file=(path)
|
128
|
+
@authors_file = File.expand_path(path)
|
129
|
+
end
|
130
|
+
|
131
|
+
def log(*str)
|
132
|
+
puts("\n#{str.join("\n")}\n\n") unless @silent
|
133
|
+
end
|
134
|
+
|
135
|
+
def config(key)
|
136
|
+
value = sh("git config --get #{key}", true)
|
137
|
+
value unless value.empty?
|
138
|
+
end
|
139
|
+
|
140
|
+
def sh(command, capture = false)
|
141
|
+
Dir.chdir(workbench) do
|
142
|
+
command = "env GIT_DIR='#{workbench}' #{command}"
|
143
|
+
command += (@silent ? " > /dev/null 2>&1" : " 1>&2") unless capture
|
144
|
+
`#{command}`.strip
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-svn-mirror
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Eloy Duran
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-11 00:00:00 +02:00
|
18
|
+
default_executable: git-svn-mirror
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A command-line tool that automates the task of creating a GIT mirror for a SVN repo, and keeping it up-to-date.
|
22
|
+
email: eloy.de.enige@gmail.com
|
23
|
+
executables:
|
24
|
+
- git-svn-mirror
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.md
|
30
|
+
- TODO
|
31
|
+
files:
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
34
|
+
- TODO
|
35
|
+
- bin/git-svn-mirror
|
36
|
+
- git-svn-mirror.gemspec
|
37
|
+
- lib/git-svn-mirror.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/alloy/git-svn-mirror
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --charset=UTF-8
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
hash: 3
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: A command-line tool that automates the task of creating a GIT mirror for a SVN repo, and keeping it up-to-date.
|
72
|
+
test_files: []
|
73
|
+
|