Init branch crash fixed if branch already exist (big problem with branch --init --all)

This commit is contained in:
Shapkin Arkady
2014-01-20 14:20:35 +04:00
committed by Arkady Shapkin
parent 6f03a2e2f6
commit dc7c6d61bc
2 changed files with 16 additions and 4 deletions
@@ -76,7 +76,7 @@ namespace Sep.Git.Tfs.VsCommon
Trace.WriteLine("Found parent branch : " + tfsPathParentBranch);
var firstChangesetInBranchToCreate = VersionControl.QueryHistory(tfsPathBranchToCreate, VersionSpec.Latest, 0, RecursionType.Full,
null, null, null, int.MaxValue, true, false, false).Cast<Changeset>().LastOrDefault();
null, null, null, 1, false, false, false, true).Cast<Changeset>().FirstOrDefault();
if (firstChangesetInBranchToCreate == null)
{
@@ -97,9 +97,9 @@ namespace Sep.Git.Tfs.VsCommon
return rootChangesetInParentBranch.ChangesetId;
}
catch(VersionControlException)
catch (VersionControlException)
{
throw new GitTfsException("An unexpected error occured when trying to find the root changeset.\nFailed to get merge changesets for " + tfsPathBranchToCreate);
throw new GitTfsException("An unexpected error occured when trying to find the root changeset.\nFailed to query history for " + tfsPathBranchToCreate);
}
}
catch (FeatureNotSupportedException ex)
+13 -1
View File
@@ -112,6 +112,7 @@ namespace Sep.Git.Tfs.Commands
return GitTfsExitCodes.OK;
}
[DebuggerDisplay("{TfsRepositoryPath} C{RootChangesetId}")]
class BranchDatas
{
public string TfsRepositoryPath { get; set; }
@@ -248,6 +249,17 @@ namespace Sep.Git.Tfs.Commands
throw new GitTfsException("error: The Git branch name '" + gitBranchName + "' is not valid...\n");
Trace.WriteLine("Git local branch will be :" + gitBranchName);
if (_globals.Repository.HasRemote(gitBranchName))
{
Trace.WriteLine("Remote already exist");
var remote = _globals.Repository.ReadTfsRemote(gitBranchName);
if (remote.TfsUrl != defaultRemote.TfsUrl)
Trace.WriteLine("warning: Url is different");
if (remote.TfsRepositoryPath != tfsRepositoryPath)
Trace.WriteLine("warning: TFS repository path is different");
return remote;
}
Trace.WriteLine("Try creating remote...");
var tfsRemote = _globals.Repository.CreateTfsRemote(new RemoteInfo
{
@@ -255,7 +267,7 @@ namespace Sep.Git.Tfs.Commands
Url = defaultRemote.TfsUrl,
Repository = tfsRepositoryPath,
RemoteOptions = _remoteOptions
}, System.String.Empty);
}, String.Empty);
if (!_globals.Repository.CreateBranch(tfsRemote.RemoteRef, sha1RootCommit))
throw new GitTfsException("error: Fail to create remote branch ref file!");