Skip to content

Commit 0aa271e

Browse files
committed
Fixed branch tracking issue.
Remove the legacy support for tracking. User checkout -b directly instead of trying tracking the remote branch. Fix #56
1 parent ef5fce8 commit 0aa271e

File tree

2 files changed

+2
-154
lines changed

2 files changed

+2
-154
lines changed

src/Fixer.cs

+2-68
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ public void FixBranches()
8585
Log(sb.ToString());
8686
}
8787

88-
bool cannotSetupTrackingInformation = false;
89-
bool legacySvnBranchTrackingMessageDisplayed = false;
90-
9188
foreach (var b in svnBranches)
9289
{
9390
var branch = Regex.Replace(b, @"^svn\/", "").Trim();
@@ -116,50 +113,8 @@ public void FixBranches()
116113
continue;
117114
}
118115

119-
if (cannotSetupTrackingInformation)
120-
{
121-
CommandInfo ci = CommandInfoBuilder.BuildCheckoutSvnRemoteBranchCommandInfo(branch);
122-
CommandRunner.Run(ci.Command, ci.Arguments);
123-
}
124-
else
125-
{
126-
CommandInfo trackCommandInfo = CommandInfoBuilder.BuildGitBranchTrackCommandInfo(branch);
127-
128-
string trackCommandError = string.Empty;
129-
string dummyOutput = string.Empty;
130-
RunCommand(trackCommandInfo, out dummyOutput, out trackCommandError);
131-
132-
// As of git 1.8.3.2, tracking information cannot be set up for remote SVN branches:
133-
// http://git.661346.n2.nabble.com/git-svn-Use-prefix-by-default-td7594288.html#a7597159
134-
//
135-
// Older versions of git can do it and it should be safe as long as remotes aren't pushed.
136-
// Our --rebase option obviates the need for read-only tracked remotes, however. So, we'll
137-
// deprecate the old option, informing those relying on the old behavior that they should
138-
// use the newer --rebase option.
139-
Log($"trackCommandError: {trackCommandError}");
140-
if (Regex.IsMatch(trackCommandError, @"(?m)Cannot setup tracking information"))
141-
{
142-
Log("Has tracking error.");
143-
cannotSetupTrackingInformation = true;
144-
145-
CommandInfo checkoutRemoteBranchCommandInfo = CommandInfoBuilder.BuildCheckoutSvnRemoteBranchCommandInfo(branch);
146-
147-
RunCommand(checkoutRemoteBranchCommandInfo);
148-
}
149-
else
150-
{
151-
if (!legacySvnBranchTrackingMessageDisplayed)
152-
{
153-
ShowTrackingRemoteSvnBranchesDeprecatedWarning();
154-
}
155-
156-
legacySvnBranchTrackingMessageDisplayed = true;
157-
158-
CommandInfo checkoutLocalBranchCommandInfo = CommandInfoBuilder.BuildCheckoutLocalBranchCommandInfo(branch);
159-
160-
RunCommand(checkoutLocalBranchCommandInfo);
161-
}
162-
}
116+
// Now checkout the remote svn branch.
117+
RunCommand(CommandInfoBuilder.BuildCheckoutSvnRemoteBranchCommandInfo(branch));
163118
}
164119

165120
Log("End fixing branches.");
@@ -261,26 +216,5 @@ public void OptimizeRepos()
261216
{
262217
CommandRunner.Run("git", "gc");
263218
}
264-
265-
private void ShowTrackingRemoteSvnBranchesDeprecatedWarning()
266-
{
267-
StringBuilder message = new StringBuilder();
268-
for (int i = 0; i < 68; ++i)
269-
{
270-
message.Append("*");
271-
}
272-
message.AppendLine();
273-
274-
message.AppendLine("svn2gitnet warning: Tracking remote SVN branches is deprecated.");
275-
message.AppendLine("In a future release local branches will be created without tracking.");
276-
message.AppendLine("If you must resync your branches, run: svn2gitnet --rebase");
277-
278-
for (int i = 0; i < 68; ++i)
279-
{
280-
message.Append("*");
281-
}
282-
283-
ShowMessageIfPossible(message.ToString());
284-
}
285219
}
286220
}

tests/unittests/FixerTest.cs

-86
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,6 @@ public void FixBranchesIsNotRebaseIsNotTrunkBranchTest()
324324
mock.Setup(f => f.Run("git", It.IsAny<string>()))
325325
.Returns(0);
326326

327-
string standardOutput = string.Empty;
328-
string standardError = "Hello. Cannot setup tracking information!";
329-
mock.Setup(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError));
330-
331-
332327
MetaInfo metaInfo = new MetaInfo()
333328
{
334329
LocalBranches = new List<string>()
@@ -353,87 +348,6 @@ public void FixBranchesIsNotRebaseIsNotTrunkBranchTest()
353348

354349
// Assert
355350
mock.Verify(f => f.Run("git", "checkout -b \"dev\" \"remotes/svn/dev\""), Times.Once());
356-
mock.Verify(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError), Times.Once());
357-
}
358-
359-
[Fact]
360-
public void FixBranchesIsNotRebaseIsNotTrunkBranchTrackingWarningTest()
361-
{
362-
// Prepare
363-
var mock = new Mock<ICommandRunner>();
364-
mock.Setup(f => f.Run("git", It.IsAny<string>()))
365-
.Returns(0);
366-
367-
string standardOutput = string.Empty;
368-
string standardError = "Hello. Cannot setup tracking information!";
369-
mock.Setup(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError));
370-
371-
MetaInfo metaInfo = new MetaInfo()
372-
{
373-
LocalBranches = new List<string>()
374-
{
375-
"nodev"
376-
},
377-
RemoteBranches = new List<string>()
378-
{
379-
"svn/dev",
380-
"svn/branch2"
381-
}
382-
};
383-
384-
Options options = new Options()
385-
{
386-
Rebase = false
387-
};
388-
389-
IFixer fixer = new Fixer(metaInfo, options, mock.Object, "", null, null);
390-
391-
// Act
392-
fixer.FixBranches();
393-
394-
// Assert
395-
mock.Verify(f => f.Run("git", "checkout -b \"dev\" \"remotes/svn/dev\""), Times.Once());
396-
mock.Verify(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError), Times.Once());
397-
}
398-
399-
[Fact]
400-
public void FixBranchesIsNotRebaseIsNotTrunkBranchTrackingNoWarningTest()
401-
{
402-
// Prepare
403-
var mock = new Mock<ICommandRunner>();
404-
mock.Setup(f => f.Run("git", It.IsAny<string>()))
405-
.Returns(0);
406-
407-
string standardOutput = string.Empty;
408-
string standardError = string.Empty;
409-
mock.Setup(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError));
410-
411-
MetaInfo metaInfo = new MetaInfo()
412-
{
413-
LocalBranches = new List<string>()
414-
{
415-
"nodev"
416-
},
417-
RemoteBranches = new List<string>()
418-
{
419-
"svn/dev",
420-
"svn/branch2"
421-
}
422-
};
423-
424-
Options options = new Options()
425-
{
426-
Rebase = false
427-
};
428-
429-
IFixer fixer = new Fixer(metaInfo, options, mock.Object, "", null, null);
430-
431-
// Act
432-
fixer.FixBranches();
433-
434-
// Assert
435-
mock.Verify(f => f.Run("git", "checkout \"dev\""), Times.Once());
436-
mock.Verify(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError), Times.Once());
437351
}
438352

439353
#endregion

0 commit comments

Comments
 (0)