lib/svn2git/migration.rb in svn2git-2.3.0 vs lib/svn2git/migration.rb in svn2git-2.3.1

- old
+ new

@@ -153,10 +153,14 @@ def escape_quotes(str) Svn2Git::Migration.escape_quotes(str) end + def self.checkout_svn_branch(branch) + "git checkout -b \"#{branch}\" \"remotes/svn/#{branch}\"" + end + private def clone! trunk = @options[:trunk] branches = @options[:branches] @@ -316,12 +320,40 @@ run_command("git rebase \"remotes/svn/#{branch}\"") next end next if branch == 'trunk' || @local.include?(branch) - run_command("git branch --track \"#{branch}\" \"remotes/svn/#{branch}\"") - run_command("git checkout \"#{branch}\"") + + if @cannot_setup_tracking_information + run_command(Svn2Git::Migration.checkout_svn_branch(branch)) + else + status = run_command("git branch --track \"#{branch}\" \"remotes/svn/#{branch}\"", false) + + # As of git 1.8.3.2, tracking information cannot be set up for remote SVN branches: + # http://git.661346.n2.nabble.com/git-svn-Use-prefix-by-default-td7594288.html#a7597159 + # + # Older versions of git can do it and it should be safe as long as remotes aren't pushed. + # Our --rebase option obviates the need for read-only tracked remotes, however. So, we'll + # deprecate the old option, informing those relying on the old behavior that they should + # use the newer --rebase otion. + if status =~ /Cannot setup tracking information/m + @cannot_setup_tracking_information = true + run_command(Svn2Git::Migration.checkout_svn_branch(branch)) + else + unless @legacy_svn_branch_tracking_message_displayed + warn '*' * 68 + warn "svn2git warning: Tracking remote SVN branches is deprecated." + warn "In a future release local branches will be created without tracking." + warn "If you must resync your branches, run: svn2git --rebase" + warn '*' * 68 + end + + @legacy_svn_branch_tracking_message_displayed = true + + run_command("git checkout \"#{branch}\"") + end + end end end def fix_trunk trunk = @remote.find { |b| b.strip == 'trunk' } @@ -337,11 +369,11 @@ def optimize_repos run_command("git gc") end def run_command(cmd, exit_on_error=true, printout_output=false) - log "Running command: #{cmd}" + log "Running command: #{cmd}\n" ret = '' @mutex ||= Mutex.new @stdin_queue ||= Queue.new @@ -421,10 +453,10 @@ ret end def log(msg) - puts msg if @options[:verbose] + print msg if @options[:verbose] end def show_help_message(msg) puts "Error starting script: #{msg}\n\n" puts @opts.help