Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the branch tracing info bug. #56

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 2 additions & 68 deletions src/Fixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public void FixBranches()
Log(sb.ToString());
}

bool cannotSetupTrackingInformation = false;
bool legacySvnBranchTrackingMessageDisplayed = false;

foreach (var b in svnBranches)
{
var branch = Regex.Replace(b, @"^svn\/", "").Trim();
Expand Down Expand Up @@ -116,50 +113,8 @@ public void FixBranches()
continue;
}

if (cannotSetupTrackingInformation)
{
CommandInfo ci = CommandInfoBuilder.BuildCheckoutSvnRemoteBranchCommandInfo(branch);
CommandRunner.Run(ci.Command, ci.Arguments);
}
else
{
CommandInfo trackCommandInfo = CommandInfoBuilder.BuildGitBranchTrackCommandInfo(branch);

string trackCommandError = string.Empty;
string dummyOutput = string.Empty;
RunCommand(trackCommandInfo, out dummyOutput, out trackCommandError);

// 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 option.
Log($"trackCommandError: {trackCommandError}");
if (Regex.IsMatch(trackCommandError, @"(?m)Cannot setup tracking information"))
{
Log("Has tracking error.");
cannotSetupTrackingInformation = true;

CommandInfo checkoutRemoteBranchCommandInfo = CommandInfoBuilder.BuildCheckoutSvnRemoteBranchCommandInfo(branch);

RunCommand(checkoutRemoteBranchCommandInfo);
}
else
{
if (!legacySvnBranchTrackingMessageDisplayed)
{
ShowTrackingRemoteSvnBranchesDeprecatedWarning();
}

legacySvnBranchTrackingMessageDisplayed = true;

CommandInfo checkoutLocalBranchCommandInfo = CommandInfoBuilder.BuildCheckoutLocalBranchCommandInfo(branch);

RunCommand(checkoutLocalBranchCommandInfo);
}
}
// Now checkout the remote svn branch.
RunCommand(CommandInfoBuilder.BuildCheckoutSvnRemoteBranchCommandInfo(branch));
}

Log("End fixing branches.");
Expand Down Expand Up @@ -261,26 +216,5 @@ public void OptimizeRepos()
{
CommandRunner.Run("git", "gc");
}

private void ShowTrackingRemoteSvnBranchesDeprecatedWarning()
{
StringBuilder message = new StringBuilder();
for (int i = 0; i < 68; ++i)
{
message.Append("*");
}
message.AppendLine();

message.AppendLine("svn2gitnet warning: Tracking remote SVN branches is deprecated.");
message.AppendLine("In a future release local branches will be created without tracking.");
message.AppendLine("If you must resync your branches, run: svn2gitnet --rebase");

for (int i = 0; i < 68; ++i)
{
message.Append("*");
}

ShowMessageIfPossible(message.ToString());
}
}
}
86 changes: 0 additions & 86 deletions tests/unittests/FixerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,6 @@ public void FixBranchesIsNotRebaseIsNotTrunkBranchTest()
mock.Setup(f => f.Run("git", It.IsAny<string>()))
.Returns(0);

string standardOutput = string.Empty;
string standardError = "Hello. Cannot setup tracking information!";
mock.Setup(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError));


MetaInfo metaInfo = new MetaInfo()
{
LocalBranches = new List<string>()
Expand All @@ -353,87 +348,6 @@ public void FixBranchesIsNotRebaseIsNotTrunkBranchTest()

// Assert
mock.Verify(f => f.Run("git", "checkout -b \"dev\" \"remotes/svn/dev\""), Times.Once());
mock.Verify(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError), Times.Once());
}

[Fact]
public void FixBranchesIsNotRebaseIsNotTrunkBranchTrackingWarningTest()
{
// Prepare
var mock = new Mock<ICommandRunner>();
mock.Setup(f => f.Run("git", It.IsAny<string>()))
.Returns(0);

string standardOutput = string.Empty;
string standardError = "Hello. Cannot setup tracking information!";
mock.Setup(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError));

MetaInfo metaInfo = new MetaInfo()
{
LocalBranches = new List<string>()
{
"nodev"
},
RemoteBranches = new List<string>()
{
"svn/dev",
"svn/branch2"
}
};

Options options = new Options()
{
Rebase = false
};

IFixer fixer = new Fixer(metaInfo, options, mock.Object, "", null, null);

// Act
fixer.FixBranches();

// Assert
mock.Verify(f => f.Run("git", "checkout -b \"dev\" \"remotes/svn/dev\""), Times.Once());
mock.Verify(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError), Times.Once());
}

[Fact]
public void FixBranchesIsNotRebaseIsNotTrunkBranchTrackingNoWarningTest()
{
// Prepare
var mock = new Mock<ICommandRunner>();
mock.Setup(f => f.Run("git", It.IsAny<string>()))
.Returns(0);

string standardOutput = string.Empty;
string standardError = string.Empty;
mock.Setup(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError));

MetaInfo metaInfo = new MetaInfo()
{
LocalBranches = new List<string>()
{
"nodev"
},
RemoteBranches = new List<string>()
{
"svn/dev",
"svn/branch2"
}
};

Options options = new Options()
{
Rebase = false
};

IFixer fixer = new Fixer(metaInfo, options, mock.Object, "", null, null);

// Act
fixer.FixBranches();

// Assert
mock.Verify(f => f.Run("git", "checkout \"dev\""), Times.Once());
mock.Verify(f => f.Run("git", "branch --track \"dev\" \"remotes/svn/dev\"", out standardOutput, out standardError), Times.Once());
}

#endregion
Expand Down