Skip to content

Commit 5842a2a

Browse files
committed
Fixed issue attempting to track remote SVN branches in git >= 1.8.3.2.
In order not to break semantics with those using svn2git with git < 1.8.3.2, the current tracking behavior is preserved but deprecated. Its functionality is superceded by our '--rebase' option for re-syncing with upstream.
1 parent 8e0ce38 commit 5842a2a

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/svn2git/migration.rb

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def escape_quotes(str)
155155
Svn2Git::Migration.escape_quotes(str)
156156
end
157157

158+
def self.checkout_svn_branch(branch)
159+
"git checkout -b \"#{branch}\" \"remotes/svn/#{branch}\""
160+
end
161+
158162
private
159163

160164
def clone!
@@ -318,8 +322,36 @@ def fix_branches
318322
end
319323

320324
next if branch == 'trunk' || @local.include?(branch)
321-
run_command("git branch --track \"#{branch}\" \"remotes/svn/#{branch}\"")
322-
run_command("git checkout \"#{branch}\"")
325+
326+
if @cannot_setup_tracking_information
327+
run_command(Svn2Git::Migration.checkout_svn_branch(branch))
328+
else
329+
status = run_command("git branch --track \"#{branch}\" \"remotes/svn/#{branch}\"", false)
330+
331+
# As of git 1.8.3.2, tracking information cannot be set up for remote SVN branches:
332+
# http://git.661346.n2.nabble.com/git-svn-Use-prefix-by-default-td7594288.html#a7597159
333+
#
334+
# Older versions of git can do it and it should be safe as long as remotes aren't pushed.
335+
# Our --rebase option obviates the need for read-only tracked remotes, however. So, we'll
336+
# deprecate the old option, informing those relying on the old behavior that they should
337+
# use the newer --rebase otion.
338+
if status =~ /Cannot setup tracking information/m
339+
@cannot_setup_tracking_information = true
340+
run_command(Svn2Git::Migration.checkout_svn_branch(branch))
341+
else
342+
unless @legacy_svn_branch_tracking_message_displayed
343+
warn '*' * 68
344+
warn "svn2git warning: Tracking remote SVN branches is deprecated."
345+
warn "In a future release local branches will be created without tracking."
346+
warn "If you must resync your branches, run: svn2git --rebase"
347+
warn '*' * 68
348+
end
349+
350+
@legacy_svn_branch_tracking_message_displayed = true
351+
352+
run_command("git checkout \"#{branch}\"")
353+
end
354+
end
323355
end
324356
end
325357

test/commands_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require File.expand_path(File.join(__FILE__, '..', 'test_helper'))
2+
3+
class CommandsTest < Minitest::Test
4+
def test_checkout_svn_branch
5+
actual = Svn2Git::Migration.checkout_svn_branch('blah')
6+
7+
assert_equal 'git checkout -b "blah" "remotes/svn/blah"', actual
8+
end
9+
end

0 commit comments

Comments
 (0)