Skip to content

Commit

Permalink
Merge master and git-tfs#299.
Browse files Browse the repository at this point in the history
  • Loading branch information
spraints committed Feb 1, 2013
2 parents 0a155ff + 3b7b078 commit 04f8993
Show file tree
Hide file tree
Showing 14 changed files with 648 additions and 482 deletions.
15 changes: 7 additions & 8 deletions GitTfs/Commands/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,22 @@ public int Run()
var tfsRemotes = globals.Repository.ReadAllTfsRemotes();
if (DisplayRemotes)
{
WriteRemoteTfsBranchStructure(stdout, remoteId, tfsRemotes);
var remote = globals.Repository.ReadTfsRemote(remoteId);

stdout.WriteLine("\nTFS branch structure:");
WriteRemoteTfsBranchStructure(remote.Tfs, stdout, remote.TfsRepositoryPath, tfsRemotes);
return GitTfsExitCodes.OK;
}

WriteTfsRemoteDetails(stdout, tfsRemotes);
return GitTfsExitCodes.OK;
}

private void WriteRemoteTfsBranchStructure(TextWriter writer, string remoteId, IEnumerable<IGitTfsRemote> tfsRemotes)
public static void WriteRemoteTfsBranchStructure(ITfsHelper tfsHelper, TextWriter writer, string tfsRepositoryPath, IEnumerable<IGitTfsRemote> tfsRemotes = null)
{
writer.WriteLine("\nTFS branch structure:");

var repo = globals.Repository;
var remote = repo.ReadTfsRemote(remoteId);
var root = remote.Tfs.GetRootTfsBranchForRemotePath(remote.TfsRepositoryPath);
var root = tfsHelper.GetRootTfsBranchForRemotePath(tfsRepositoryPath);

var visitor = new WriteBranchStructureTreeVisitor(remote.TfsRepositoryPath, writer, tfsRemotes);
var visitor = new WriteBranchStructureTreeVisitor(tfsRepositoryPath, writer, tfsRemotes);
root.AcceptVisitor(visitor);
}

Expand Down
2 changes: 1 addition & 1 deletion GitTfs/Commands/Clone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Sep.Git.Tfs.Commands
{
[Pluggable("clone")]
[Description("clone [options] tfs-url-or-instance-name repository-path <git-repository-path>")]
[Description("clone [options] tfs-url-or-instance-name repository-path <git-repository-path>\n ex : git tfs clone http://myTfsServer:8080/tfs/TfsRepository $/ProjectName/ProjectBranch\n")]
public class Clone : GitTfsCommand
{
private readonly Fetch fetch;
Expand Down
68 changes: 68 additions & 0 deletions GitTfs/Commands/ListRemoteBranches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using NDesk.Options;
using StructureMap;
using Sep.Git.Tfs.Core;
using Sep.Git.Tfs.Core.TfsInterop;
using Sep.Git.Tfs.Util;

namespace Sep.Git.Tfs.Commands
{
[Pluggable("list-remote-branches")]
[Description("list-remote-branches tfs-url-or-instance-name \n git tfs list-remote-branches http://myTfsServer:8080/tfs/TfsRepository\n")]
public class ListRemoteBranches : GitTfsCommand
{
private readonly Globals globals;
private readonly ITfsHelper tfsHelper;
private readonly RemoteOptions remoteOptions;
private TextWriter stdout;

public ListRemoteBranches(Globals globals, TextWriter stdout, ITfsHelper tfsHelper, RemoteOptions remoteOptions)
{
this.globals = globals;
this.stdout = stdout;
this.tfsHelper = tfsHelper;
this.remoteOptions = remoteOptions;
}

public OptionSet OptionSet
{
get
{
return remoteOptions.OptionSet;
}
}

public int Run(string tfsUrl)
{
if (!tfsHelper.CanGetBranchInformation)
{
throw new GitTfsException("error: this version of TFS doesn't support this functionnality");
}

tfsHelper.Url = tfsUrl;
tfsHelper.Username = remoteOptions.Username;
tfsHelper.Password = remoteOptions.Password;
tfsHelper.EnsureAuthenticated();
var branches = tfsHelper.GetBranches().Where(b => b.IsRoot).ToList();
if (branches.IsEmpty())
{
stdout.WriteLine("No TFS branches were found!");
}
else
{
stdout.WriteLine("TFS branches that could be cloned:");
foreach (var branchObject in branches.Where(b => b.IsRoot))
{
Branch.WriteRemoteTfsBranchStructure(tfsHelper, stdout, branchObject.Path);
}
stdout.WriteLine("\nCloning root branches (marked by [*]) is recommended!");
}
return GitTfsExitCodes.OK;
}
}
}
4 changes: 3 additions & 1 deletion GitTfs/Commands/QuickClone.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.IO;
using StructureMap;

namespace Sep.Git.Tfs.Commands
Expand All @@ -7,7 +8,8 @@ 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, null)
public QuickClone(Globals globals, Init init, QuickFetch fetch, TextWriter stdout)
: base(globals, fetch, init, null, stdout)
{
}
}
Expand Down
16 changes: 9 additions & 7 deletions GitTfs/Core/RemoteConfigConverter.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using LibGit2Sharp;

namespace Sep.Git.Tfs.Core
{
public class RemoteConfigConverter
{
public IEnumerable<RemoteInfo> Load(IEnumerable<ConfigurationEntry> config)
public IEnumerable<RemoteInfo> Load(IEnumerable<ConfigurationEntry<string>> config)
{
var remotes = new Dictionary<string, RemoteInfo>();
foreach (var entry in config)
{
var keyParts = entry.Key.Split('.');
if (keyParts.Length == 3 && keyParts[0] == "tfs-remote")
if (keyParts.Length >= 3 && keyParts[0] == "tfs-remote")
{
var id = keyParts[1];
var key = keyParts[2];
// The branch name may contain dots ("maint-1.0.0") which must be considered since split on "."
var id = string.Join(".", keyParts, 1, keyParts.Length - 2);
var key = keyParts.Last();
var remote = remotes.GetOrAdd(id);
remote.Id = id;
if (key == "url")
Expand All @@ -37,7 +39,7 @@ public IEnumerable<RemoteInfo> Load(IEnumerable<ConfigurationEntry> config)
return remotes.Values;
}

public IEnumerable<ConfigurationEntry> Dump(RemoteInfo remote)
public IEnumerable<KeyValuePair<string, string>> Dump(RemoteInfo remote)
{
if (!string.IsNullOrWhiteSpace(remote.Id))
{
Expand All @@ -52,9 +54,9 @@ public IEnumerable<ConfigurationEntry> Dump(RemoteInfo remote)
}
}

private ConfigurationEntry c(string key, string value)
private KeyValuePair<string, string> c(string key, string value)
{
return new ConfigurationEntry(key, value, ConfigurationLevel.Local);
return new KeyValuePair<string, string>(key, value);
}
}
}
Loading

0 comments on commit 04f8993

Please sign in to comment.