private IGitTfsRemote FindOrInitTfsRemoteOfChangeset(int parentChangesetId, bool mergeChangeset, IRenameResult renameResult, out string omittedParentBranch)
{
omittedParentBranch = null;
IGitTfsRemote tfsRemote;
IChangeset parentChangeset = Tfs.GetChangeset(parentChangesetId);
//I think you want something that uses GetPathInGitRepo and ShouldSkip. See TfsChangeset.Apply.
//Don't know if there is a way to extract remote tfs repository path from changeset datas! Should be better!!!
var remote = Repository.ReadAllTfsRemotes().FirstOrDefault(r => parentChangeset.Changes.Any(c => r.GetPathInGitRepo(c.Item.ServerItem) != null));
if (remote != null)
tfsRemote = remote;
else
{
// If the changeset has created multiple folders, the expected branch folder will not always be the first
// so we scan all the changes of type folder to try to detect the first one which is a branch.
// In most cases it will change nothing: the first folder is the good one
IBranchObject tfsBranch = null;
string tfsPath = null;
var allBranches = Tfs.GetBranches(true);
foreach (var change in parentChangeset.Changes)
{
tfsPath = change.Item.ServerItem;
tfsPath = tfsPath.EndsWith("/") ? tfsPath : tfsPath + "/";
tfsBranch = allBranches.SingleOrDefault(b => tfsPath.StartsWith(b.Path.EndsWith("/") ? b.Path : b.Path + "/"));
if (tfsBranch != null)
{
// we found a branch, we stop here
break;
}
}
if (mergeChangeset && tfsBranch != null && Repository.GetConfig(GitTfsConstants.IgnoreNotInitBranches) == true.ToString())
{
Trace.TraceInformation("warning: skip not initialized branch for path " + tfsBranch.Path);
tfsRemote = null;
omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId;
}
else if (tfsBranch == null)
{
Trace.TraceInformation("error: branch not found. Verify that all the folders have been converted to branches (or something else :().\n\tpath {0}", tfsPath);
tfsRemote = null;
omittedParentBranch = ";C" + parentChangesetId;
}
else
{
tfsRemote = InitTfsRemoteOfChangeset(tfsBranch, parentChangeset.ChangesetId, renameResult);
if (tfsRemote == null)
omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId;
}
}
return tfsRemote;
}