public virtual void RepositoryWithSubmodule() { WriteTrashFile("file.txt", "content"); Git git = Git.Wrap(db); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("create file").Call(); ObjectId id = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); string path = "sub"; DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_96(id, path)); editor.Commit(); FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants .DOT_GIT_MODULES), db.FileSystem); modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants .CONFIG_KEY_PATH, path); string url = "git://server/repo.git"; modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants .CONFIG_KEY_URL, url); modulesConfig.Save(); Repository subRepo = Git.CloneRepository().SetURI(db.Directory.ToURI().ToString() ).SetDirectory(new FilePath(db.WorkTree, path)).Call().GetRepository(); AddRepoToClose(subRepo); NUnit.Framework.Assert.IsNotNull(subRepo); SubmoduleWalk generator = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.IsNull(generator.GetConfigUrl()); NUnit.Framework.Assert.AreEqual(url, generator.GetModulesUrl()); SubmoduleSyncCommand command = new SubmoduleSyncCommand(db); IDictionary <string, string> synced = command.Call(); NUnit.Framework.Assert.IsNotNull(synced); NUnit.Framework.Assert.AreEqual(1, synced.Count); KeyValuePair <string, string> module = synced.EntrySet().Iterator().Next(); NUnit.Framework.Assert.AreEqual(path, module.Key); NUnit.Framework.Assert.AreEqual(url, module.Value); generator = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(url, generator.GetConfigUrl()); Repository subModRepository = generator.GetRepository(); AddRepoToClose(subModRepository); StoredConfig submoduleConfig = subModRepository.GetConfig(); NUnit.Framework.Assert.AreEqual(url, submoduleConfig.GetString(ConfigConstants.CONFIG_REMOTE_SECTION , Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL)); }
public virtual void TestConflicting() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); // create side branch with two modifications CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); WriteTrashFile("a", "1\na(side)\n3\n"); WriteTrashFile("b", "1\nb\n3\n(side)"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); // update a on master to generate conflict CheckoutBranch("refs/heads/master"); WriteTrashFile("a", "1\na(main)\n3\n"); git.Add().AddFilepattern("a").Call(); git.Commit().SetMessage("main").Call(); // merge side with master MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus()); FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); diff.Diff(); NUnit.Framework.CollectionAssert.AreEqual("[b]", new TreeSet <string>(diff.GetChanged()).ToString ()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetAdded()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetRemoved()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetMissing()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetModified()); NUnit.Framework.Assert.AreEqual("a", diff.GetConflicting().First()); NUnit.Framework.Assert.AreEqual(1, diff.GetConflicting().Count()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetUntrackedFolders()); }
public virtual void ResolveExprSimple() { Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("create file").Call(); NUnit.Framework.Assert.AreEqual("master", db.Simplify("master")); NUnit.Framework.Assert.AreEqual("refs/heads/master", db.Simplify("refs/heads/master" )); NUnit.Framework.Assert.AreEqual("HEAD", db.Simplify("HEAD")); }
public virtual void FailingPathsShouldNotResultInOKReturnValue(MergeStrategy strategy ) { FilePath folder1 = new FilePath(db.WorkTree, "folder1"); FileUtils.Mkdir(folder1); FilePath file = new FilePath(folder1, "file1.txt"); Write(file, "folder1--file1.txt"); file = new FilePath(folder1, "file2.txt"); Write(file, "folder1--file2.txt"); Git git = new Git(db); git.Add().AddFilepattern(folder1.GetName()).Call(); RevCommit @base = git.Commit().SetMessage("adding folder").Call(); RecursiveDelete(folder1); git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt"). Call(); RevCommit other = git.Commit().SetMessage("removing folders on 'other'").Call(); git.Checkout().SetName(@base.Name).Call(); file = new FilePath(db.WorkTree, "unrelated.txt"); Write(file, "unrelated"); git.Add().AddFilepattern("unrelated.txt").Call(); RevCommit head = git.Commit().SetMessage("Adding another file").Call(); // Untracked file to cause failing path for delete() of folder1 file = new FilePath(folder1, "file3.txt"); Write(file, "folder1--file3.txt"); ResolveMerger merger = (ResolveMerger)strategy.NewMerger(db, false); merger.SetCommitNames(new string[] { "BASE", "HEAD", "other" }); merger.SetWorkingTreeIterator(new FileTreeIterator(db)); bool ok = merger.Merge(head.Id, other.Id); NUnit.Framework.Assert.IsFalse(merger.GetFailingPaths().IsEmpty()); NUnit.Framework.Assert.IsFalse(ok); }
private void CommitRemoteRepository(string remoteRepository) { Git git = Git.Open(remoteRepository); try { git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Commit message").Call(); } finally { git.GetRepository().Close(); } }
public virtual void TestSameDiff() { Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test"); FilePath folder = new FilePath(db.Directory.GetParent(), "folder"); folder.Mkdir(); Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder"); Git git = new Git(db); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder change"); PatchIdDiffFormatter df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId ().Name); Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder"); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder change"); df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); oldTree = new DirCacheIterator(db.ReadDirCache()); newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId ().Name); }
public virtual void TestDirtyFileModeEqualIndexMerge() { if (!FS.DETECTED.SupportsExecute()) { return; } Git git = Git.Wrap(db); // Add non-executable file FilePath file = WriteTrashFile("file.txt", "a"); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("commit1").Call(); NUnit.Framework.Assert.IsFalse(db.FileSystem.CanExecute(file)); // Create branch git.BranchCreate().SetName("b1").Call(); // Create second commit with executable file file = WriteTrashFile("file.txt", "b"); db.FileSystem.SetExecute(file, true); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("commit2").Call(); // stage the same content as in the branch we want to switch to WriteTrashFile("file.txt", "a"); db.FileSystem.SetExecute(file, false); git.Add().AddFilepattern("file.txt").Call(); // dirty the file WriteTrashFile("file.txt", "c"); db.FileSystem.SetExecute(file, true); NUnit.Framework.Assert.AreEqual("[file.txt, mode:100644, content:a]", IndexState( CONTENT)); AssertWorkDir(Mkmap("file.txt", "c")); // Switch branches and check that the dirty file survived in worktree // and index git.Checkout().SetName("b1").Call(); NUnit.Framework.Assert.AreEqual("[file.txt, mode:100644, content:a]", IndexState( CONTENT)); AssertWorkDir(Mkmap("file.txt", "c")); }
public virtual void TestUnchangedComplex() { Git git = new Git(db); WriteTrashFile("a.b", "a.b"); WriteTrashFile("a.c", "a.c"); WriteTrashFile("a/b.b/b", "a/b.b/b"); WriteTrashFile("a/b", "a/b"); WriteTrashFile("a/c", "a/c"); WriteTrashFile("a=c", "a=c"); WriteTrashFile("a=d", "a=d"); git.Add().AddFilepattern("a.b").AddFilepattern("a.c").AddFilepattern("a/b.b/b").AddFilepattern ("a/b").AddFilepattern("a/c").AddFilepattern("a=c").AddFilepattern("a=d").Call(); Tree tree = new Tree(db); // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851" )); tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca" )); tree.AddFile("a/b.b/b").SetId(ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd" )); tree.AddFile("a/b").SetId(ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415" )); tree.AddFile("a/c").SetId(ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007" )); tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714" )); tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2" )); Tree tree3 = (Tree)tree.FindTreeMember("a/b.b"); tree3.SetId(InsertTree(tree3)); Tree tree2 = (Tree)tree.FindTreeMember("a"); tree2.SetId(InsertTree(tree2)); tree.SetId(InsertTree(tree)); FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator); diff.Diff(); NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count); NUnit.Framework.Assert.AreEqual(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders() ); }
public virtual void CheckLockedFilesToBeDeleted(MergeStrategy strategy) { Git git = Git.Wrap(db); WriteTrashFile("a.txt", "orig"); WriteTrashFile("b.txt", "orig"); git.Add().AddFilepattern("a.txt").AddFilepattern("b.txt").Call(); RevCommit first = git.Commit().SetMessage("added a.txt, b.txt").Call(); // modify and delete files on the master branch WriteTrashFile("a.txt", "master"); git.Rm().AddFilepattern("b.txt").Call(); RevCommit masterCommit = git.Commit().SetMessage("modified a.txt, deleted b.txt") .SetAll(true).Call(); // switch back to a side branch git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call(); WriteTrashFile("c.txt", "side"); git.Add().AddFilepattern("c.txt").Call(); git.Commit().SetMessage("added c.txt").Call(); // Get a handle to the the file so on windows it can't be deleted. FileInputStream fis = new FileInputStream(new FilePath(db.WorkTree, "b.txt")); MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit ).Call(); if (mergeRes.GetMergeStatus().Equals(MergeStatus.FAILED)) { // probably windows NUnit.Framework.Assert.AreEqual(1, mergeRes.GetFailingPaths().Count); NUnit.Framework.Assert.AreEqual(ResolveMerger.MergeFailureReason.COULD_NOT_DELETE , mergeRes.GetFailingPaths().Get("b.txt")); } NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:master]" + "[c.txt, mode:100644, content:side]" , IndexState(CONTENT)); fis.Close(); }
public virtual void CheckMergeConflictingFilesWithTreeInIndex(MergeStrategy strategy ) { Git git = Git.Wrap(db); WriteTrashFile("0", "orig"); git.Add().AddFilepattern("0").Call(); RevCommit first = git.Commit().SetMessage("added 0").Call(); WriteTrashFile("0", "master"); RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified 0 on master" ).Call(); git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call(); WriteTrashFile("0", "side"); git.Commit().SetAll(true).SetMessage("modified 0 on side").Call(); git.Rm().AddFilepattern("0").Call(); WriteTrashFile("0/0", "side"); git.Add().AddFilepattern("0/0").Call(); MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit ).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.FAILED, mergeRes.GetMergeStatus()); }
public virtual void TestAssumeUnchanged() { Git git = new Git(db); string path = "file"; WriteTrashFile(path, "content"); git.Add().AddFilepattern(path).Call(); string path2 = "file2"; WriteTrashFile(path2, "content"); git.Add().AddFilepattern(path2).Call(); git.Commit().SetMessage("commit").Call(); AssumeUnchanged(path2); WriteTrashFile(path, "more content"); WriteTrashFile(path2, "more content"); FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); diff.Diff(); NUnit.Framework.Assert.AreEqual(1, diff.GetAssumeUnchanged().Count); NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count); NUnit.Framework.Assert.IsTrue(diff.GetAssumeUnchanged().Contains("file2")); NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("file")); git.Add().AddFilepattern(".").Call(); iterator = new FileTreeIterator(db); diff = new IndexDiff(db, Constants.HEAD, iterator); diff.Diff(); NUnit.Framework.Assert.AreEqual(1, diff.GetAssumeUnchanged().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count); NUnit.Framework.Assert.AreEqual(1, diff.GetChanged().Count); NUnit.Framework.Assert.IsTrue(diff.GetAssumeUnchanged().Contains("file2")); NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file")); NUnit.Framework.Assert.AreEqual(Sharpen.Collections <string> .EMPTY_SET, diff.GetUntrackedFolders ()); }
public virtual void TestUnchangedSimple() { WriteTrashFile("a.b", "a.b"); WriteTrashFile("a.c", "a.c"); WriteTrashFile("a=c", "a=c"); WriteTrashFile("a=d", "a=d"); Git git = new Git(db); git.Add().AddFilepattern("a.b").Call(); git.Add().AddFilepattern("a.c").Call(); git.Add().AddFilepattern("a=c").Call(); git.Add().AddFilepattern("a=d").Call(); Tree tree = new Tree(db); // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851" )); tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca" )); tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714" )); tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2" )); tree.SetId(InsertTree(tree)); FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator); diff.Diff(); NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count); NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count); NUnit.Framework.Assert.AreEqual(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders() ); }
public virtual void TestRemovedUntracked() { Git git = new Git(db); string path = "file"; WriteTrashFile(path, "content"); git.Add().AddFilepattern(path).Call(); git.Commit().SetMessage("commit").Call(); RemoveFromIndex(path); FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); diff.Diff(); NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains(path)); NUnit.Framework.Assert.IsTrue(diff.GetUntracked().Contains(path)); }
public virtual void ResolveDate() { Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("create file").Call(); try { db.Resolve("master@{yesterday}"); NUnit.Framework.Assert.Fail("Exception not thrown"); } catch (RevisionSyntaxException e) { NUnit.Framework.Assert.IsNotNull(e); } }
public virtual void AddSubmoduleWithRelativeUri() { Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit = git.Commit().SetMessage("create file").Call(); SubmoduleAddCommand command = new SubmoduleAddCommand(db); string path = "sub"; string uri = "./.git"; command.SetPath(path); command.SetURI(uri); Repository repo = command.Call(); NUnit.Framework.Assert.IsNotNull(repo); AddRepoToClose(repo); SubmoduleWalk generator = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(path, generator.GetPath()); NUnit.Framework.Assert.AreEqual(commit, generator.GetObjectId()); NUnit.Framework.Assert.AreEqual(uri, generator.GetModulesUrl()); NUnit.Framework.Assert.AreEqual(path, generator.GetModulesPath()); string fullUri = db.Directory.GetAbsolutePath(); if (FilePath.separatorChar == '\\') { fullUri = fullUri.Replace('\\', '/'); } NUnit.Framework.Assert.AreEqual(fullUri, generator.GetConfigUrl()); Repository subModRepo = generator.GetRepository(); AddRepoToClose(subModRepo); NUnit.Framework.Assert.IsNotNull(subModRepo); NUnit.Framework.Assert.AreEqual(fullUri, subModRepo.GetConfig().GetString(ConfigConstants .CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL )); NUnit.Framework.Assert.AreEqual(commit, repo.Resolve(Constants.HEAD)); Status status = Git.Wrap(db).Status().Call(); NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(Constants.DOT_GIT_MODULES )); NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path)); }
private bool GenerateRepository(string dirName) { git.WorkingDir = $"{Directory.GetCurrentDirectory()}/{dirName}"; if (!git.Init()) { return(false); } var readme = $"{dirName}/README.md"; using (var writer = File.CreateText(readme)) { writer.WriteLine($"# {packageName}"); writer.WriteLine("Upload this entire package to GitHub or some other hosting site. You can then add it " + "to a unity project by going into `Window -> Package Manager -> + -> Add Package From git URL...`."); } return(git.Add("README.md") && git.Commit("Initialized Repository")); }
public virtual void TestIsModifiedSymlink() { FilePath f = WriteTrashFile("symlink", "content"); Git git = new Git(db); git.Add().AddFilepattern("symlink").Call(); git.Commit().SetMessage("commit").Call(); // Modify previously committed DirCacheEntry and write it back to disk DirCacheEntry dce = db.ReadDirCache().GetEntry("symlink"); dce.FileMode = FileMode.SYMLINK; DirCacheCheckout.CheckoutEntry(db, f, dce); FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig )db.GetConfig()).Get(WorkingTreeOptions.KEY)); while (!fti.EntryPathString.Equals("symlink")) { fti.Next(1); } NUnit.Framework.Assert.IsFalse(fti.IsModified(dce, false)); }
public void AddTest() { string command = null; string arguments = null; var processManager = Container.Resolve <IProcessManager>(); processManager.Arrange(p => p.Start(Arg.IsAny <ProcessStartInfo>())) .Returns((ProcessStartInfo info) => { command = info.FileName; arguments = info.Arguments; return(new FakeProcess()); }); var instance = new Git(); var code = instance.Add("packages.config"); Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code"); Assert.AreEqual("git", command); Assert.AreEqual("add packages.config", arguments); }
public virtual void RepositoryWithSubmodule() { WriteTrashFile("file.txt", "content"); Git git = Git.Wrap(db); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit = git.Commit().SetMessage("create file").Call(); string path = "sub"; DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_94(commit, path)); editor.Commit(); StoredConfig config = ((FileBasedConfig)db.GetConfig()); config.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants. CONFIG_KEY_URL, db.Directory.ToURI().ToString()); config.Save(); FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants .DOT_GIT_MODULES), db.FileSystem); modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants .CONFIG_KEY_PATH, path); modulesConfig.Save(); SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db); ICollection <string> updated = command.Call(); NUnit.Framework.Assert.IsNotNull(updated); NUnit.Framework.Assert.AreEqual(1, updated.Count); NUnit.Framework.Assert.AreEqual(path, updated.Iterator().Next()); SubmoduleWalk generator = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(generator.Next()); Repository subRepo = generator.GetRepository(); AddRepoToClose(subRepo); NUnit.Framework.Assert.IsNotNull(subRepo); NUnit.Framework.Assert.AreEqual(commit, subRepo.Resolve(Constants.HEAD)); }
public virtual void AddSubmoduleWithExistingSubmoduleDefined() { string path1 = "sub1"; string url1 = "git://server/repo1.git"; string path2 = "sub2"; FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants .DOT_GIT_MODULES), db.FileSystem); modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path1, ConfigConstants .CONFIG_KEY_PATH, path1); modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path1, ConfigConstants .CONFIG_KEY_URL, url1); modulesConfig.Save(); Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("create file").Call()); SubmoduleAddCommand command = new SubmoduleAddCommand(db); command.SetPath(path2); string url2 = db.Directory.ToURI().ToString(); command.SetURI(url2); Repository r = command.Call(); NUnit.Framework.Assert.IsNotNull(r); AddRepoToClose(r); modulesConfig.Load(); NUnit.Framework.Assert.AreEqual(path1, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION , path1, ConfigConstants.CONFIG_KEY_PATH)); NUnit.Framework.Assert.AreEqual(url1, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION , path1, ConfigConstants.CONFIG_KEY_URL)); NUnit.Framework.Assert.AreEqual(path2, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION , path2, ConfigConstants.CONFIG_KEY_PATH)); NUnit.Framework.Assert.AreEqual(url2, modulesConfig.GetString(ConfigConstants.CONFIG_SUBMODULE_SECTION , path2, ConfigConstants.CONFIG_KEY_URL)); }
public virtual void ShouldListModificationInDirWithModifiedTrees() { // given Git git = new Git(db); FilePath tree = new FilePath(new FilePath(db.WorkTree, "a"), "b"); FileUtils.Mkdirs(tree); FilePath file = new FilePath(tree, "c.txt"); FileUtils.CreateNewFile(file); Write(file, "content"); git.Add().AddFilepattern("a").Call(); RevCommit c1 = git.Commit().SetMessage("initial commit").Call(); Write(file, "new line"); RevCommit c2 = git.Commit().SetAll(true).SetMessage("second commit").Call(); // when TreeWalk walk = new TreeWalk(db); walk.AddTree(c1.Tree); walk.AddTree(c2.Tree); IList <DiffEntry> result = DiffEntry.Scan(walk, true); // then Assert.IsNotNull(result); Assert.AreEqual(3, result.Count);; DiffEntry entry = result[0]; Assert.AreEqual(entry.GetChangeType(), DiffEntry.ChangeType.MODIFY); Assert.AreEqual(entry.GetNewPath(), "a"); entry = result[1]; Assert.AreEqual(entry.GetChangeType(), DiffEntry.ChangeType.MODIFY); Assert.AreEqual(entry.GetNewPath(), "a/b"); entry = result[2]; Assert.AreEqual(entry.GetChangeType(), DiffEntry.ChangeType.MODIFY); Assert.AreEqual(entry.GetNewPath(), "a/b/c.txt"); }
public virtual void TestUntrackedFolders() { Git git = new Git(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); diff.Diff(); NUnit.Framework.Assert.AreEqual(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders() ); WriteTrashFile("readme", string.Empty); WriteTrashFile("src/com/A.java", string.Empty); WriteTrashFile("src/com/B.java", string.Empty); WriteTrashFile("src/org/A.java", string.Empty); WriteTrashFile("src/org/B.java", string.Empty); WriteTrashFile("target/com/A.java", string.Empty); WriteTrashFile("target/com/B.java", string.Empty); WriteTrashFile("target/org/A.java", string.Empty); WriteTrashFile("target/org/B.java", string.Empty); git.Add().AddFilepattern("src").AddFilepattern("readme").Call(); git.Commit().SetMessage("initial").Call(); diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); diff.Diff(); NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet <string>(Arrays.AsList("target")), diff .GetUntrackedFolders()); WriteTrashFile("src/tst/A.java", string.Empty); WriteTrashFile("src/tst/B.java", string.Empty); diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); diff.Diff(); NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet <string>(Arrays.AsList("target", "src/tst" )), diff.GetUntrackedFolders()); git.Rm().AddFilepattern("src/com/B.java").AddFilepattern("src/org").Call(); git.Commit().SetMessage("second").Call(); WriteTrashFile("src/org/C.java", string.Empty); diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); diff.Diff(); NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet <string>(Arrays.AsList("src/org", "src/tst" , "target")), diff.GetUntrackedFolders()); }
public virtual void AddSubmodule() { Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit = git.Commit().SetMessage("create file").Call(); SubmoduleAddCommand command = new SubmoduleAddCommand(db); string path = "sub"; command.SetPath(path); string uri = db.Directory.ToURI().ToString(); command.SetURI(uri); Repository repo = command.Call(); NUnit.Framework.Assert.IsNotNull(repo); AddRepoToClose(repo); SubmoduleWalk generator = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(path, generator.GetPath()); NUnit.Framework.Assert.AreEqual(commit, generator.GetObjectId()); NUnit.Framework.Assert.AreEqual(uri, generator.GetModulesUrl()); NUnit.Framework.Assert.AreEqual(path, generator.GetModulesPath()); NUnit.Framework.Assert.AreEqual(uri, generator.GetConfigUrl()); Repository subModRepo = generator.GetRepository(); AddRepoToClose(subModRepo); NUnit.Framework.Assert.IsNotNull(subModRepo); NUnit.Framework.Assert.AreEqual(commit, repo.Resolve(Constants.HEAD)); Status status = Git.Wrap(db).Status().Call(); NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(Constants.DOT_GIT_MODULES )); NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path)); }
public virtual void ShouldListAddedFileInInitialCommit() { // given WriteTrashFile("a.txt", "content"); Git git = new Git(db); git.Add().AddFilepattern("a.txt").Call(); RevCommit c = git.Commit().SetMessage("initial commit").Call(); // when TreeWalk walk = new TreeWalk(db); walk.AddTree(new EmptyTreeIterator()); walk.AddTree(c.Tree); IList <DiffEntry> result = DiffEntry.Scan(walk); // then Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); DiffEntry entry = result[0]; Assert.AreEqual(entry.GetChangeType(), DiffEntry.ChangeType.ADD); Assert.AreEqual(entry.GetNewPath(), "a.txt"); Assert.AreEqual(entry.GetOldPath(), DiffEntry.DEV_NULL); }
public virtual void TestDiff() { Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test"); FilePath folder = new FilePath(db.Directory.GetParent(), "folder"); folder.Mkdir(); Write(new FilePath(folder, "folder.txt"), "folder"); Git git = new Git(db); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "folder change"); PatchIdDiffFormatter df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df.GetCalulatedPatchId ().Name); }
public virtual void CheckMergeEqualTreesWithoutIndex(MergeStrategy strategy) { Git git = Git.Wrap(db); WriteTrashFile("d/1", "orig"); git.Add().AddFilepattern("d/1").Call(); RevCommit first = git.Commit().SetMessage("added d/1").Call(); WriteTrashFile("d/1", "modified"); RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on master" ).Call(); git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call(); WriteTrashFile("d/1", "modified"); git.Commit().SetAll(true).SetMessage("modified d/1 on side").Call(); git.Rm().AddFilepattern("d/1").Call(); git.Rm().AddFilepattern("d").Call(); MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit ).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, mergeRes.GetMergeStatus()); NUnit.Framework.Assert.AreEqual("[d/1, mode:100644, content:modified]", IndexState (CONTENT)); }
public virtual void CheckMergeEqualTreesInCore(MergeStrategy strategy) { Git git = Git.Wrap(db); WriteTrashFile("d/1", "orig"); git.Add().AddFilepattern("d/1").Call(); RevCommit first = git.Commit().SetMessage("added d/1").Call(); WriteTrashFile("d/1", "modified"); RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on master" ).Call(); git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call(); WriteTrashFile("d/1", "modified"); RevCommit sideCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on side" ).Call(); git.Rm().AddFilepattern("d/1").Call(); git.Rm().AddFilepattern("d").Call(); ThreeWayMerger resolveMerger = (ThreeWayMerger)strategy.NewMerger(db, true); bool noProblems = resolveMerger.Merge(masterCommit, sideCommit); NUnit.Framework.Assert.IsTrue(noProblems); }
private void AddItemsToGit(bool initialCheckin) { using (var frmStatus = new Status()) { frmStatus.Show(); if (initialCheckin) { frmStatus.SetStatusText("Gathering items to add to version control"); Git git = new Git(_repo); var status = git.Status().Call(); frmStatus.SetMaximum(status.GetUntracked().Count); var add = git.Add(); foreach (var item in status.GetUntracked().ToList()) { add.AddFilepattern(item); frmStatus.SetValue(frmStatus.Value + 1); } add.Call(); frmStatus.SetStatusText("Committing profile items to version control."); git.Commit().SetAll(true).SetMessage(@"Initial commit of existing Vixen profile data files.").Call(); frmStatus.SetValue(2); frmStatus.SetStatusText(@"Completed initial load of existing Vixen profile data files."); } else { //This handles checking in any changes that might have happened outside of a Vixen session. frmStatus.SetStatusText("Gathering items that have changed outside of Vixen and updating version control."); Git git = new Git(_repo); try { var status = git.Status().Call(); var changed = status.GetAdded().Count > 0 || status.GetChanged().Count > 0 || status.GetModified().Count > 0 || status.GetRemoved().Count > 0 || status.GetUntracked().Count > 0 || status.GetMissing().Count > 0; if (changed) { frmStatus.SetMaximum(status.GetAdded().Count + status.GetRemoved().Count + status.GetModified().Count + status.GetChanged().Count + status.GetMissing().Count + status.GetUntracked().Count); if (status.GetAdded().Count > 0 || status.GetUntracked().Count > 0 || status.GetModified().Count > 0) { var add = git.Add(); status.GetAdded().ToList().ForEach(a => { add.AddFilepattern(a); frmStatus.SetValue(frmStatus.Value + 1); }); status.GetModified().ToList().ForEach(a => { add.AddFilepattern(a); frmStatus.SetValue(frmStatus.Value + 1); }); status.GetChanged().ToList().ForEach(a => { add.AddFilepattern(a); frmStatus.SetValue(frmStatus.Value + 1); }); status.GetUntracked().ToList().ForEach(a => { add.AddFilepattern(a); frmStatus.SetValue(frmStatus.Value + 1); }); add.Call(); } if (status.GetMissing().Count > 0 || status.GetRemoved().Count > 0) { var removed = git.Rm(); status.GetRemoved().ToList().ForEach(a => { removed.AddFilepattern(a); frmStatus.SetValue(frmStatus.Value + 1); }); status.GetMissing().ToList().ForEach(a => { removed.AddFilepattern(a); frmStatus.SetValue(frmStatus.Value + 1); }); removed.Call(); } git.Commit().SetMessage(@"Update of profile changes outside of Vixen.").Call(); frmStatus.SetStatusText(@"Committed profile changes outside of Vixen."); } RunCleanup(frmStatus); } catch (Exception e) { Logging.Error(e, "Unable to access repository."); } } frmStatus.Close(); } }
public void Commit(string message) { _git.Add().AddFilepattern(".").Call(); _git.Add().SetUpdate(true).AddFilepattern(".").Call(); _git.Commit().SetMessage(message).Call(); }
public virtual void TestRenamedBoundLineDelete() { Git git = new Git(db); string FILENAME_1 = "subdir/file1.txt"; string FILENAME_2 = "subdir/file2.txt"; string[] content1 = new string[] { "first", "second" }; WriteTrashFile(FILENAME_1, Join(content1)); git.Add().AddFilepattern(FILENAME_1).Call(); RevCommit c1 = git.Commit().SetMessage("create file1").Call(); // rename it WriteTrashFile(FILENAME_2, Join(content1)); git.Add().AddFilepattern(FILENAME_2).Call(); DeleteTrashFile(FILENAME_1); git.Rm().AddFilepattern(FILENAME_1).Call(); git.Commit().SetMessage("rename file1.txt to file2.txt").Call(); // and change the new file string[] content2 = new string[] { "third", "first", "second" }; WriteTrashFile(FILENAME_2, Join(content2)); git.Add().AddFilepattern(FILENAME_2).Call(); RevCommit c2 = git.Commit().SetMessage("change file2").Call(); BlameGenerator generator = new BlameGenerator(db, FILENAME_2); try { generator.Push(null, db.Resolve(Constants.HEAD)); NUnit.Framework.Assert.AreEqual(3, generator.GetResultContents().Size()); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(c2, generator.GetSourceCommit()); NUnit.Framework.Assert.AreEqual(1, generator.GetRegionLength()); NUnit.Framework.Assert.AreEqual(0, generator.GetResultStart()); NUnit.Framework.Assert.AreEqual(1, generator.GetResultEnd()); NUnit.Framework.Assert.AreEqual(0, generator.GetSourceStart()); NUnit.Framework.Assert.AreEqual(1, generator.GetSourceEnd()); NUnit.Framework.Assert.AreEqual(FILENAME_2, generator.GetSourcePath()); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(c1, generator.GetSourceCommit()); NUnit.Framework.Assert.AreEqual(2, generator.GetRegionLength()); NUnit.Framework.Assert.AreEqual(1, generator.GetResultStart()); NUnit.Framework.Assert.AreEqual(3, generator.GetResultEnd()); NUnit.Framework.Assert.AreEqual(0, generator.GetSourceStart()); NUnit.Framework.Assert.AreEqual(2, generator.GetSourceEnd()); NUnit.Framework.Assert.AreEqual(FILENAME_1, generator.GetSourcePath()); NUnit.Framework.Assert.IsFalse(generator.Next()); } finally { generator.Release(); } // and test again with other BlameGenerator API: generator = new BlameGenerator(db, FILENAME_2); try { generator.Push(null, db.Resolve(Constants.HEAD)); BlameResult result = generator.ComputeBlameResult(); NUnit.Framework.Assert.AreEqual(3, result.GetResultContents().Size()); NUnit.Framework.Assert.AreEqual(c2, result.GetSourceCommit(0)); NUnit.Framework.Assert.AreEqual(FILENAME_2, result.GetSourcePath(0)); NUnit.Framework.Assert.AreEqual(c1, result.GetSourceCommit(1)); NUnit.Framework.Assert.AreEqual(FILENAME_1, result.GetSourcePath(1)); NUnit.Framework.Assert.AreEqual(c1, result.GetSourceCommit(2)); NUnit.Framework.Assert.AreEqual(FILENAME_1, result.GetSourcePath(2)); } finally { generator.Release(); } }