private void VerifyTfsPathToClone(string tfsRepositoryPath)
{
if (_initBranch == null)
return;
try
{
var remote = _globals.Repository.ReadTfsRemote(GitTfsConstants.DefaultRepositoryId);
if (!remote.Tfs.IsExistingInTfs(tfsRepositoryPath))
throw new GitTfsException("error: the path " + tfsRepositoryPath + " you want to clone doesn't exist!")
.WithRecommendation("To discover which branch to clone, you could use the command :\ngit tfs list-remote-branches " + remote.TfsUrl);
if (!remote.Tfs.CanGetBranchInformation)
return;
var tfsTrunkRepository = remote.Tfs.GetRootTfsBranchForRemotePath(tfsRepositoryPath, false);
if (tfsTrunkRepository == null)
{
var tfsRootBranches = remote.Tfs.GetAllTfsRootBranchesOrderedByCreation();
if (!tfsRootBranches.Any())
{
Trace.TraceInformation("info: no TFS root found !\n\nPS:perhaps you should convert your trunk folder into a branch in TFS.");
return;
}
var cloneMsg = " => If you want to manage branches with git-tfs, clone one of this branch instead :\n"
+ " - " + tfsRootBranches.Aggregate((s1, s2) => s1 + "\n - " + s2)
+ "\n\nPS:if your branch is not listed here, perhaps you should convert the containing folder to a branch in TFS.";
if (_fetch.BranchStrategy == BranchStrategy.All)
throw new GitTfsException("error: cloning the whole repository or too high in the repository path doesn't permit to manage branches!\n" + cloneMsg);
Trace.TraceWarning("warning: you are going to clone the whole repository or too high in the repository path !\n" + cloneMsg);
return;
}
var tfsBranchesPath = tfsTrunkRepository.GetAllChildren();
var tfsPathToClone = tfsRepositoryPath.TrimEnd('/').ToLower();
var tfsTrunkRepositoryPath = tfsTrunkRepository.Path;
if (tfsPathToClone != tfsTrunkRepositoryPath.ToLower())
{
if (tfsBranchesPath.Select(e => e.Path.ToLower()).Contains(tfsPathToClone))
Trace.TraceInformation("info: you are going to clone a branch instead of the trunk ( {0} )\n"
+ " => If you want to manage branches with git-tfs, clone {0} with '--branches=all' option instead...)", tfsTrunkRepositoryPath);
else
Trace.TraceWarning("warning: you are going to clone a subdirectory of a branch and won't be able to manage branches :(\n"
+ " => If you want to manage branches with git-tfs, clone " + tfsTrunkRepositoryPath + " with '--branches=all' option instead...)");
}
}
catch (GitTfsException)
{
throw;
}
catch (Exception ex)
{
Trace.TraceWarning("warning: a server error occurs when trying to verify the tfs path cloned:\n " + ex.Message
+ "\n try to continue anyway...");
}
}