nirvdrum-svn2git 1.1.1 → 1.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.
- data/ChangeLog.markdown +22 -0
- data/{README → README.markdown} +31 -15
- data/VERSION.yml +2 -2
- data/lib/svn2git/migration.rb +97 -37
- metadata +7 -5
data/ChangeLog.markdown
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# 1.2.0 - 2009-04-17
|
2
|
+
|
3
|
+
* Reworked command-line options so they work similarly to every other app in the world.
|
4
|
+
* Better error messaging when no URL provided.
|
5
|
+
* Improved docs.
|
6
|
+
|
7
|
+
# 1.1.1 - 2009-04-15
|
8
|
+
|
9
|
+
* Started using Jeweler for gem management.
|
10
|
+
* Fixed issue with not loading up RubyGems appropriately.
|
11
|
+
|
12
|
+
# 1.1.0 - 2009-01-02
|
13
|
+
|
14
|
+
* First release since nirvdrum fork.
|
15
|
+
|
16
|
+
* Fixed issues with handling of tags and branches.
|
17
|
+
* Added better logging of output from git-svn.
|
18
|
+
* Wrap external command processing to capture failures.
|
19
|
+
|
20
|
+
# 1.0.0 - 2008-07-19
|
21
|
+
|
22
|
+
* Forked version from jcoglan.
|
data/{README → README.markdown}
RENAMED
@@ -1,13 +1,15 @@
|
|
1
|
-
|
1
|
+
svn2git
|
2
|
+
=======
|
2
3
|
|
3
|
-
|
4
|
+
_svn2git_ is a tiny utility for migrating projects from Subversion to Git
|
4
5
|
while keeping the trunk, branches and tags where they should be. It uses
|
5
6
|
git-svn to clone an svn repository and does some clean-up to make sure
|
6
7
|
branches and tags are imported in a meaningful way, and that the code checked
|
7
8
|
into master ends up being what's currently in your svn trunk rather than
|
8
9
|
whichever svn branch your last commit was in.
|
9
10
|
|
10
|
-
|
11
|
+
Examples
|
12
|
+
--------
|
11
13
|
|
12
14
|
Say I have this code in svn:
|
13
15
|
|
@@ -59,14 +61,16 @@ After svn2git is done with your project, you'll get this instead:
|
|
59
61
|
Finally, it makes sure the HEAD of master is the same as the current trunk of
|
60
62
|
the svn repo.
|
61
63
|
|
62
|
-
|
64
|
+
Installation
|
65
|
+
------------
|
63
66
|
|
64
67
|
Make sure you have git installed, then install the gem:
|
65
68
|
|
66
|
-
|
67
|
-
|
69
|
+
$ sudo apt-get install git-core git-svn
|
70
|
+
$ sudo gem install nirvdrum-svn2git
|
68
71
|
|
69
|
-
|
72
|
+
Usage
|
73
|
+
-----
|
70
74
|
|
71
75
|
There are a number of ways in which you can create a git repo from an existing
|
72
76
|
svn repo. The differentiating factor is the svn repo layout. Below is an
|
@@ -76,28 +80,28 @@ create a git repo from a svn repo in the specified layout.
|
|
76
80
|
1. The svn repo is in the standard layout of (trunk, branches, tags) at the
|
77
81
|
root level of the repo.
|
78
82
|
|
79
|
-
|
83
|
+
$ svn2git http://svn.yoursite.com/path/to/repo --trunk trunk --branches branches --tags tags
|
80
84
|
|
81
85
|
2. The svn repo is NOT in standard layout and has only a trunk and tags at the
|
82
86
|
root level of the repo.
|
83
87
|
|
84
|
-
|
88
|
+
$ svn2git http://svn.yoursite.com/path/to/repo --trunk trunk --tags tags
|
85
89
|
|
86
90
|
3. The svn repo is NOT in standard layout and has only a trunk and branches at
|
87
91
|
the root level of the repo.
|
88
92
|
|
89
|
-
|
93
|
+
$ svn2git http://svn.yoursite.com/path/to/repo --trunk trunk --branches branches
|
90
94
|
|
91
95
|
4. The svn repo is NOT in standard layout and has only a trunk at the root
|
92
96
|
level of the repo.
|
93
97
|
|
94
|
-
|
98
|
+
$ svn2git http://svn.yoursite.com/path/to/repo --trunk trunk
|
95
99
|
|
96
100
|
5. The svn repo is NOT in standard layout and has no trunk, branches, or tags
|
97
101
|
at the root level of the repo. Instead the root level of the repo is
|
98
102
|
equivalent to the trunk and there are no tags or branches.
|
99
103
|
|
100
|
-
|
104
|
+
$ svn2git http://svn.yoursite.com/path/to/repo --rootistrunk
|
101
105
|
|
102
106
|
The above will create a git repository in the current directory with the git
|
103
107
|
version of the svn repository. Hence, you need to make a directory that you
|
@@ -108,7 +112,8 @@ specified trunk=foo branches=bar and tags=foobar it would be referencing
|
|
108
112
|
http://svn.yoursite.com/path/to/repo/foo as your trunk, and so on. However, in
|
109
113
|
case 5 it references the root of the repo as trunk.
|
110
114
|
|
111
|
-
|
115
|
+
Authors
|
116
|
+
-------
|
112
117
|
|
113
118
|
To convert all your svn authors to git format, create a file somewhere on your
|
114
119
|
system with the list of conversions to make, one per line, for example:
|
@@ -118,9 +123,20 @@ system with the list of conversions to make, one per line, for example:
|
|
118
123
|
|
119
124
|
Then pass an +authors+ option to +svn2git+ pointing to your file:
|
120
125
|
|
121
|
-
svn2git http://repos.com/myproject authors
|
126
|
+
svn2git http://repos.com/myproject --authors ~/authors.txt
|
122
127
|
|
123
128
|
Alternatively, you can place the authors file into ~/.svn2git/authors and
|
124
129
|
svn2git will load it out of there. This allows you to build up one authors
|
125
130
|
file for all your projects and have it loaded for each repository that you
|
126
|
-
migrate.
|
131
|
+
migrate.
|
132
|
+
|
133
|
+
Debugging
|
134
|
+
---------
|
135
|
+
|
136
|
+
If you're having problems with converting your repository and you're not sure why,
|
137
|
+
try turning on verbose logging. This will print out more information from the
|
138
|
+
underlying git-svn process.
|
139
|
+
|
140
|
+
You can turn on verbose logging with the '-v' or '--verbose' flags, like so:
|
141
|
+
|
142
|
+
$ svn2git http://svn.yoursite.com/path/to/repo --verbose
|
data/VERSION.yml
CHANGED
data/lib/svn2git/migration.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'pp'
|
3
|
+
|
1
4
|
module Svn2Git
|
2
5
|
DEFAULT_AUTHORS_FILE = "~/.svn2git/authors"
|
3
|
-
|
6
|
+
|
4
7
|
class Migration
|
5
|
-
|
8
|
+
|
6
9
|
attr_reader :dir
|
7
|
-
|
8
|
-
def initialize(
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
@options[:branches] ||= 'branches'
|
15
|
-
@options[:tags] ||= 'tags'
|
16
|
-
|
17
|
-
@authors = options[:authors]
|
18
|
-
if @authors.nil? && File.exists?(File.expand_path(DEFAULT_AUTHORS_FILE))
|
19
|
-
@authors = DEFAULT_AUTHORS_FILE
|
20
|
-
end
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
@options = parse(args)
|
13
|
+
show_help_message("Missing SVN_URL parameter") if args.empty?
|
14
|
+
show_help_message('Too many arguments') if args.size > 1
|
15
|
+
|
16
|
+
@url = args.first
|
21
17
|
end
|
22
|
-
|
18
|
+
|
23
19
|
def run!
|
24
20
|
clone!
|
25
21
|
fix_tags
|
@@ -27,43 +23,103 @@ module Svn2Git
|
|
27
23
|
fix_trunk
|
28
24
|
optimize_repos
|
29
25
|
end
|
30
|
-
|
26
|
+
|
27
|
+
def parse(args)
|
28
|
+
# Set up reasonable defaults for options.
|
29
|
+
options = {}
|
30
|
+
options[:verbose] = false
|
31
|
+
options[:rootistrunk] = false
|
32
|
+
options[:trunk] = 'trunk'
|
33
|
+
options[:branches] = 'branches'
|
34
|
+
options[:tags] = 'tags'
|
35
|
+
|
36
|
+
if File.exists?(File.expand_path(DEFAULT_AUTHORS_FILE))
|
37
|
+
options[:authors] = DEFAULT_AUTHORS_FILE
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Parse the command-line arguments.
|
42
|
+
@opts = OptionParser.new do |opts|
|
43
|
+
opts.banner = 'Usage: svn2git SVN_URL [options]'
|
44
|
+
|
45
|
+
opts.separator ''
|
46
|
+
opts.separator 'Specific options:'
|
47
|
+
|
48
|
+
opts.on('--trunk TRUNK_PATH', 'Subpath to trunk from repository URL (default: trunk)') do |trunk|
|
49
|
+
options[:trunk] = trunk
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('--branches BRANCHES_PATH', 'Subpath to branches from repository URL (default: branches)') do |branches|
|
53
|
+
options[:branches] = branches
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on('--tags TAGS_PATH', 'Subpath to tags from repository URL (default: tags)') do |tags|
|
57
|
+
options[:tags] = tags
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on('--authors AUTHORS_FILE', "Path to file containing svn-to-git authors mapping (default: #{DEFAULT_AUTHORS_FILE})") do |authors|
|
61
|
+
options[:authors] = authors
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on('--rootistrunk', 'Use this if the root level of the repo isequivalent to the trunk and there are no tags or branches') do
|
65
|
+
options[:rootistrunk] = true
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on('-v', '--verbose', 'Be verbose in logging -- useful for debugging issues') do
|
69
|
+
options[:verbose] = true
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.separator ""
|
73
|
+
|
74
|
+
# No argument, shows at tail. This will print an options summary.
|
75
|
+
# Try it and see!
|
76
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
77
|
+
puts opts
|
78
|
+
exit
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
@opts.parse! args
|
83
|
+
options
|
84
|
+
end
|
85
|
+
|
31
86
|
private
|
32
|
-
|
87
|
+
|
33
88
|
def clone!
|
34
89
|
trunk = @options[:trunk]
|
35
90
|
branches = @options[:branches]
|
36
91
|
tags = @options[:tags]
|
37
92
|
rootistrunk = @options[:rootistrunk]
|
38
|
-
|
39
|
-
|
93
|
+
authors = @options[:authors]
|
94
|
+
|
95
|
+
if rootistrunk
|
40
96
|
# Non-standard repository layout. The repository root is effectively 'trunk.'
|
41
97
|
run_command("git svn init --no-metadata --trunk=#{@url}")
|
42
|
-
|
98
|
+
|
43
99
|
else
|
44
100
|
cmd = "git svn init --no-metadata "
|
45
|
-
|
101
|
+
|
46
102
|
# Add each component to the command that was passed as an argument.
|
47
103
|
cmd += "--trunk=#{trunk} " unless trunk.nil?
|
48
104
|
cmd += "--tags=#{tags} " unless tags.nil?
|
49
105
|
cmd += "--branches=#{branches} " unless branches.nil?
|
50
|
-
|
106
|
+
|
51
107
|
cmd += @url
|
52
|
-
|
108
|
+
|
53
109
|
run_command(cmd)
|
54
110
|
end
|
55
|
-
|
56
|
-
run_command("git config svn.authorsfile #{
|
111
|
+
|
112
|
+
run_command("git config svn.authorsfile #{authors}") if authors
|
57
113
|
run_command("git svn fetch")
|
58
|
-
|
114
|
+
|
59
115
|
get_branches
|
60
116
|
end
|
61
|
-
|
117
|
+
|
62
118
|
def get_branches
|
63
119
|
@remote = `git branch -r`.split(/\n/)
|
64
120
|
@tags = @remote.find_all { |b| b.strip =~ %r{^#{@options[:tags]}\/} }
|
65
121
|
end
|
66
|
-
|
122
|
+
|
67
123
|
def fix_tags
|
68
124
|
@tags.each do |tag|
|
69
125
|
id = tag.strip.gsub(%r{^#{@options[:tags]}\/}, '')
|
@@ -74,7 +130,7 @@ module Svn2Git
|
|
74
130
|
run_command("git branch -d -r #{tag.strip()}")
|
75
131
|
end
|
76
132
|
end
|
77
|
-
|
133
|
+
|
78
134
|
def fix_branches
|
79
135
|
svn_branches = @remote.find_all { |b| not @tags.include?(b) }
|
80
136
|
svn_branches.each do |branch|
|
@@ -84,7 +140,7 @@ module Svn2Git
|
|
84
140
|
run_command("git checkout -b #{branch}")
|
85
141
|
end
|
86
142
|
end
|
87
|
-
|
143
|
+
|
88
144
|
def fix_trunk
|
89
145
|
trunk = @remote.find { |b| b.strip == 'trunk' }
|
90
146
|
if trunk
|
@@ -94,14 +150,14 @@ module Svn2Git
|
|
94
150
|
run_command("git branch -d -r trunk")
|
95
151
|
end
|
96
152
|
end
|
97
|
-
|
153
|
+
|
98
154
|
def optimize_repos
|
99
155
|
run_command("git gc")
|
100
156
|
end
|
101
|
-
|
157
|
+
|
102
158
|
def run_command(cmd)
|
103
159
|
log "Running command: #{cmd}"
|
104
|
-
|
160
|
+
|
105
161
|
IO.popen(cmd) do |stdout|
|
106
162
|
stdout.each do |line|
|
107
163
|
log line
|
@@ -109,12 +165,16 @@ module Svn2Git
|
|
109
165
|
end
|
110
166
|
end
|
111
167
|
|
112
|
-
private
|
113
|
-
|
114
168
|
def log(msg)
|
115
169
|
puts msg if @options[:verbose]
|
116
170
|
end
|
117
171
|
|
172
|
+
def show_help_message(msg)
|
173
|
+
puts "Error starting script: #{msg}\n\n"
|
174
|
+
puts @opts.help
|
175
|
+
exit
|
176
|
+
end
|
177
|
+
|
118
178
|
end
|
119
179
|
end
|
120
180
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nirvdrum-svn2git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Coglan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-04-
|
13
|
+
date: 2009-04-17 00:00:00 -07:00
|
14
14
|
default_executable: svn2git
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -21,14 +21,16 @@ executables:
|
|
21
21
|
extensions: []
|
22
22
|
|
23
23
|
extra_rdoc_files:
|
24
|
-
-
|
24
|
+
- ChangeLog.markdown
|
25
|
+
- README.markdown
|
25
26
|
files:
|
27
|
+
- ChangeLog.markdown
|
28
|
+
- README.markdown
|
26
29
|
- Rakefile
|
27
30
|
- VERSION.yml
|
28
31
|
- bin/svn2git
|
29
32
|
- lib/svn2git.rb
|
30
33
|
- lib/svn2git/migration.rb
|
31
|
-
- README
|
32
34
|
has_rdoc: true
|
33
35
|
homepage: https://www.negativetwenty.net/redmine/projects/svn2git
|
34
36
|
post_install_message:
|
@@ -53,7 +55,7 @@ requirements: []
|
|
53
55
|
rubyforge_project:
|
54
56
|
rubygems_version: 1.2.0
|
55
57
|
signing_key:
|
56
|
-
specification_version:
|
58
|
+
specification_version: 3
|
57
59
|
summary: A tool for migrating svn projects to git
|
58
60
|
test_files: []
|
59
61
|
|