lib/svn2git/migration.rb in nirvdrum-svn2git-1.2.4 vs lib/svn2git/migration.rb in nirvdrum-svn2git-1.3.0
- old
+ new
@@ -30,10 +30,11 @@
options[:verbose] = false
options[:rootistrunk] = false
options[:trunk] = 'trunk'
options[:branches] = 'branches'
options[:tags] = 'tags'
+ options[:exclude] = []
if File.exists?(File.expand_path(DEFAULT_AUTHORS_FILE))
options[:authors] = DEFAULT_AUTHORS_FILE
end
@@ -50,21 +51,39 @@
end
opts.on('--branches BRANCHES_PATH', 'Subpath to branches from repository URL (default: branches)') do |branches|
options[:branches] = branches
end
-
opts.on('--tags TAGS_PATH', 'Subpath to tags from repository URL (default: tags)') do |tags|
options[:tags] = tags
end
+ opts.on('--rootistrunk', 'Use this if the root level of the repo is equivalent to the trunk and there are no tags or branches') do
+ options[:rootistrunk] = true
+ options[:trunk] = nil
+ options[:branches] = nil
+ options[:tags] = nil
+ end
+
+ opts.on('--notrunk', 'Do not import anything from trunk') do
+ options[:trunk] = nil
+ end
+
+ opts.on('--nobranches', 'Do not try to import any branches') do
+ options[:branches] = nil
+ end
+
+ opts.on('--notags', 'Do not try to import any tags') do
+ options[:tags] = nil
+ end
+
opts.on('--authors AUTHORS_FILE', "Path to file containing svn-to-git authors mapping (default: #{DEFAULT_AUTHORS_FILE})") do |authors|
options[:authors] = authors
end
- opts.on('--rootistrunk', 'Use this if the root level of the repo isequivalent to the trunk and there are no tags or branches') do
- options[:rootistrunk] = true
+ opts.on('--exclude REGEX', 'Specify a Perl regular expression to filter paths when fetching; can be used multiple times') do |regex|
+ options[:exclude] << regex
end
opts.on('-v', '--verbose', 'Be verbose in logging -- useful for debugging issues') do
options[:verbose] = true
end
@@ -89,10 +108,11 @@
trunk = @options[:trunk]
branches = @options[:branches]
tags = @options[:tags]
rootistrunk = @options[:rootistrunk]
authors = @options[:authors]
+ exclude = @options[:exclude]
if rootistrunk
# Non-standard repository layout. The repository root is effectively 'trunk.'
run_command("git svn init --no-metadata --trunk=#{@url}")
@@ -108,12 +128,26 @@
run_command(cmd)
end
run_command("git config svn.authorsfile #{authors}") if authors
- run_command("git svn fetch")
+ cmd = "git svn fetch"
+ unless exclude.empty?
+ # Add exclude paths to the command line; some versions of git support
+ # this for fetch only, later also for init.
+ regex = []
+ unless rootistrunk
+ regex << "#{trunk}[/]" unless trunk.nil?
+ regex << "#{tags}[/][^/]+[/]" unless tags.nil?
+ regex << "#{branches}[/][^/]+[/]" unless branches.nil?
+ end
+ regex = '^(?:' + regex.join('|') + ')(?:' + exclude.join('|') + ')'
+ cmd += "'--ignore-paths=#{regex}'"
+ end
+ run_command(cmd)
+
get_branches
end
def get_branches
@remote = `git branch -r`.split(/\n/)
@@ -123,11 +157,10 @@
def fix_tags
@tags.each do |tag|
id = tag.strip.gsub(%r{^#{@options[:tags]}\/}, '')
subject = `git log -1 --pretty=format:"%s" #{tag.strip()}`
date = `git log -1 --pretty=format:"%ci" #{tag.strip()}`
- `export GIT_COMMITER_DATE="#{date}"`
- run_command("git tag -a -m '#{subject}' '#{id.strip()}' '#{tag.strip()}'")
+ run_command("GIT_COMMITTER_DATE='#{date}' git tag -a -m '#{subject}' '#{id.strip()}' '#{tag.strip()}'")
run_command("git branch -d -r #{tag.strip()}")
end
end
def fix_branches