Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: gburgett/git-tfs
...
head fork: gburgett/git-tfs
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
159 GitTfs/Commands/Subtree.cs
@@ -0,0 +1,159 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Text;
+using NDesk.Options;
+using Sep.Git.Tfs.Core;
+using StructureMap;
+
+namespace Sep.Git.Tfs.Commands
+{
+ [Pluggable("subtree")]
+ [Description("subtree [add|pull|split] [options] [remote | ( [tfs-url] [repository-path] )]")]
+ [RequiresValidGitRepository]
+ public class Subtree : GitTfsCommand
+ {
+
+ private readonly TextWriter _stdout;
+ private readonly Fetch _fetch;
+ private readonly QuickFetch _quickFetch;
+ private readonly Globals _globals;
+ private readonly RemoteOptions _remoteOptions;
+
+ private string Prefix;
+ private bool Squash = false;
+
+ public OptionSet OptionSet
+ {
+ get
+ {
+ return new OptionSet
+ {
+ { "p|prefix=",
+ v => Prefix = v},
+ { "squash",
+ v => Squash = v != null}
+ // { "r|revision=",
+ // v => RevisionToFetch = Convert.ToInt32(v) },
+ }
+ .Merge(_fetch.OptionSet);
+ }
+ }
+
+ public Subtree(TextWriter stdout, Fetch fetch, QuickFetch quickFetch, Globals globals, RemoteOptions remoteOptions)
+ {
+ this._stdout = stdout;
+ this._fetch = fetch;
+ this._quickFetch = quickFetch;
+ this._globals = globals;
+ this._remoteOptions = remoteOptions;
+ }
+
+ public int Run(IList<string> args)
+ {
+ string command = args.FirstOrDefault() ?? "";
+ _stdout.WriteLine("executing subtree " + command);
+
+ if (string.IsNullOrEmpty(Prefix))
+ {
+ _stdout.WriteLine("Prefix must be specified, use -p or -prefix");
+ return GitTfsExitCodes.InvalidArguments;
+ }
+
+ switch (command.ToLower())
+ {
+ case "add":
+ return DoAdd(args.ElementAtOrDefault(1) ?? "", args.ElementAtOrDefault(2) ?? "");
+ break;
+
+ case "pull":
+ return DoPull(args.ElementAtOrDefault(1));
+
+
+ default:
+ _stdout.WriteLine("Expected one of [add, pull, merge, split]");
+ return GitTfsExitCodes.InvalidArguments;
+ break;
+ }
+ }
+
+ public int DoAdd(string tfsUrl, string tfsRepositoryPath)
+ {
+ if (File.Exists(Prefix) || Directory.Exists(Prefix))
+ {
+ _stdout.WriteLine(string.Format("Directory {0} already exists", Prefix));
+ return GitTfsExitCodes.InvalidArguments;
+ }
+
+
+ var fetch = Squash ? this._quickFetch : this._fetch;
+
+
+ //create a remote for the new subtree
+ string remoteId = "subtree/" + Prefix;
+ IGitTfsRemote remote = _globals.Repository.CreateTfsRemote(new RemoteInfo
+ {
+ Id = remoteId,
+ Url = tfsUrl,
+ Repository = tfsRepositoryPath,
+ RemoteOptions = _remoteOptions,
+ });
+ _stdout.WriteLine("-> new remote " + remote.Id);
+
+
+ var parentRemote = _globals.Repository.
+
+ int result = fetch.Run(remote.Id);
+
+ if (result == GitTfsExitCodes.OK)
+ {
+ var p = Prefix.Replace(" ", "\\ ");
+ List<string> args = new List<string>(){"subtree", "add", "--prefix=" + p, remote.RemoteRef};
+ if (Squash)
+ {
+ args.Add("--squash");
+ }
+ command(args);
+
+ result = GitTfsExitCodes.OK;
+ }
+
+ return result;
+ }
+
+ public int DoPull(string remoteId)
+ {
+ if (!Directory.Exists(Prefix))
+ {
+ _stdout.WriteLine("You must first add the subtree using 'git tfs subtree add -p=<prefix> [tfs-server] [tfs-repository]'");
+ return GitTfsExitCodes.InvalidArguments;
+ }
+
+ remoteId = remoteId ?? "subtree/" + Prefix;
+ IGitTfsRemote remote = _globals.Repository.ReadTfsRemote(remoteId);
+
+ int result = this._fetch.Run(remote.Id);
+ if (result == GitTfsExitCodes.OK)
+ {
+ var p = Prefix.Replace(" ", "\\ ");
+ List<string> args = new List<string>(){ "subtree", "merge", "--prefix=" + p, remote.RemoteRef };
+ if(Squash)
+ {
+ args.Add("--squash");
+ }
+ command(args);
+ result = GitTfsExitCodes.OK;
+ }
+
+ return result;
+ }
+
+ private void command(List<string> args)
+ {
+ _stdout.WriteLine("git " + string.Join(" ", args));
+ _globals.Repository.CommandNoisy(args.ToArray());
+ }
+ }
+}
View
11 GitTfs/Core/RemoteInfo.cs
@@ -17,6 +17,17 @@ public class RemoteInfo
public IEnumerable<string> Aliases { get; set; }
public bool Autotag { get; set; }
+ /// <summary>
+ /// Gets or sets the list of other remotes which have been added as subtrees under this remote.
+ /// All subtrees will have the same <see cref="Url"/> as this remote.
+ /// </summary>
+ /// <remarks>
+ /// We track subtree remotes in this way so that a "git tfs pull" or a "git tfs checkin" will pull
+ /// all known subtrees as well. This facilitates a git repo which contains multiple TFS projects on the
+ /// same server.
+ /// </remarks>
+ public List<string> Subtrees { get; set; }
+
public RemoteOptions RemoteOptions
{
get { return new RemoteOptions { IgnoreRegex = IgnoreRegex, Username = Username, Password = Password }; }
View
5 GitTfs/GitTfs.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -131,6 +131,7 @@
<Link>Properties\Version.cs</Link>
</Compile>
<Compile Include="Commands\ListRemoteBranches.cs" />
+ <Compile Include="Commands\Subtree.cs" />
<Compile Include="Core\DirectoryTidier.cs" />
<Compile Include="Core\ITfsWorkitem.cs" />
<Compile Include="Commands\Branch.cs" />
@@ -301,4 +302,4 @@
</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
-</Project>
+</Project>

No commit comments for this range

Something went wrong with that request. Please try again.