AutoSelect remote only for command that need it

This commit is contained in:
Philippe Miossec
2014-04-20 02:38:27 +02:00
parent 7074fe1dde
commit f79dd99dc1
2 changed files with 51 additions and 39 deletions
+2 -37
View File
@@ -47,45 +47,9 @@ namespace Sep.Git.Tfs
var unparsedArgs = ParseOptions(command, args);
Trace.WriteLine("Command run:" + commandLineRun);
ParseAuthors();
AutoDetectRemoteToUse();
return Main(command, unparsedArgs);
}
private void AutoDetectRemoteToUse()
{
if (string.IsNullOrEmpty(_globals.UserSpecifiedRemoteId))
{
if (_globals.AutoFindRemote)
_stdout.WriteLine("info: Option '-I' is now the default behavior and is no more needed. It will be removed in the next version.");
var changesetsWithRemote = _globals.Repository.GetLastParentTfsCommits("HEAD");
if (!changesetsWithRemote.Any())
{
var allRemotes = _globals.Repository.ReadAllTfsRemotes();
if (!allRemotes.Any())
throw new Exception("error: no tfs remotes defined in this repository!");
if (allRemotes.Count() == 1)
{
_globals.UserSpecifiedRemoteId = allRemotes.First().Id;
_stdout.WriteLine("Working with tfs remote: " + _globals.RemoteId);
return;
}
throw new Exception("error: can't find a tfs remote to use\n No TFS parents found and more than one tfs remote defined in the repository!"
+ "\n Use '-i' option to define which one to use.");
}
var foundRemote = changesetsWithRemote.First().Remote;
if (foundRemote.IsDerived)
{
_stdout.WriteLine("Bootstraping tfs remote...");
foundRemote = _bootstrapper.CreateRemote(changesetsWithRemote.First());
}
_globals.UserSpecifiedRemoteId = foundRemote.Id;
_stdout.WriteLine("Working with tfs remote: " + _globals.RemoteId);
}
}
public int Main(GitTfsCommand command, IList<string> unparsedArgs)
{
Trace.WriteLine(_gitTfsVersionProvider.GetVersionString());
@@ -151,7 +115,8 @@ namespace Sep.Git.Tfs
{
_globals.GitDir = ".git";
}
_globals.RemoteId = GitTfsConstants.DefaultRepositoryId;
_globals.Stdout = _stdout;
_globals.Bootstrapper = _bootstrapper;
}
public void AssertValidGitRepository()
+49 -2
View File
@@ -2,6 +2,7 @@ using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using NDesk.Options;
using Sep.Git.Tfs.Core;
using Sep.Git.Tfs.Util;
@@ -63,13 +64,55 @@ namespace Sep.Git.Tfs
public string UserSpecifiedRemoteId
{
get { return _userSpecifiedRemoteId; }
set { RemoteId = _userSpecifiedRemoteId = value; }
set { _userSpecifiedRemoteId = value; }
}
private string _userSpecifiedRemoteId;
private string _activeRemoteId = null;
public string ActiveRemoteId
{
get
{
if (!string.IsNullOrEmpty(_activeRemoteId))
return _activeRemoteId;
if (!string.IsNullOrEmpty(UserSpecifiedRemoteId))
return UserSpecifiedRemoteId;
//if (AutoFindRemote)
// Stdout.WriteLine("info: Option '-I' is now the default behavior and is no more needed. It will be removed in the next version.");
var changesetsWithRemote = Repository.GetLastParentTfsCommits("HEAD");
if (!changesetsWithRemote.Any())
{
var allRemotes = Repository.ReadAllTfsRemotes();
if (!allRemotes.Any())
throw new Exception("error: no tfs remotes defined in this repository!");
if (allRemotes.Count() == 1)
{
_activeRemoteId = allRemotes.First().Id;
Stdout.WriteLine("Working with tfs remote: " + _activeRemoteId);
return _activeRemoteId;
}
throw new Exception("error: can't find a tfs remote to use\n No TFS parents found and more than one tfs remote defined in the repository!"
+ "\n Use '-i' option to define which one to use.");
}
var foundRemote = changesetsWithRemote.First().Remote;
if (foundRemote.IsDerived)
{
Stdout.WriteLine("Bootstraping tfs remote...");
foundRemote = Bootstrapper.CreateRemote(changesetsWithRemote.First());
}
_activeRemoteId = foundRemote.Id;
Stdout.WriteLine("Working with tfs remote: " + _activeRemoteId);
return _activeRemoteId;
}
}
public bool AutoFindRemote { get; set; }
public string RemoteId { get; set; }
public string RemoteId { get{ return ActiveRemoteId; } }
public string GitDir
{
@@ -110,5 +153,9 @@ For more information, see https://github.com/git-tfs/git-tfs/issues/448 ");
{
get { return 200; }
}
public TextWriter Stdout { get; set; }
public Bootstrapper Bootstrapper { get; set; }
}
}