Permalink
Browse files

Make the test fail like the bug report in #307.

  • Loading branch information...
spraints committed Feb 25, 2013
1 parent 4c3059a commit 27fe18ba7c5cbb4a818ae4111280fe48b453c388
@@ -25,7 +25,8 @@ public TfsHelper(IContainer container, TextWriter stdout, Script script)
_container = container;
_stdout = stdout;
_script = script;
- InitializeItemIds();
+ if(_script != null)
+ InitializeItemIds();
}
public string TfsClientLibraryVersion { get { return "(FAKE)"; } }
@@ -396,34 +397,30 @@ private void InitializeItemIds()
var current = new IdMap();
foreach (var changeset in _script.Changesets)
{
- current.Unchanged();
foreach (var change in changeset.Changes)
{
current.Update(change);
}
- _itemIds.Add(changeset.Id, current.Clone());
+ _itemIds.Add(changeset.Id, current);
+ current = new IdMap(current);
}
}
class IdMap
{
static int lastItemId = 0;
+ IdMap previousMap;
Dictionary<int, string> idToPath = new Dictionary<int, string>();
Dictionary<string, int> pathToId = new Dictionary<string, int>();
- List<int> changedItems = new List<int>();
public int this[ScriptedChange change] { get { return this[change.RepositoryPath]; } }
- public int this[string path] { get { return pathToId[path]; } }
- public string this[int id] { get { return idToPath[id]; } }
- //public IEnumerable<string> ChangedPaths { get
+ public int this[string path] { get { return pathToId.ContainsKey(path) ? pathToId[path] : previousMap[path]; } }
+ public string this[int id] { get { return idToPath.ContainsKey(id) ? idToPath[id] : previousMap[id]; } }
- /// <summary>
- /// Resets all the change indicators.
- /// </summary>
- public void Unchanged()
+ public IdMap(IdMap previousMap = null)
{
- changedItems = new List<int>();
+ this.previousMap = previousMap;
}
/// <summary>
@@ -437,31 +434,24 @@ public void Update(ScriptedChange change)
var id = ++lastItemId;
pathToId.Add(change.RepositoryPath, id);
idToPath.Add(id, change.RepositoryPath);
- changedItems.Add(id);
}
else if (change.ChangeType.IncludesOneOf(TfsChangeType.Rename))
{
- var renamedItemId = pathToId[change.RenamedFrom];
- pathToId.Remove(change.RenamedFrom);
+ var renamedItemId = previousMap[change.RenamedFrom];
pathToId.Add(change.RepositoryPath, renamedItemId);
- changedItems.Add(renamedItemId);
+ idToPath.Add(renamedItemId, change.RepositoryPath);
}
else if (change.ChangeType.IncludesOneOf(TfsChangeType.Delete))
{
- var deletedItemId = pathToId[change.RepositoryPath];
- pathToId.Remove(change.RepositoryPath);
- idToPath.Remove(deletedItemId);
- changedItems.Add(deletedItemId);
+ // Do nothing.
+ // This isn't strictly "correct", but it is good enough for the tests.
}
}
- public IdMap Clone()
+ public string Inspect()
{
- var clone = new IdMap();
- clone.idToPath = new Dictionary<int, string>(idToPath);
- clone.pathToId = new Dictionary<string, int>(pathToId);
- clone.changedItems = new List<int>(changedItems);
- return clone;
+ var s = idToPath.Select(x => String.Format("{0} - {1}\n", x.Key, x.Value)).Aggregate("", (s1, s2) => s1 + s2);
+ return (previousMap == null ? "" : previousMap.Inspect() + "^^^^\n") + s;
}
}
@@ -161,7 +161,7 @@ public void CloneWithRenames()
r.Changeset(2, "Add A and B", DateTime.Now)
.Change(TfsChangeType.Add, TfsItemType.File, "$/MyProject/A", "original contents of A")
.Change(TfsChangeType.Add, TfsItemType.File, "$/MyProject/B", "original contents of B");
- r.Changeset(3, "Rename", DateTime.Now)
+ r.Changeset(3, "Rename A->C, B->A", DateTime.Now)
.Rename(TfsItemType.File, from: "$/MyProject/A", to: "$/MyProject/C")
.Rename(TfsItemType.File, from: "$/MyProject/B", to: "$/MyProject/A");
});
@@ -170,5 +170,25 @@ public void CloneWithRenames()
h.AssertFileInWorkspace("MyProject", "C", "original contents of A");
h.AssertFileInWorkspace("MyProject", "A", "original contents of B");
}
+
+ [FactExceptOnUnix]
+ public void CloneWithRenamesInTheOtherOrder()
+ {
+ h.SetupFake(r =>
+ {
+ r.Changeset(1, "Project created from template", DateTime.Now)
+ .Change(TfsChangeType.Add, TfsItemType.Folder, "$/MyProject");
+ r.Changeset(2, "Add A and B", DateTime.Now)
+ .Change(TfsChangeType.Add, TfsItemType.File, "$/MyProject/A", "original contents of A")
+ .Change(TfsChangeType.Add, TfsItemType.File, "$/MyProject/B", "original contents of B");
+ r.Changeset(3, "Rename A->B, B->C", DateTime.Now)
+ .Rename(TfsItemType.File, from: "$/MyProject/A", to: "$/MyProject/B")
+ .Rename(TfsItemType.File, from: "$/MyProject/B", to: "$/MyProject/C");
+ });
+ h.Run("clone", h.TfsUrl, "$/MyProject");
+ h.AssertGitRepo("MyProject");
+ h.AssertFileInWorkspace("MyProject", "B", "original contents of A");
+ h.AssertFileInWorkspace("MyProject", "C", "original contents of B");
+ }
}
}
@@ -236,7 +236,17 @@ public void ChangeConfigSetting(string repodir, string key, string value)
public int GetCommitCount(string repodir)
{
var repo = new LibGit2Sharp.Repository(Path.Combine(Workdir, repodir));
- return repo.Commits.Count();
+ return Repository(repodir).Commits.Count();
+ }
+
+ public void WhatChanged(string repodir, bool showDiff = false)
+ {
+ var whatchanged = new ProcessStartInfo();
+ whatchanged.UseShellExecute = false;
+ whatchanged.FileName = "git";
+ whatchanged.Arguments = "--git-dir=" + Repository(repodir).Info.Path + " whatchanged" + (showDiff ? " -p" : "");
+ var p = Process.Start(whatchanged);
+ p.WaitForExit();
}
public void AssertGitRepo(string repodir)

0 comments on commit 27fe18b

Please sign in to comment.