Esempio n. 1
0
        public void testReadTree2()
        {
            // Prepare a larger tree to test some odd cases in tree writing
            var      index = new GitIndex(db);
            FileInfo f1    = writeTrashFile("a/a/a/a", "data:a/a/a/a");
            FileInfo f2    = writeTrashFile("a/c/c", "data:a/c/c");
            FileInfo f3    = writeTrashFile("a/b", "data:a/b");
            FileInfo f4    = writeTrashFile("a@b", "data:a:b");
            FileInfo f5    = writeTrashFile("a/d", "data:a/d");
            FileInfo f6    = writeTrashFile("a.b", "data:a.b");

            index.add(trash, f1);
            index.add(trash, f2);
            index.add(trash, f3);
            index.add(trash, f4);
            index.add(trash, f5);
            index.add(trash, f6);
            index.write();
            ObjectId id = index.writeTree();

            Console.WriteLine("wrote id " + id);
            Assert.AreEqual("5e0bf0aad57706894c15fdf0681c9bc7343274fc", id.Name);
            var index2 = new GitIndex(db);

            index2.ReadTree(db.MapTree(ObjectId.FromString("5e0bf0aad57706894c15fdf0681c9bc7343274fc")));
            IList <GitIndex.Entry> members = index2.Members;

            Assert.AreEqual(6, members.Count);
            Assert.AreEqual("a.b", members[0].Name);
            Assert.AreEqual("a/a/a/a", members[1].Name);
            Assert.AreEqual("a/b", members[2].Name);
            Assert.AreEqual("a/c/c", members[3].Name);
            Assert.AreEqual("a/d", members[4].Name);
            Assert.AreEqual("a@b", members[5].Name);

            // reread and test
            var indexr = new GitIndex(db);

            indexr.Read();
            IList <GitIndex.Entry> membersr = indexr.Members;

            Assert.AreEqual(6, membersr.Count);
            Assert.AreEqual("a.b", membersr[0].Name);
            Assert.AreEqual("a/a/a/a", membersr[1].Name);
            Assert.AreEqual("a/b", membersr[2].Name);
            Assert.AreEqual("a/c/c", membersr[3].Name);
            Assert.AreEqual("a/d", membersr[4].Name);
            Assert.AreEqual("a@b", membersr[5].Name);
        }
Esempio n. 2
0
        public void CanAddAFileToAMSysGitIndexWhereAFileIsAlreadyWaitingToBeCommitted()
        {
            //setup of .git directory
            var resource =
                new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"),
                                               "CorruptIndex"));
            var tempRepository =
                new DirectoryInfo(Path.Combine(trash.FullName, "CorruptIndex" + Path.GetRandomFileName()));

            CopyDirectory(resource.FullName, tempRepository.FullName);

            var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, Constants.DOT_GIT));

            Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName);



            using (var repository = new Core.Repository(repositoryPath))
            {
                GitIndex index = repository.Index;

                Assert.IsNotNull(index);

                writeTrashFile(Path.Combine(repository.WorkingDirectory.FullName, "c.txt"), "c");

                var tree = repository.MapTree(repository.Head.ObjectId);

                index.add(repository.WorkingDirectory,
                          new FileInfo(Path.Combine(repository.WorkingDirectory.FullName, "c.txt")));

                var diff = new IndexDiff(tree, index);
                diff.Diff();

                index.write();


                Assert.AreEqual(2, diff.Added.Count);
                Assert.IsFalse(diff.Added.Contains("a.txt"), "Should not contain a.txt because it is already committed.");
                Assert.IsTrue(diff.Added.Contains("b.txt"),
                              "Should contain b.txt since it was added by msysgit, but not committed");
                Assert.IsTrue(diff.Added.Contains("c.txt"),
                              "Should contain c.txt since it was added by this test, but not committed");
                Assert.AreEqual(0, diff.Changed.Count);
                Assert.AreEqual(0, diff.Modified.Count);
                Assert.AreEqual(0, diff.Removed.Count);
            }
        }
Esempio n. 3
0
        public void testReadTree()
        {
            // Prepare tree
            var index = new GitIndex(db);

            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a@b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            index.write();

            ObjectId id = index.writeTree();

            Console.WriteLine("wrote id " + id);
            Assert.AreEqual("0036d433dc4f10ec47b61abc3ec5033c78d34f84", id.Name);
            var index2 = new GitIndex(db);

            index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84")));
            IList <GitIndex.Entry> members = index2.Members;

            Assert.AreEqual(3, members.Count);
            Assert.AreEqual("a.b", members[0].Name);
            Assert.AreEqual("a/b", members[1].Name);
            Assert.AreEqual("a@b", members[2].Name);
            Assert.AreEqual(3, members.Count);

            var indexr = new GitIndex(db);

            indexr.Read();
            IList <GitIndex.Entry> membersr = indexr.Members;

            Assert.AreEqual(3, membersr.Count);
            Assert.AreEqual("a.b", membersr[0].Name);
            Assert.AreEqual("a/b", membersr[1].Name);
            Assert.AreEqual("a@b", membersr[2].Name);
            Assert.AreEqual(3, membersr.Count);

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 4
0
        public void testUpdateExistingMsysgitIndex()
        {
            var index_path = Path.Combine(trash.FullName + "/.git", "index");

            new FileInfo("Resources/index_originating_from_msysgit").CopyTo(index_path);

            var index = new GitIndex(db);

            index.Read();
            var a = writeTrashFile("a.txt", "Data:a");

            index.add(trash, a);
            index.write();
            index.Read();

            byte[] content = File.ReadAllBytes(index_path);

            Assert.AreEqual(352, content.Length);
        }
Esempio n. 5
0
        public void testUpdateSimpleSortTestIndex()
        {
            var index = new GitIndex(db);

            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a@b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            writeTrashFile("a/b", "data:a/b modified");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.write();

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 6
0
        public void testWriteTree()
        {
            var index = new GitIndex(db);

            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a@b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            index.write();

            ObjectId id = index.writeTree();

            Assert.AreEqual("0036d433dc4f10ec47b61abc3ec5033c78d34f84", id.Name);

            writeTrashFile("a/b", "data:a/b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 7
0
        public void testCreateEmptyIndex()
        {
            var index = new GitIndex(db);
            index.write();
            // native git doesn't like an empty index
            // Assert.AreEqual(0,System(trash,"git status"));

            var indexr = new GitIndex(db);
            indexr.Read();
            Assert.AreEqual(0, indexr.Members.Count);
        }
Esempio n. 8
0
        public void testCheckout()
        {
            // Prepare tree, remote it and checkout
            var index = new GitIndex(db);
            FileInfo aslashb = writeTrashFile("a/b", "data:a/b");
            FileInfo acolonb = writeTrashFile("a@b", "data:a:b");
            FileInfo adotb = writeTrashFile("a.b", "data:a.b");
            index.add(trash, aslashb);
            index.add(trash, acolonb);
            index.add(trash, adotb);
            index.write();
            index.writeTree();
            Delete(aslashb);
            Delete(acolonb);
            Delete(adotb);
            Delete(Directory.GetParent(aslashb.FullName));

            var index2 = new GitIndex(db);
            Assert.AreEqual(0, index2.Members.Count);

            index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84")));

            index2.checkout(trash);
            Assert.AreEqual("data:a/b", Content(aslashb));
            Assert.AreEqual("data:a:b", Content(acolonb));
            Assert.AreEqual("data:a.b", Content(adotb));

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 9
0
        private void doCheckout(GitSharp.Core.Ref branch)
        {
            if (branch == null)
                throw new ArgumentNullException("branch", "Cannot checkout; no HEAD advertised by remote");
            var repo = Repository._internal_repo;

            if (!Constants.HEAD.Equals(branch.getName()))
            {
                RefUpdate u1 = repo.UpdateRef(Constants.HEAD);
                u1.disableRefLog();
                u1.link(branch.getName());
            }

            GitSharp.Core.Commit commit = repo.MapCommit(branch.ObjectId);
            RefUpdate u = repo.UpdateRef(Constants.HEAD);
            u.NewObjectId = commit.CommitId;
            u.forceUpdate();
            GitIndex index = new GitIndex(repo);
            GitSharp.Core.Tree tree = commit.TreeEntry;
            WorkDirCheckout co = new WorkDirCheckout(repo, repo.WorkingDirectory, index, tree);
            co.checkout();
            index.write();
        }
Esempio n. 10
0
        private void doCheckout(GitSharp.Core.Ref branch)
        {
            if (branch == null)
                throw new ArgumentNullException("branch", "Cannot checkout; no HEAD advertised by remote");

            if (!Constants.HEAD.Equals(branch.Name))
                GitRepository.WriteSymref(Constants.HEAD, branch.Name);
            GitSharp.Core.Commit commit = GitRepository.MapCommit(branch.ObjectId);
            RefUpdate u = GitRepository.UpdateRef(Constants.HEAD);
            u.NewObjectId = commit.CommitId;
            u.ForceUpdate();
            GitIndex index = new GitIndex(GitRepository);
            GitSharp.Core.Tree tree = commit.TreeEntry;
            WorkDirCheckout co = new WorkDirCheckout(GitRepository, GitRepository.WorkingDirectory, index, tree);
            co.checkout();
            index.write();
        }
Esempio n. 11
0
        public void testReadTree2()
        {
            // Prepare a larger tree to test some odd cases in tree writing
            var index = new GitIndex(db);
            FileInfo f1 = writeTrashFile("a/a/a/a", "data:a/a/a/a");
            FileInfo f2 = writeTrashFile("a/c/c", "data:a/c/c");
            FileInfo f3 = writeTrashFile("a/b", "data:a/b");
            FileInfo f4 = writeTrashFile("a:b", "data:a:b");
            FileInfo f5 = writeTrashFile("a/d", "data:a/d");
            FileInfo f6 = writeTrashFile("a.b", "data:a.b");
            index.add(trash, f1);
            index.add(trash, f2);
            index.add(trash, f3);
            index.add(trash, f4);
            index.add(trash, f5);
            index.add(trash, f6);
            index.write();
            ObjectId id = index.writeTree();
            Console.WriteLine("wrote id " + id);
            Assert.AreEqual("ba78e065e2c261d4f7b8f42107588051e87e18e9", id.Name);
            var index2 = new GitIndex(db);

            index2.ReadTree(db.MapTree(ObjectId.FromString("ba78e065e2c261d4f7b8f42107588051e87e18e9")));
            GitIndex.Entry[] members = index2.Members;
            Assert.AreEqual(6, members.Length);
            Assert.AreEqual("a.b", members[0].Name);
            Assert.AreEqual("a/a/a/a", members[1].Name);
            Assert.AreEqual("a/b", members[2].Name);
            Assert.AreEqual("a/c/c", members[3].Name);
            Assert.AreEqual("a/d", members[4].Name);
            Assert.AreEqual("a:b", members[5].Name);

            // reread and test
            var indexr = new GitIndex(db);
            indexr.Read();
            GitIndex.Entry[] membersr = indexr.Members;
            Assert.AreEqual(6, membersr.Length);
            Assert.AreEqual("a.b", membersr[0].Name);
            Assert.AreEqual("a/a/a/a", membersr[1].Name);
            Assert.AreEqual("a/b", membersr[2].Name);
            Assert.AreEqual("a/c/c", membersr[3].Name);
            Assert.AreEqual("a/d", membersr[4].Name);
            Assert.AreEqual("a:b", membersr[5].Name);
        }
Esempio n. 12
0
        public void testUpdateSimpleSortTestIndex()
        {
            var index = new GitIndex(db);
            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a@b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            writeTrashFile("a/b", "data:a/b modified");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.write();

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 13
0
        public void testReadTree()
        {
            // Prepare tree
            var index = new GitIndex(db);
            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a@b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            index.write();

            ObjectId id = index.writeTree();
            Console.WriteLine("wrote id " + id);
            Assert.AreEqual("0036d433dc4f10ec47b61abc3ec5033c78d34f84", id.Name);
            var index2 = new GitIndex(db);

            index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84")));
            IList<GitIndex.Entry> members = index2.Members;
            Assert.AreEqual(3, members.Count);
            Assert.AreEqual("a.b", members[0].Name);
            Assert.AreEqual("a/b", members[1].Name);
            Assert.AreEqual("a@b", members[2].Name);
            Assert.AreEqual(3, members.Count);

            var indexr = new GitIndex(db);
            indexr.Read();
            IList<GitIndex.Entry> membersr = indexr.Members;
            Assert.AreEqual(3, membersr.Count);
            Assert.AreEqual("a.b", membersr[0].Name);
            Assert.AreEqual("a/b", membersr[1].Name);
            Assert.AreEqual("a@b", membersr[2].Name);
            Assert.AreEqual(3, membersr.Count);

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 14
0
        public void testCheckout()
        {
            // Prepare tree, remote it and checkout
            var index = new GitIndex(db);
            FileInfo aslashb = writeTrashFile("a/b", "data:a/b");
            FileInfo acolonb = writeTrashFile("a:b", "data:a:b");
            FileInfo adotb = writeTrashFile("a.b", "data:a.b");
            index.add(trash, aslashb);
            index.add(trash, acolonb);
            index.add(trash, adotb);
            index.write();
            index.writeTree();
            Delete(aslashb);
            Delete(acolonb);
            Delete(adotb);
            Delete(Directory.GetParent(aslashb.FullName));

            var index2 = new GitIndex(db);
            Assert.AreEqual(0, index2.Members.Length);

            index2.ReadTree(db.MapTree(ObjectId.FromString("c696abc3ab8e091c665f49d00eb8919690b3aec3")));

            index2.checkout(trash);
            Assert.AreEqual("data:a/b", Content(aslashb));
            Assert.AreEqual("data:a:b", Content(acolonb));
            Assert.AreEqual("data:a.b", Content(adotb));

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 15
0
        public void testUpdateExistingMsysgitIndex()
        {
            var index_path = Path.Combine(trash.FullName + "/.git", "index");
            new FileInfo("Resources/index_originating_from_msysgit").CopyTo(index_path);

            var index = new GitIndex(db);
            index.Read();
            var a = writeTrashFile("a.txt", "Data:a");
            index.add(trash, a);
            index.write();
            index.Read();

            byte[] content = File.ReadAllBytes(index_path);

            Assert.AreEqual(352, content.Length);
        }
Esempio n. 16
0
 /// <summary>
 /// Writes the index to the disk.
 /// </summary>
 public void Write()
 {
     GitIndex.write();
 }
Esempio n. 17
0
        public void testWriteTree()
        {
            var index = new GitIndex(db);
            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a:b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a:b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            index.write();

            ObjectId id = index.writeTree();
            Assert.AreEqual("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.Name);

            writeTrashFile("a/b", "data:a/b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 18
0
        public void testCreateSimpleSortTestIndex()
        {
            var index = new GitIndex(db);
            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a@b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            index.write();

            Assert.AreEqual("a/b", index.GetEntry("a/b").Name);
            Assert.AreEqual("a@b", index.GetEntry("a@b").Name);
            Assert.AreEqual("a.b", index.GetEntry("a.b").Name);
            Assert.IsNull(index.GetEntry("a*b"));

            // Repeat test for re-Read index
            var indexr = new GitIndex(db);
            indexr.Read();
            Assert.AreEqual("a/b", indexr.GetEntry("a/b").Name);
            Assert.AreEqual("a@b", indexr.GetEntry("a@b").Name);
            Assert.AreEqual("a.b", indexr.GetEntry("a.b").Name);
            Assert.IsNull(indexr.GetEntry("a*b"));

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 19
0
        internal void Apply(Stash stash)
        {
            Commit wip   = _repo.Get <Commit> (stash.CommitId);
            Commit index = wip.Parents.Last();

            Tree     wipTree          = wip.Tree;
            Tree     headTree         = _repo.CurrentBranch.CurrentCommit.Tree;
            GitIndex currentIndex     = _repo.Index.GitIndex;
            Tree     currentIndexTree = new Tree(_repo, _repo._internal_repo.MapTree(currentIndex.writeTree()));

            WorkDirCheckout co = new WorkDirCheckout(_repo._internal_repo, _repo._internal_repo.WorkingDirectory, headTree.InternalTree, currentIndex, wip.Tree.InternalTree);

            co.checkout();

            currentIndex.write();

            List <DirCacheEntry> toAdd = new List <DirCacheEntry> ();

            DirCache dc = DirCache.Lock(_repo._internal_repo);

            try {
                var cacheEditor = dc.editor();

                // The WorkDirCheckout class doesn't check if there are conflicts in modified files,
                // so we have to do it here.

                foreach (var c in co.Updated)
                {
                    var baseEntry   = wip.Parents.First().Tree[c.Key] as Leaf;
                    var oursEntry   = wipTree [c.Key] as Leaf;
                    var theirsEntry = headTree [c.Key] as Leaf;

                    if (baseEntry != null && oursEntry != null && currentIndexTree [c.Key] == null)
                    {
                        // If a file was reported as updated but that file is not present in the stashed index,
                        // it means that the file was scheduled to be deleted.
                        cacheEditor.@add(new DirCacheEditor.DeletePath(c.Key));
                        File.Delete(_repo.FromGitPath(c.Key));
                    }
                    else if (baseEntry != null && oursEntry != null && theirsEntry != null)
                    {
                        MergeResult    res = MergeAlgorithm.merge(new RawText(baseEntry.RawData), new RawText(oursEntry.RawData), new RawText(theirsEntry.RawData));
                        MergeFormatter f   = new MergeFormatter();
                        using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(_repo.FromGitPath(c.Key)))) {
                            f.formatMerge(bw, res, "Base", "Stash", "Head", Constants.CHARSET.WebName);
                        }
                        if (res.containsConflicts())
                        {
                            // Remove the entry from the index. It will be added later on.
                            cacheEditor.@add(new DirCacheEditor.DeletePath(c.Key));

                            // Generate index entries for each merge stage
                            // Those entries can't be added right now to the index because a DirCacheEditor
                            // can't be used at the same time as a DirCacheBuilder.
                            var e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_1);
                            e.setObjectId(baseEntry.InternalEntry.Id);
                            e.setFileMode(baseEntry.InternalEntry.Mode);
                            toAdd.Add(e);

                            e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_2);
                            e.setObjectId(oursEntry.InternalEntry.Id);
                            e.setFileMode(oursEntry.InternalEntry.Mode);
                            toAdd.Add(e);

                            e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_3);
                            e.setObjectId(theirsEntry.InternalEntry.Id);
                            e.setFileMode(theirsEntry.InternalEntry.Mode);
                            toAdd.Add(e);
                        }
                    }
                }

                cacheEditor.finish();

                if (toAdd.Count > 0)
                {
                    // Add the index entries generated above
                    var cacheBuilder = dc.builder();
                    for (int n = 0; n < dc.getEntryCount(); n++)
                    {
                        cacheBuilder.@add(dc.getEntry(n));
                    }
                    foreach (var entry in toAdd)
                    {
                        cacheBuilder.@add(entry);
                    }
                    cacheBuilder.finish();
                }

                dc.write();
                dc.commit();
            } catch {
                dc.unlock();
                throw;
            }
        }
Esempio n. 20
0
        public void testDelete()
        {
            var index = new GitIndex(db);
            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a@b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            index.write();
            index.writeTree();
            index.remove(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.write();
            Assert.AreEqual("a.b", index.Members[0].Name);
            Assert.AreEqual("a/b", index.Members[1].Name);

            var indexr = new GitIndex(db);
            indexr.Read();
            Assert.AreEqual("a.b", indexr.Members[0].Name);
            Assert.AreEqual("a/b", indexr.Members[1].Name);

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
		protected override void Run ()
		{
			var cloneDialog = new CloneRepositoryDialog ();
			cloneDialog.Run ();
			cloneDialog.Destroy ();
			
			var repositoryPath = cloneDialog.RepositoryPath;
			URIish source = new URIish (repositoryPath);
			var originName = cloneDialog.OriginName;
			var destination = cloneDialog.WorkingDirectory;
			var workingDirectory = Path.Combine (destination, Constants.DOT_GIT);
			
			if (string.IsNullOrEmpty (originName))
				originName = Constants.DEFAULT_REMOTE_NAME;
			
			var rep = new GitSharp.Core.Repository (new DirectoryInfo (workingDirectory));
			rep.Create ();
			rep.Config.setBoolean ("core", null, "bare", false);
			rep.Config.save ();
			
			var rc = new RemoteConfig (rep.Config, originName);
			rc.AddURI (source);
			rc.AddFetchRefSpec (new RefSpec ().SetForce (true).SetSourceDestination (
					Constants.R_HEADS + "*", 
					Constants.R_REMOTES + originName + "/*"));
			rc.Update (rep.Config);
			rep.Config.save ();
			
			Transport tn = Transport.open (rep, originName);
			FetchResult fetchResult = null;
			try 
			{
				fetchResult = tn.fetch (new NullProgressMonitor (), null);
			} 
			catch 
			{
				tn.Dispose ();
			}
			
			GitSharp.Core.Ref branch = null;
			if (fetchResult != null) 
			{
				var headId = fetchResult.GetAdvertisedRef (Constants.HEAD);
				var availableRefs = new List<GitSharp.Core.Ref> ();
				
				foreach (GitSharp.Core.Ref r in fetchResult.AdvertisedRefs) 
				{
					var n = r.Name;
					if (!n.StartsWith (Constants.R_HEADS))
						continue;
					
					availableRefs.Add (r);
					if (headId == null || branch != null)
						continue;
					
					if (r.ObjectId.Equals (headId.ObjectId))
						branch = r;
				}
				
				availableRefs.Sort (RefComparator.INSTANCE);
				
				if (headId != null && branch == null)
					branch = headId;
			}
			
			if (branch != null) 
			{
				if (!Constants.HEAD.Equals (branch.Name)) 
				{
					//rep. (Constants.HEAD, branch.Name);
					GitSharp.Core.Commit commit = rep.MapCommit (branch.ObjectId);
					RefUpdate update = rep.UpdateRef (Constants.HEAD);
					update.NewObjectId = commit.CommitId;
					update.forceUpdate ();
					
					var index = new GitIndex (rep);
					var tree = commit.TreeEntry;
					WorkDirCheckout co = new WorkDirCheckout (rep, rep.WorkingDirectory, index, tree);
					co.checkout ();
					index.write ();
				}
			} 
			else 
			{
				MessageService.ShowError ("Cannot clone: no HEAD advertised by remote.");
			}
			
			MessageService.ShowMessage(string.Format("Finished cloning {0} to {1}", 
					repositoryPath, 
					destination));
		}
Esempio n. 22
0
        public void testReadTree2()
        {
            // Prepare a larger tree to test some odd cases in tree writing
            var index = new GitIndex(db);
            FileInfo f1 = writeTrashFile("a/a/a/a", "data:a/a/a/a");
            FileInfo f2 = writeTrashFile("a/c/c", "data:a/c/c");
            FileInfo f3 = writeTrashFile("a/b", "data:a/b");
            FileInfo f4 = writeTrashFile("a@b", "data:a:b");
            FileInfo f5 = writeTrashFile("a/d", "data:a/d");
            FileInfo f6 = writeTrashFile("a.b", "data:a.b");
            index.add(trash, f1);
            index.add(trash, f2);
            index.add(trash, f3);
            index.add(trash, f4);
            index.add(trash, f5);
            index.add(trash, f6);
            index.write();
            ObjectId id = index.writeTree();
            Console.WriteLine("wrote id " + id);
            Assert.AreEqual("5e0bf0aad57706894c15fdf0681c9bc7343274fc", id.Name);
            var index2 = new GitIndex(db);

            index2.ReadTree(db.MapTree(ObjectId.FromString("5e0bf0aad57706894c15fdf0681c9bc7343274fc")));
            IList<GitIndex.Entry> members = index2.Members;
            Assert.AreEqual(6, members.Count);
            Assert.AreEqual("a.b", members[0].Name);
            Assert.AreEqual("a/a/a/a", members[1].Name);
            Assert.AreEqual("a/b", members[2].Name);
            Assert.AreEqual("a/c/c", members[3].Name);
            Assert.AreEqual("a/d", members[4].Name);
            Assert.AreEqual("a@b", members[5].Name);

            // reread and test
            var indexr = new GitIndex(db);
            indexr.Read();
            IList<GitIndex.Entry> membersr = indexr.Members;
            Assert.AreEqual(6, membersr.Count);
            Assert.AreEqual("a.b", membersr[0].Name);
            Assert.AreEqual("a/a/a/a", membersr[1].Name);
            Assert.AreEqual("a/b", membersr[2].Name);
            Assert.AreEqual("a/c/c", membersr[3].Name);
            Assert.AreEqual("a/d", membersr[4].Name);
            Assert.AreEqual("a@b", membersr[5].Name);
        }
Esempio n. 23
0
        private void doCheckout(Ref branch)
        {
            if (branch == null)
                throw die("Cannot checkout; no HEAD advertised by remote");
            if (!Constants.HEAD.Equals(branch.Name))
                db.WriteSymref(Constants.HEAD, branch.Name);

            GitSharp.Commit commit = db.MapCommit(branch.ObjectId);
            RefUpdate u = db.UpdateRef(Constants.HEAD);
            u.NewObjectId = commit.CommitId;
            u.ForceUpdate();

            GitIndex index = new GitIndex(db);
            Tree tree = commit.TreeEntry;

            WorkDirCheckout co = new WorkDirCheckout(db, db.WorkingDirectory, index, tree);
            co.checkout();
            index.write();
        }
Esempio n. 24
0
        public void testWriteTree()
        {
            var index = new GitIndex(db);
            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a@b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            index.write();

            ObjectId id = index.writeTree();
            Assert.AreEqual("0036d433dc4f10ec47b61abc3ec5033c78d34f84", id.Name);

            writeTrashFile("a/b", "data:a/b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Esempio n. 25
0
        public void testReadTree()
        {
            // Prepare tree
            var index = new GitIndex(db);
            writeTrashFile("a/b", "data:a/b");
            writeTrashFile("a:b", "data:a:b");
            writeTrashFile("a.b", "data:a.b");
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a:b")));
            index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b")));
            index.write();

            ObjectId id = index.writeTree();
            Console.WriteLine("wrote id " + id);
            Assert.AreEqual("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.Name);
            var index2 = new GitIndex(db);

            index2.ReadTree(db.MapTree(ObjectId.FromString("c696abc3ab8e091c665f49d00eb8919690b3aec3")));
            GitIndex.Entry[] members = index2.Members;
            Assert.AreEqual(3, members.Length);
            Assert.AreEqual("a.b", members[0].Name);
            Assert.AreEqual("a/b", members[1].Name);
            Assert.AreEqual("a:b", members[2].Name);
            Assert.AreEqual(3, members.Length);

            var indexr = new GitIndex(db);
            indexr.Read();
            GitIndex.Entry[] membersr = indexr.Members;
            Assert.AreEqual(3, membersr.Length);
            Assert.AreEqual("a.b", membersr[0].Name);
            Assert.AreEqual("a/b", membersr[1].Name);
            Assert.AreEqual("a:b", membersr[2].Name);
            Assert.AreEqual(3, membersr.Length);

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }