From dc7c6d61bc79ccfbbbc4fe944c29ca74e18d5444 Mon Sep 17 00:00:00 2001 From: Shapkin Arkady Date: Mon, 20 Jan 2014 14:20:35 +0400 Subject: [PATCH] Init branch crash fixed if branch already exist (big problem with `branch --init --all`) --- GitTfs.VsCommon/TfsHelper.PostVs2010.Common.cs | 6 +++--- GitTfs/Commands/InitBranch.cs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/GitTfs.VsCommon/TfsHelper.PostVs2010.Common.cs b/GitTfs.VsCommon/TfsHelper.PostVs2010.Common.cs index 888df91c..3deeba06 100644 --- a/GitTfs.VsCommon/TfsHelper.PostVs2010.Common.cs +++ b/GitTfs.VsCommon/TfsHelper.PostVs2010.Common.cs @@ -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().LastOrDefault(); + null, null, null, 1, false, false, false, true).Cast().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) diff --git a/GitTfs/Commands/InitBranch.cs b/GitTfs/Commands/InitBranch.cs index cfef4ca4..889a9ee8 100644 --- a/GitTfs/Commands/InitBranch.cs +++ b/GitTfs/Commands/InitBranch.cs @@ -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!");