Permalink
Browse files

Fixing internals for when a remote has subtrees

Signed-off-by: Gordon Burgett <gordon.burgett@gmail.com>
  • Loading branch information...
gburgett committed Apr 9, 2013
1 parent fc1365d commit 4cfe68be057593557bbf40db01c0d1af55d571af
@@ -176,7 +176,7 @@ public virtual int GetRootChangesetForBranch(string tfsPathBranchToCreate, strin
}
}
- private ITfsChangeset BuildTfsChangeset(Changeset changeset, GitTfsRemote remote)
+ private ITfsChangeset BuildTfsChangeset(Changeset changeset, IGitTfsRemote remote)
{
var tfsChangeset = _container.With<ITfsHelper>(this).With<IChangeset>(_bridge.Wrap<WrapperForChangeset, Changeset>(changeset)).GetInstance<TfsChangeset>();
tfsChangeset.Summary = new TfsChangesetInfo { ChangesetId = changeset.ChangesetId, Remote = remote };
@@ -219,7 +219,7 @@ public void WithWorkspace(string localDirectory, IGitTfsRemote remote, IEnumerab
public void WithWorkspace(string localDirectory, IGitTfsRemote remote, TfsChangesetInfo versionToFetch, Action<ITfsWorkspace> action)
{
Trace.WriteLine("Setting up a TFS workspace at " + localDirectory);
- var workspace = GetWorkspace(new WorkingFolder(localDirectory, remote.TfsRepositoryPath));
+ var workspace = GetWorkspace(new WorkingFolder(remote.TfsRepositoryPath, localDirectory));
try
{
var tfsWorkspace = _container.With("localDirectory").EqualTo(localDirectory)
@@ -578,7 +578,7 @@ public IIdentity GetIdentity(string username)
return _bridge.Wrap<WrapperForIdentity, Identity>(GroupSecurityService.ReadIdentity(SearchFactor.AccountName, username, QueryMembership.None));
}
- public ITfsChangeset GetLatestChangeset(GitTfsRemote remote)
+ public ITfsChangeset GetLatestChangeset(IGitTfsRemote remote)
{
var history = VersionControl.QueryHistory(remote.TfsRepositoryPath, VersionSpec.Latest, 0,
RecursionType.Full, null, null, VersionSpec.Latest, 1, true, false,
@@ -595,7 +595,7 @@ public IChangeset GetChangeset(int changesetId)
return _bridge.Wrap<WrapperForChangeset, Changeset>(VersionControl.GetChangeset(changesetId));
}
- public ITfsChangeset GetChangeset(int changesetId, GitTfsRemote remote)
+ public ITfsChangeset GetChangeset(int changesetId, IGitTfsRemote remote)
{
return BuildTfsChangeset(VersionControl.GetChangeset(changesetId), remote);
}
@@ -50,7 +50,7 @@ public IIdentity GetIdentity(string username)
#region read changesets
- public ITfsChangeset GetLatestChangeset(GitTfsRemote remote)
+ public ITfsChangeset GetLatestChangeset(IGitTfsRemote remote)
{
return _script.Changesets.LastOrDefault().AndAnd(x => BuildTfsChangeset(x, remote));
}
@@ -60,7 +60,7 @@ public IEnumerable<ITfsChangeset> GetChangesets(string path, long startVersion,
return _script.Changesets.Where(x => x.Id >= startVersion).Select(x => BuildTfsChangeset(x, remote));
}
- private ITfsChangeset BuildTfsChangeset(ScriptedChangeset changeset, GitTfsRemote remote)
+ private ITfsChangeset BuildTfsChangeset(ScriptedChangeset changeset, IGitTfsRemote remote)
{
var tfsChangeset = _container.With<ITfsHelper>(this).With<IChangeset>(new Changeset(changeset)).GetInstance<TfsChangeset>();
tfsChangeset.Summary = new TfsChangesetInfo { ChangesetId = changeset.Id, Remote = remote };
@@ -185,6 +185,19 @@ TemporaryFile IItem.DownloadFile()
#region workspaces
+ public void WithWorkspace(string localDirectory, IGitTfsRemote remote, IEnumerable<Tuple<string, string>> mappings, TfsChangesetInfo versionToFetch, Action<ITfsWorkspace> action)
+ {
+ Trace.WriteLine("Setting up a TFS workspace at " + localDirectory);
+ var fakeWorkspace = new FakeWorkspace(localDirectory, remote.TfsRepositoryPath);
+ var workspace = _container.With("localDirectory").EqualTo(localDirectory)
+ .With("remote").EqualTo(remote)
+ .With("contextVersion").EqualTo(versionToFetch)
+ .With("workspace").EqualTo(fakeWorkspace)
+ .With("tfsHelper").EqualTo(this)
+ .GetInstance<TfsWorkspace>();
+ action(workspace);
+ }
+
public void WithWorkspace(string directory, IGitTfsRemote remote, TfsChangesetInfo versionToFetch, Action<ITfsWorkspace> action)
{
Trace.WriteLine("Setting up a TFS workspace at " + directory);
@@ -319,7 +332,7 @@ public ICheckinNote CreateCheckinNote(Dictionary<string, string> checkinNotes)
throw new NotImplementedException();
}
- public ITfsChangeset GetChangeset(int changesetId, GitTfsRemote remote)
+ public ITfsChangeset GetChangeset(int changesetId, IGitTfsRemote remote)
{
throw new NotImplementedException();
}
View
@@ -90,48 +90,39 @@ public int DoAdd(string tfsUrl, string tfsRepositoryPath)
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 tfsUri = new Uri(tfsUrl);
- IGitTfsRemote owner = _globals.Repository.ReadAllTfsRemotes().FirstOrDefault(x => !x.Id.StartsWith("subtree/") && tfsUri.Equals(x.TfsUrl));
+ IGitTfsRemote owner = _globals.Repository.ReadAllTfsRemotes().FirstOrDefault(x => string.IsNullOrEmpty(x.TfsRepositoryPath) && !x.Id.StartsWith("subtree/") && tfsUri.Equals(x.TfsUrl));
if (owner == null)
{
- try
- {
- owner = _globals.Repository.CreateTfsRemote(new RemoteInfo
- {
- Id = "origin",
- Url = tfsUrl,
- Repository = "",
- RemoteOptions = _remoteOptions
- });
- }
- catch (Exception)
+ owner = _globals.Repository.CreateTfsRemote(new RemoteInfo
{
- //need to clean up our subtree
- try
- {
- _globals.Repository.DeleteTfsRemote(remote);
- }
- catch
- {
-
- }
-
- throw;
- }
+ Id = "origin",
+ Url = tfsUrl,
+ Repository = null,
+ RemoteOptions = _remoteOptions
+ });
+ _stdout.WriteLine("-> new owning remote " + owner.Id);
+ }
+ else
+ {
+ _stdout.WriteLine("Attaching subtree to owning remote " + owner.Id);
}
-
+
+
+ //create a remote for the new subtree
+ string remoteId = "subtree/" + Prefix;
+ IGitTfsRemote remote = _globals.Repository.HasRemote(remoteId) ?
+ _globals.Repository.ReadTfsRemote(remoteId) :
+ _globals.Repository.CreateTfsRemote(new RemoteInfo
+ {
+ Id = remoteId,
+ Url = tfsUrl,
+ Repository = tfsRepositoryPath,
+ RemoteOptions = _remoteOptions,
+ });
+
+ _stdout.WriteLine("-> new remote " + remote.Id);
+
int result = fetch.Run(remote.Id);
if (result == GitTfsExitCodes.OK)
@@ -234,7 +234,7 @@ public void Apply(ITfsChangeset changeset, string destinationRef)
public void QuickFetch()
{
- var changeset = Tfs.GetLatestChangeset(this);
+ var changeset = GetLatestChangeset();
quickFetch(changeset);
}
@@ -256,16 +256,36 @@ private IEnumerable<ITfsChangeset> FetchChangesets()
{
Trace.WriteLine(RemoteRef + ": Getting changesets from " + (MaxChangesetId + 1) + " to current ...", "info");
// TFS 2010 doesn't like when we ask for history past its last changeset.
- if (MaxChangesetId == Tfs.GetLatestChangeset(this).Summary.ChangesetId)
+ if (MaxChangesetId == GetLatestChangeset().Summary.ChangesetId)
return Enumerable.Empty<ITfsChangeset>();
- return Tfs.GetChangesets(TfsRepositoryPath, MaxChangesetId + 1, this);
+
+ if(!string.IsNullOrEmpty(TfsRepositoryPath))
+ return Tfs.GetChangesets(TfsRepositoryPath, MaxChangesetId + 1, this);
+
+ return globals.Repository.GetSubtrees(this)
+ .SelectMany(x => Tfs.GetChangesets(x.TfsRepositoryPath, x.MaxChangesetId + 1, x))
+ .Distinct()
+ .OrderBy(x => x.Summary.ChangesetId);
}
public ITfsChangeset GetChangeset(long changesetId)
{
return Tfs.GetChangeset((int)changesetId, this);
}
+ private ITfsChangeset GetLatestChangeset()
+ {
+ if (!string.IsNullOrEmpty(this.TfsRepositoryPath))
+ {
+ return Tfs.GetLatestChangeset(this);
+ }
+ else
+ {
+ var changesetId = globals.Repository.GetSubtrees(this).Select(x => Tfs.GetLatestChangeset(x)).Max(x => x.Summary.ChangesetId);
+ return GetChangeset(changesetId);
+ }
+ }
+
public void UpdateRef(string commitHash, long changesetId)
{
MaxCommitHash = commitHash;
@@ -550,7 +570,7 @@ private void WithWorkspace(TfsChangesetInfo parentChangeset, Action<ITfsWorkspac
var subtrees = globals.Repository.GetSubtrees(this);
if (subtrees.Any())
{
- Tfs.WithWorkspace(WorkingDirectory, this, subtrees.Select(x => new Tuple<string, string>(x.Id.Substring("subtree/".Length), x.TfsRepositoryPath)), parentChangeset, action);
+ Tfs.WithWorkspace(WorkingDirectory, this, subtrees.Select(x => new Tuple<string, string>(x.TfsRepositoryPath, x.Id.Substring("subtree/".Length))), parentChangeset, action);
}
else
{
@@ -36,7 +36,7 @@ public IEnumerable<RemoteInfo> Load(IEnumerable<ConfigurationEntry<string>> conf
remote.Autotag = bool.Parse(entry.Value);
}
}
- return remotes.Values.Where(r => !string.IsNullOrWhiteSpace(r.Url) && !string.IsNullOrWhiteSpace(r.Repository));
+ return remotes.Values.Where(r => !string.IsNullOrWhiteSpace(r.Url));
}
public IEnumerable<KeyValuePair<string, string>> Dump(RemoteInfo remote)
@@ -9,7 +9,7 @@
namespace Sep.Git.Tfs.Core
{
- public class TfsChangeset : ITfsChangeset
+ public class TfsChangeset : ITfsChangeset, IEquatable<TfsChangeset>
{
private readonly ITfsHelper _tfs;
private readonly IChangeset _changeset;
@@ -287,5 +287,27 @@ private LogEntry MakeNewLogEntry(IChangeset changesetToLog)
AuthorEmail = email
};
}
+
+
+ public bool Equals(TfsChangeset other)
+ {
+ if (ReferenceEquals(null, other)) return false;
+ if (ReferenceEquals(this, other)) return true;
+
+ return this.Summary.ChangesetId == other.Summary.ChangesetId;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (TfsChangeset)) return false;
+ return Equals((TfsChangeset) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return (Summary != null ? Summary.ChangesetId.GetHashCode() : 0);
+ }
}
}
@@ -17,8 +17,8 @@ public interface ITfsHelper
IEnumerable<IWorkItemCheckedInfo> GetWorkItemCheckedInfos(IEnumerable<string> workItems, TfsWorkItemCheckinAction checkinAction);
ICheckinNote CreateCheckinNote(Dictionary<string, string> checkinNotes);
IIdentity GetIdentity(string username);
- ITfsChangeset GetLatestChangeset(GitTfsRemote remote);
- ITfsChangeset GetChangeset(int changesetId, GitTfsRemote remote);
+ ITfsChangeset GetLatestChangeset(IGitTfsRemote remote);
+ ITfsChangeset GetChangeset(int changesetId, IGitTfsRemote remote);
IChangeset GetChangeset(int changesetId);
bool HasShelveset(string shelvesetName);
ITfsChangeset GetShelvesetData(IGitTfsRemote remote, string shelvesetOwner, string shelvesetName);

0 comments on commit 4cfe68b

Please sign in to comment.