Display informations (info, warning or error) if the clone is not made from a TFS trunk path

... preventing to use `init-branch` later (it's better to warn the earliest possible)
This commit is contained in:
Philippe Miossec
2012-12-09 01:01:17 +01:00
parent b0276231d4
commit e20238fceb
2 changed files with 47 additions and 2 deletions
+46 -1
View File
@@ -20,13 +20,15 @@ namespace Sep.Git.Tfs.Commands
private readonly Globals globals;
private readonly InitBranch initBranch;
private bool withBranches;
private TextWriter stdout;
public Clone(Globals globals, Fetch fetch, Init init, InitBranch initBranch)
public Clone(Globals globals, Fetch fetch, Init init, InitBranch initBranch, TextWriter stdout)
{
this.fetch = fetch;
this.init = init;
this.globals = globals;
this.initBranch = initBranch;
this.stdout = stdout;
}
public OptionSet OptionSet
@@ -52,6 +54,9 @@ namespace Sep.Git.Tfs.Commands
{
var retVal = 0;
retVal = init.Run(tfsUrl, tfsRepositoryPath, gitRepositoryPath);
VerifyTfsPathToClone(tfsRepositoryPath);
if (retVal == 0) retVal = fetch.Run();
if (retVal == 0) globals.Repository.CommandNoisy("merge", globals.Repository.ReadAllTfsRemotes().First().RemoteRef);
if (retVal == 0 && withBranches && initBranch != null)
@@ -89,6 +94,46 @@ namespace Sep.Git.Tfs.Commands
}
}
private void VerifyTfsPathToClone(string tfsRepositoryPath)
{
if (initBranch != null)
{
var remote = globals.Repository.ReadTfsRemote(GitTfsConstants.DefaultRepositoryId);
List<string> tfsBranchesPath;
try
{
tfsBranchesPath = remote.Tfs.GetAllTfsBranchesOrderedByCreation().ToList();
}
//Catch GitTfsException for TFS2008 where GetAllTfsBranchesOrderedByCreation() is not supported/implemented
//=>No control could be done!
catch (GitTfsException) { return; }
var tfsPathToClone = tfsRepositoryPath.TrimEnd('/').ToLower();
var tfsTrunkRepositoryPath = tfsBranchesPath.First();
if (tfsPathToClone != tfsTrunkRepositoryPath.ToLower())
{
if (tfsBranchesPath.Select(e=>e.ToLower()).Contains(tfsPathToClone))
stdout.WriteLine("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 '--with-branches' option instead...)", tfsTrunkRepositoryPath);
else
{
if (tfsTrunkRepositoryPath.ToLower().IndexOf(tfsPathToClone) == 0)
{
if (withBranches)
throw new GitTfsException("error: cloning the whole repository doesn't permit to manage branches!\n"
+ " =>If you want to manage branches with git-tfs, clone " + tfsTrunkRepositoryPath + " instead...");
stdout.WriteLine("warning: you are going to clone the whole repository!\n"
+ " =>If you want to manage branches with git-tfs, clone " + tfsTrunkRepositoryPath + " instead...");
}
else
{
stdout.WriteLine("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 '--with-branches' option instead...)");
}
}
}
}
}
private static bool InitGitDir(string gitRepositoryPath)
{
bool repositoryDirCreated = false;
+1 -1
View File
@@ -7,7 +7,7 @@ namespace Sep.Git.Tfs.Commands
[Description("quick-clone [options] tfs-url-or-instance-name repository-path <git-repository-path>")]
public class QuickClone : Clone
{
public QuickClone(Globals globals, Init init, QuickFetch fetch) : base(globals, fetch, init, null)
public QuickClone(Globals globals, Init init, QuickFetch fetch) : base(globals, fetch, init, null, null)
{
}
}