Beispiel #1
0
        public void testObjectMovedWithinPack()
        {
            // Create an object and pack it.
            //
            Core.Repository eden = createBareRepository();
            RevObject       o1   = WriteBlob(eden, "o1");

            FileInfo[] out1 = Pack(eden, o1);
            Assert.AreEqual(o1.Name, Parse(o1).Name);

            // Force close the old pack.
            //
            WhackCache();

            // Now overwrite the old pack in place. This method of creating a
            // different pack under the same file name is partially broken. We
            // should also have a different file name because the list of objects
            // within the pack has been modified.
            //
            RevObject o2 = WriteBlob(eden, "o2");
            var       pw = new PackWriter(eden, NullProgressMonitor.Instance);

            pw.addObject(o2);
            pw.addObject(o1);
            Write(out1, pw);

            // Try the old name, then the new name. The old name should cause the
            // pack to reload when it opens and the index and pack mismatch.
            //
            Assert.AreEqual(o1.Name, Parse(o1).Name);
            Assert.AreEqual(o2.Name, Parse(o2).Name);
        }
Beispiel #2
0
        public void testObjectMovedToNewPack1()
        {
            // Create an object and pack it. Then remove that pack and put the
            // object into a different pack file, with some other object. We
            // still should be able to access the objects.
            //
            Core.Repository eden = createBareRepository();
            RevObject       o1   = WriteBlob(eden, "o1");

            FileInfo[] out1 = Pack(eden, o1);
            Assert.AreEqual(o1.Name, Parse(o1).Name);

            RevObject o2 = WriteBlob(eden, "o2");

            Pack(eden, o2, o1);

            // Force close, and then delete, the old pack.
            //
            WhackCache();
            Delete(out1);

            // Now here is the interesting thing. Will git figure the new
            // object exists in the new pack, and not the old one.
            //
            Assert.AreEqual(o2.Name, Parse(o2).Name);
            Assert.AreEqual(o1.Name, Parse(o1).Name);
        }
Beispiel #3
0
        public override void setUp()
        {
            base.setUp();

            db    = createWorkRepository();
            trash = db.WorkingDirectory;
        }
Beispiel #4
0
        public void Check_entries_of_msysgit_index()
        {
            using (var repo = new Core.Repository(db.Directory))
            {
                var index_path = Path.Combine(repo.Directory.FullName, "index");
                new FileInfo("Resources/index_originating_from_msysgit").CopyTo(index_path);

                var index = repo.Index;
                index.RereadIfNecessary();

                var paths = new[]
                {
                    "New Folder/New Ruby Program.rb",
                    "for henon.txt",
                    "test.cmd",
                };

                var dict = index.Members.ToDictionary(entry => entry.Name);
                Assert.AreEqual(3, dict.Count);
                foreach (var path in paths)
                {
                    Assert.IsTrue(dict.ContainsKey(path));
                }
            }
        }
        public override void setUp()
        {
            base.setUp();

            db = createWorkRepository();
            trash = db.WorkingDirectory;
        }
Beispiel #6
0
        public override void setUp()
        {
            base.setUp();

            db = createWorkRepository();
            trash = db.WorkingDirectory;

            string[] packs = {
                "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f",
                "pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371",
                "pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745",
                "pack-546ff360fe3488adb20860ce3436a2d6373d2796",
                "pack-cbdeda40019ae0e6e789088ea0f51f164f489d14",
                "pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa",
                "pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12"
            };

            var packDir = new DirectoryInfo(db.ObjectsDirectory + "/pack");

            foreach (var packname in packs)
            {
                new FileInfo("Resources/" + Core.Transport.IndexPack.GetPackFileName(packname)).CopyTo(packDir + "/" + Core.Transport.IndexPack.GetPackFileName(packname), true);
                new FileInfo("Resources/" + Core.Transport.IndexPack.GetIndexFileName(packname)).CopyTo(packDir + "/" + Core.Transport.IndexPack.GetIndexFileName(packname), true);
            }

            new FileInfo("Resources/packed-refs").CopyTo(db.Directory.FullName + "/packed-refs", true);
        }
Beispiel #7
0
 public void testCacheOpen()
 {
     RepositoryCache.FileKey loc = RepositoryCache.FileKey.exact(db.Directory);
     Core.Repository         d2  = RepositoryCache.open(loc);
     Assert.AreNotSame(db, d2);
     Assert.AreSame(d2, RepositoryCache.open(RepositoryCache.FileKey.exact(loc.getFile())));
     d2.Close();
     d2.Close();
 }
Beispiel #8
0
 public void test007_Open()
 {
     using (Core.Repository db2 = new Core.Repository(db.Directory))
     {
         Assert.AreEqual(db.Directory, db2.Directory);
         Assert.AreEqual(db.ObjectsDirectory.FullName, db2.ObjectsDirectory.FullName);
         Assert.AreNotSame(db.Config, db2.Config);
     }
 }
Beispiel #9
0
        public void testObjectInNewPack()
        {
            // Create a new object in a new pack, and test that it is present.
            //
            Core.Repository eden = createBareRepository();
            RevObject       o1   = WriteBlob(eden, "o1");

            Pack(eden, o1);
            Assert.AreEqual(o1.Name, Parse(o1).Name);
        }
Beispiel #10
0
        ObjectId Resolve(string s)
        {
            Core.Repository repo = Git.DefaultRepository;
            ObjectId        r    = repo.Resolve(s);

            if (r == null)
            {
                throw die("Not a revision: " + s);
            }
            return(r);
        }
Beispiel #11
0
        /**
         * Creates a new empty repository.
         *
         * @param bare
         *            true to create a bare repository; false to make a repository
         *            within its working directory
         * @return the newly created repository, opened for access
         * @throws IOException
         *             the repository could not be created in the temporary area
         */
        private Core.Repository createRepository(bool bare)
        {
            String        uniqueId   = GetType().Name + Guid.NewGuid().ToString();
            String        gitdirName = "test" + uniqueId + (bare ? "" : "/") + Constants.DOT_GIT;
            DirectoryInfo gitdir     = new DirectoryInfo(Path.Combine(trash.FullName, gitdirName));

            Core.Repository db = new Core.Repository(gitdir);

            Assert.IsFalse(gitdir.Exists);
            db.Create();
            toClose.Add(db);
            return(db);
        }
Beispiel #12
0
        private FetchResult fetchFromBundle(Core.Repository newRepo, byte[] bundle)
        {
            var uri  = new URIish("in-memory://");
            var @in  = new MemoryStream(bundle);
            var rs   = new RefSpec("refs/heads/*:refs/heads/*");
            var refs = new List <RefSpec> {
                rs
            };
            var transportBundleStream = new TransportBundleStream(newRepo, uri, @in);

            _transportBundleStreams.Add(transportBundleStream);

            return(transportBundleStream.fetch(NullProgressMonitor.Instance, refs));
        }
Beispiel #13
0
        public void test002_WriteEmptyTree()
        {
            // One of our test packs contains the empty tree object. If the pack is
            // open when we Create it we won't write the object file out as a loose
            // object (as it already exists in the pack).
            //
            Core.Repository newdb = createBareRepository();
            var             t     = new Core.Tree(newdb);

            t.Accept(new WriteTree(trash, newdb), TreeEntry.MODIFIED_ONLY);
            Assert.AreEqual("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.Id.Name);
            var o = new FileInfo(newdb.Directory + "/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904");

            Assert.IsTrue(o.IsFile(), "Exists " + o);
            Assert.IsTrue(o.IsReadOnly, "Read-only " + o);
        }
Beispiel #14
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);
            }
        }
Beispiel #15
0
        private FileInfo[] Pack(Core.Repository src, params RevObject[] list)
        {
            var pw = new PackWriter(src, NullProgressMonitor.Instance);

            foreach (RevObject o in list)
            {
                pw.addObject(o);
            }

            ObjectId name     = pw.computeName();
            FileInfo packFile = FullPackFileName(name);
            FileInfo idxFile  = FullIndexFileName(name);
            var      files    = new[] { packFile, idxFile };

            Write(files, pw);
            return(files);
        }
Beispiel #16
0
        public void CanReadMsysgitIndex()
        {
            //setup of .git directory
            var resource =
                new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"),
                                               "OneFileRepository"));
            var tempRepository =
                new DirectoryInfo(Path.Combine(trash.FullName, "OneFileRepository" + 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);
                List <GitIndex.Entry> entries = index.Members.ToList();
                Assert.AreEqual(1, entries.Count);

                GitIndex.Entry entry = entries[0];
                Assert.AreEqual("dummy.txt", entry.Name);

                Core.Ref headRef = repository.Head;
                Assert.AreEqual("refs/heads/master", headRef.Target.Name);
                Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headRef.ObjectId.Name);

                object obj = repository.MapObject(headRef.ObjectId, headRef.Name);
#pragma warning disable 0612
                Assert.IsInstanceOfType(typeof(Core.Commit), obj);  // [henon] IsInstanceOfType is obsolete
#pragma warning restore 0612
                var commit = (Core.Commit)obj;

                Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", commit.CommitId.Name);
                Assert.AreEqual(commit.Committer, commit.Author);
                Assert.AreEqual("nulltoken <*****@*****.**> 1255117188 +0200",
                                commit.Committer.ToExternalString());

                Assert.AreEqual(0, commit.ParentIds.Length);
            }
        }
        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);
            }
        }
Beispiel #18
0
        public void testWrite0()
        {
            // Create a tiny bundle, (well one of) the first commits only
            byte[] bundle = makeBundle("refs/heads/firstcommit", "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", null);

            // Then we clone a new repo from that bundle and do a simple test. This
            // makes sure
            // we could Read the bundle we created.
            Core.Repository newRepo     = createBareRepository();
            FetchResult     fetchResult = fetchFromBundle(newRepo, bundle);

            Core.Ref advertisedRef = fetchResult.GetAdvertisedRef("refs/heads/firstcommit");

            // We expect firstcommit to appear by id
            Assert.AreEqual("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", advertisedRef.ObjectId.Name);
            // ..and by name as the bundle created a new ref
            Assert.AreEqual("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", newRepo.Resolve(("refs/heads/firstcommit")).Name);
        }
        public void CanReadMsysgitIndex()
        {
            //setup of .git directory
            var resource =
                new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"),
                                               "OneFileRepository"));
            var tempRepository =
                new DirectoryInfo(Path.Combine(trash.FullName, "OneFileRepository" + 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);
                List<GitIndex.Entry> entries = index.Members.ToList();
                Assert.AreEqual(1, entries.Count);

                GitIndex.Entry entry = entries[0];
                Assert.AreEqual("dummy.txt", entry.Name);

                Core.Ref headRef = repository.Head;
                Assert.AreEqual("refs/heads/master", headRef.Target.Name);
                Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headRef.ObjectId.Name);

                object obj = repository.MapObject(headRef.ObjectId, headRef.Name);
#pragma warning disable 0612
                Assert.IsInstanceOfType(typeof (Core.Commit), obj); // [henon] IsInstanceOfType is obsolete
#pragma warning restore 0612
                var commit = (Core.Commit) obj;

                Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", commit.CommitId.Name);
                Assert.AreEqual(commit.Committer, commit.Author);
                Assert.AreEqual("nulltoken <*****@*****.**> 1255117188 +0200",
                                commit.Committer.ToExternalString());

                Assert.AreEqual(0, commit.ParentIds.Length);
            }
        }
Beispiel #20
0
        public void testWrite1()
        {
            // Create a small bundle, an early commit
            byte[] bundle = makeBundle("refs/heads/aa", db.Resolve("a").Name, null);

            // Then we clone a new repo from that bundle and do a simple test. This
            // makes sure
            // we could Read the bundle we created.
            Core.Repository newRepo     = createBareRepository();
            FetchResult     fetchResult = fetchFromBundle(newRepo, bundle);

            Core.Ref advertisedRef = fetchResult.GetAdvertisedRef("refs/heads/aa");

            Assert.AreEqual(db.Resolve("a").Name, advertisedRef.ObjectId.Name);
            Assert.AreEqual(db.Resolve("a").Name, newRepo.Resolve("refs/heads/aa").Name);
            Assert.IsNull(newRepo.Resolve("refs/heads/a"));

            // Next an incremental bundle
            bundle = makeBundle(
                "refs/heads/cc",
                db.Resolve("c").Name,
                new GitSharp.Core.RevWalk.RevWalk(db).parseCommit(db.Resolve("a").ToObjectId()));

            fetchResult   = fetchFromBundle(newRepo, bundle);
            advertisedRef = fetchResult.GetAdvertisedRef("refs/heads/cc");
            Assert.AreEqual(db.Resolve("c").Name, advertisedRef.ObjectId.Name);
            Assert.AreEqual(db.Resolve("c").Name, newRepo.Resolve("refs/heads/cc").Name);
            Assert.IsNull(newRepo.Resolve("refs/heads/c"));
            Assert.IsNull(newRepo.Resolve("refs/heads/a")); // still unknown

            try
            {
                // Check that we actually needed the first bundle
                Core.Repository newRepo2 = createBareRepository();
                fetchResult = fetchFromBundle(newRepo2, bundle);
                Assert.Fail("We should not be able to fetch from bundle with prerequisites that are not fulfilled");
            }
            catch (MissingBundlePrerequisiteException e)
            {
                Assert.IsTrue(e.Message.IndexOf(db.Resolve("refs/heads/a").Name) >= 0);
            }
        }
Beispiel #21
0
        public void testObjectMovedToNewPack2()
        {
            // Create an object and pack it. Then remove that pack and put the
            // object into a different pack file, with some other object. We
            // still should be able to access the objects.
            //
            Core.Repository eden = createBareRepository();
            RevObject       o1   = WriteBlob(eden, "o1");

            FileInfo[] out1 = Pack(eden, o1);
            Assert.AreEqual(o1.Name, Parse(o1).Name);

            ObjectLoader load1 = db.OpenBlob(o1);

            Assert.IsNotNull(load1);

            RevObject o2 = WriteBlob(eden, "o2");

            Pack(eden, o2, o1);

            // Force close, and then delete, the old pack.
            //
            WhackCache();
            Delete(out1);

            // Now here is the interesting thing... can the loader we made
            // earlier still resolve the object, even though its underlying
            // pack is gone, but the object still exists.
            //
            ObjectLoader load2 = db.OpenBlob(o1);

            Assert.IsNotNull(load2);
            Assert.AreNotSame(load1, load2);

            byte[] data2 = load2.CachedBytes;
            byte[] data1 = load1.CachedBytes;
            Assert.IsNotNull(data2);
            Assert.IsNotNull(data1);
            Assert.AreNotSame(data1, data2); // cache should be per-pack, not per object
            Assert.IsTrue(data1.SequenceEqual(data2));
            Assert.AreEqual(load2.Type, load1.Type);
        }
Beispiel #22
0
        public void testBareFileKey()
        {
            Core.Repository bare   = createBareRepository();
            DirectoryInfo   gitdir = bare.Directory;
            DirectoryInfo   parent = gitdir.Parent;

            Assert.IsNotNull(parent);

            string name = gitdir.Name;

            Assert.IsTrue(name.EndsWith(Constants.DOT_GIT_EXT));
            name = name.Slice(0, name.Length - 4);

            Assert.AreEqual(gitdir, RepositoryCache.FileKey.exact(gitdir).getFile());

            Assert.AreEqual(gitdir, RepositoryCache.FileKey.lenient(gitdir).getFile());

            // Test was "fixed" because DirectoryInfo.Equals() compares two different references
            Assert.AreEqual(gitdir.FullName, RepositoryCache.FileKey.lenient(new DirectoryInfo(Path.Combine(parent.FullName, name))).getFile().FullName);
        }
Beispiel #23
0
        private RevObject WriteBlob(Core.Repository repo, string data)
        {
            var revWalk = new GitSharp.Core.RevWalk.RevWalk(repo);

            byte[]   bytes = Constants.encode(data);
            var      ow    = new ObjectWriter(repo);
            ObjectId id    = ow.WriteBlob(bytes);

            try
            {
                Parse(id);
                Assert.Fail("Object " + id.Name + " should not exist in test repository");
            }
            catch (MissingObjectException)
            {
                // Ok
            }

            return(revWalk.lookupBlob(id));
        }
Beispiel #24
0
        public void testCacheRegisterOpen()
        {
            DirectoryInfo dir = db.Directory;

            RepositoryCache.register(db);
            using (Core.Repository exact = RepositoryCache.open(RepositoryCache.FileKey.exact(dir)))
            {
                Assert.AreSame(db, exact);
            }

            Assert.IsTrue(dir.Name.EndsWith(Constants.DOT_GIT_EXT));
            Assert.AreEqual(Constants.DOT_GIT, dir.Name);
            DirectoryInfo parent = dir.Parent;

            using (Core.Repository lenient = RepositoryCache.open(RepositoryCache.FileKey.lenient(parent)))
            {
                Assert.AreSame(db, lenient);
            }

            RepositoryCache.close(db);
        }
Beispiel #25
0
        public void testFileKeyOpenNew()
        {
            Core.Repository n = createBareRepository();

            DirectoryInfo gitdir = n.Directory;

            n.Close();
            recursiveDelete(gitdir);
            Assert.IsFalse(gitdir.Exists);

            var e =
                AssertHelper.Throws <RepositoryNotFoundException>(() => new RepositoryCache.FileKey(gitdir).open(true));

            Assert.AreEqual("repository not found: " + gitdir, e.Message);

            using (Core.Repository o = new RepositoryCache.FileKey(gitdir).open(false))
            {
                Assert.IsNotNull(o);
                Assert.AreEqual(gitdir.FullName, o.Directory.FullName);
                Assert.IsFalse(gitdir.Exists);
            }
        }
Beispiel #26
0
        public void testRenameBranchAlsoInPack()
        {
            ObjectId rb  = db.Resolve("refs/heads/b");
            ObjectId rb2 = db.Resolve("refs/heads/b~1");

            Assert.AreEqual(Core.Ref.Storage.Packed, db.getRef("refs/heads/b").StorageFormat);
            RefUpdate updateRef = db.UpdateRef("refs/heads/b");

            updateRef.NewObjectId   = rb2;
            updateRef.IsForceUpdate = true;
            RefUpdate.RefUpdateResult update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update, "internal check new ref is loose");
            Assert.AreEqual(Core.Ref.Storage.LoosePacked, db.getRef("refs/heads/b")
                            .StorageFormat);
            RefLogWriter.WriteReflog(db, rb, rb, "Just a message", "refs/heads/b");
            Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists, "no log on old branch");
            RefRename renameRef = db.RenameRef("refs/heads/b",
                                               "refs/heads/new/name");

            RefUpdate.RefUpdateResult result = renameRef.Rename();
            Assert.AreEqual(RefUpdate.RefUpdateResult.Renamed, result);
            Assert.AreEqual(rb2, db.Resolve("refs/heads/new/name"));
            Assert.IsNull(db.Resolve("refs/heads/b"));
            Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader(
                                "new/name").getLastEntry().getComment());
            Assert.AreEqual(3, db.ReflogReader("refs/heads/new/name").getReverseEntries().Count);
            Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader("refs/heads/new/name").getReverseEntries()[0].getComment());
            Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count);
            // make sure b's log file is gone too.
            Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists);

            // Create new Repository instance, to reread caches and make sure our
            // assumptions are persistent.
            using (Core.Repository ndb = new Core.Repository(db.Directory))
            {
                Assert.AreEqual(rb2, ndb.Resolve("refs/heads/new/name"));
                Assert.IsNull(ndb.Resolve("refs/heads/b"));
            }
        }
Beispiel #27
0
        /**
         * Run a hook script in the repository, returning the exit status.
         *
         * @param db
         *            repository the script should see in GIT_DIR environment
         * @param hook
         *            path of the hook script to execute, must be executable file
         *            type on this platform
         * @param args
         *            arguments to pass to the hook script
         * @return exit status code of the invoked hook
         * @throws IOException
         *             the hook could not be executed
         * @throws InterruptedException
         *             the caller was interrupted before the hook completed
         */
        protected int runHook(Core.Repository db, FileInfo hook,
                              params string[] args)
        {
            String[] argv = new String[1 + args.Length];
            argv[0] = hook.FullName;
            System.Array.Copy(args, 0, argv, 1, args.Length);

            IDictionary <String, String> env = cloneEnv();

            env.put("GIT_DIR", db.Directory.FullName);
            putPersonIdent(env, "AUTHOR", author);
            putPersonIdent(env, "COMMITTER", committer);

            DirectoryInfo cwd = db.WorkingDirectory;

            throw new NotImplementedException("Not ported yet.");
            //Process p = Runtime.getRuntime().exec(argv, toEnvArray(env), cwd);
            //p.getOutputStream().close();
            //p.getErrorStream().close();
            //p.getInputStream().close();
            //return p.waitFor();
        }
Beispiel #28
0
        public void testRenameBranchAlsoInPack()
        {
            ObjectId rb = db.Resolve("refs/heads/b");
            ObjectId rb2 = db.Resolve("refs/heads/b~1");
            Assert.AreEqual(Ref.Storage.Packed, db.getRef("refs/heads/b").StorageFormat);
            RefUpdate updateRef = db.UpdateRef("refs/heads/b");
            updateRef.NewObjectId = rb2;
            updateRef.IsForceUpdate = true;
            RefUpdate.RefUpdateResult update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update, "internal check new ref is loose");
            Assert.AreEqual(Ref.Storage.LoosePacked, db.getRef("refs/heads/b")
                    .StorageFormat);
            RefLogWriter.WriteReflog(db, rb, rb, "Just a message", "refs/heads/b");
            Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists, "no log on old branch");
            RefRename renameRef = db.RenameRef("refs/heads/b",
                    "refs/heads/new/name");
            RefUpdate.RefUpdateResult result = renameRef.Rename();
            Assert.AreEqual(RefUpdate.RefUpdateResult.Renamed, result);
            Assert.AreEqual(rb2, db.Resolve("refs/heads/new/name"));
            Assert.IsNull(db.Resolve("refs/heads/b"));
            Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader(
                    "new/name").getLastEntry().getComment());
            Assert.AreEqual(3, db.ReflogReader("refs/heads/new/name").getReverseEntries().Count);
            Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader("refs/heads/new/name").getReverseEntries()[0].getComment());
            Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count);
            // make sure b's log file is gone too.
            Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists);

            // Create new Repository instance, to reread caches and make sure our
            // assumptions are persistent.
            Core.Repository ndb = new Core.Repository(db.Directory);
            Assert.AreEqual(rb2, ndb.Resolve("refs/heads/new/name"));
            Assert.IsNull(ndb.Resolve("refs/heads/b"));
        }
        /**
	 * Creates a new empty repository.
	 *
	 * @param bare
	 *            true to create a bare repository; false to make a repository
	 *            within its working directory
	 * @return the newly created repository, opened for access
	 * @throws IOException
	 *             the repository could not be created in the temporary area
	 */
        private Core.Repository createRepository(bool bare) {
            String uniqueId = GetType().Name + Guid.NewGuid().ToString();
            String gitdirName = "test" + uniqueId + (bare ? "" : "/") + ".git";
            DirectoryInfo gitdir = new DirectoryInfo(Path.Combine(trash.FullName, gitdirName));
            Core.Repository db = new Core.Repository(gitdir);

            Assert.IsFalse(gitdir.Exists);
            db.Create();
            toClose.Add(db);
            return db;
        }
Beispiel #30
0
        /// <summary>
        /// Do it.
        /// </summary>
        public override void Execute()
        {
            if (Source.Length <= 0)
            {
                throw new ArgumentException("fatal: You must specify a repository to clone.");
            }

            if (Directory != null && GitDirectory != null)
            {
                throw new ArgumentException("conflicting usage of --git-dir and arguments");
            }

            var source = new URIish(Source);

            if (Directory == null)
            {
                try
                {
                    Directory = source.getHumanishName();
                }
                catch (InvalidOperationException e)
                {
                    throw new ArgumentException("cannot guess local name from " + source, e);
                }
            }

            if (GitDirectory == null)
            {
                GitDirectory = Path.Combine(Directory, Constants.DOT_GIT);
            }

            if (Mirror)
                Bare = true;
            if (Bare)
            {
                if (OriginName != null)
                    throw new ArgumentException("Bare+Origin", "--bare and --origin " + OriginName + " options are incompatible.");
                NoCheckout = true;
            }
            if (OriginName == null)
                OriginName = Constants.DEFAULT_REMOTE_NAME;

            if (System.IO.Directory.Exists(Directory) && System.IO.Directory.GetFileSystemEntries(Directory).Length != 0)
            {
                throw new InvalidOperationException(string.Format("destination path '{0}' already exists and is not an empty directory.", new DirectoryInfo(Directory).FullName));
            }

            var repo = new Core.Repository(new DirectoryInfo(GitDirectory));
            repo.Create(Bare);
            repo.Config.setBoolean("core", null, "bare", Bare);
            repo.Config.save();
            Repository = new Repository(repo);
            if (!Quiet)
            {
                OutputStream.WriteLine("Initialized empty Git repository in " + repo.Directory.FullName);
                OutputStream.Flush();
            }

            saveRemote(source);

            FetchResult r;
            try
            {
                r = runFetch();
            }
            catch (NoRemoteRepositoryException)
            {
                Repository.Dispose();
                throw;
            }
            GitSharp.Core.Ref branch = guessHEAD(r);
            if (!NoCheckout)
                doCheckout(branch);
        }
Beispiel #31
0
        /// <summary>
        /// Execute the command line
        /// </summary>
        /// <param name="argv"></param>
        private static void execute(string[] argv)
        {
            if (argv.Count() == 0)
            {
                ShowHelp();
            }
            else if (!argv[0].StartsWith("--") && !argv[0].StartsWith("-"))
            {

                CommandCatalog catalog = new CommandCatalog();
                CommandRef subcommand = catalog.Get(argv[0]);
                string gitdir = null;

                if (subcommand != null)
                {
                    TextBuiltin cmd = subcommand.Create();
                    List<String> args = argv.ToList();
                    GitSharp.Core.Repository repo = null;

                    try
                    {
                        for (int x = 0; x < args.Count; x++)
                        {
                            if (args[x].IndexOf("--git-dir=") > -1)
                            {
                                if (args[x].Length > 10)
                                {
                                    gitdir = args[x].Substring(11);
                                    args.RemoveAt(x);
                                    break;
                                }
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        if (Git.DefaultOutputStream != null)
                        {
                            Git.DefaultOutputStream.WriteLine("error: can't find git directory");
                            Git.DefaultOutputStream.Flush();
                        }
                        Exit(1);
                    }

                    if (cmd.RequiresRepository)
                    {
                        if (gitdir == null)
                            gitdir = Commands.AbstractCommand.FindGitDirectory(null, true, false);

                        repo = new Core.Repository(new DirectoryInfo(gitdir));
                        cmd.Init(repo, gitdir);
                    }
                    else
                        cmd.Init(null, gitdir);

                    try
                    {
                        // Remove the subcommand from the command line
                        args.RemoveAt(0);
                        cmd.Execute(args.ToArray());
                    }
                    finally
                    {
                        if (Git.DefaultOutputStream != null)
                            Git.DefaultOutputStream.Flush();

                        if (repo != null)
                            repo.Close();
                    }
                }
                else
                {
                    // List all available commands starting with argv[0] if the command
                    // specified does not exist.
                    // If no commands exist starting with argv[0], show the help screen.
                    if (!ShowCommandMatches(argv[0]))
                        ShowHelp();
                }
            }
            else
            {
                // If the first argument in the command line is an option (denoted by starting with - or --),
                // no subcommand has been specified in the command line.
                try
                {
                    arguments = options.Parse(argv);
                }
                catch (OptionException err)
                {
                    if (arguments.Count > 0)
                    {
                        Console.Error.WriteLine("fatal: " + err.Message);
                        Exit(1);
                    }
                }
            }
            Exit(0);
        }
 public override AbstractTreeIterator createSubtreeIterator(Core.Repository repo)
 {
     return(null);
 }
Beispiel #33
0
        /// <summary>
        /// Do it.
        /// </summary>
        public override void Execute()
        {
            if (Source.Length <= 0)
            {
                throw new ArgumentException("fatal: You must specify a repository to clone.");
            }

            if (Directory != null && GitDirectory != null)
            {
                throw new ArgumentException("conflicting usage of --git-dir and arguments");
            }

            var source = new URIish(Source);

            if (Directory == null)
            {
                try
                {
                    Directory = source.getHumanishName();
                }
                catch (InvalidOperationException e)
                {
                    throw new ArgumentException("cannot guess local name from " + source, e);
                }
            }

            if (GitDirectory == null)
            {
                GitDirectory = Path.Combine(Directory, Constants.DOT_GIT);
            }

            if (Mirror)
            {
                Bare = true;
            }
            if (Bare)
            {
                if (OriginName != null)
                {
                    throw new ArgumentException("Bare+Origin", "--bare and --origin " + OriginName + " options are incompatible.");
                }
                NoCheckout = true;
            }
            if (OriginName == null)
            {
                OriginName = Constants.DEFAULT_REMOTE_NAME;
            }

            if (System.IO.Directory.Exists(Directory) && System.IO.Directory.GetFileSystemEntries(Directory).Length != 0)
            {
                throw new InvalidOperationException(string.Format("destination path '{0}' already exists and is not an empty directory.", new DirectoryInfo(Directory).FullName));
            }

            var repo = new Core.Repository(new DirectoryInfo(GitDirectory));

            repo.Create(Bare);
            repo.Config.setBoolean("core", null, "bare", Bare);
            repo.Config.save();
            Repository = new Repository(repo);
            if (!Quiet)
            {
                OutputStream.WriteLine("Initialized empty Git repository in " + repo.Directory.FullName);
                OutputStream.Flush();
            }

            saveRemote(source);

            FetchResult r;

            try
            {
                r = runFetch();
            }
            catch (NoRemoteRepositoryException)
            {
                Repository.Dispose();
                throw;
            }
            GitSharp.Core.Ref branch = guessHEAD(r);
            if (!NoCheckout)
            {
                doCheckout(branch);
            }
        }
        public void Check_entries_of_msysgit_index()
        {
            using (var repo = new Core.Repository(db.Directory))
            {
                var index_path = Path.Combine(repo.Directory.FullName, "index");
                new FileInfo("Resources/index_originating_from_msysgit").CopyTo(index_path);

                var index = repo.Index;
                index.RereadIfNecessary();

                var paths = new[]
                                {
                                    "New Folder/New Ruby Program.rb",
                                    "for henon.txt",
                                    "test.cmd",
                                };

                var dict = index.Members.ToDictionary(entry => entry.Name);
                Assert.AreEqual(3, dict.Count);
                foreach (var path in paths)
                    Assert.IsTrue(dict.ContainsKey(path));
            }
        }
Beispiel #35
0
 public void test007_Open()
 {
     using (Core.Repository db2 = new Core.Repository(db.Directory))
     {
         Assert.AreEqual(db.Directory, db2.Directory);
         Assert.AreEqual(db.ObjectsDirectory.FullName, db2.ObjectsDirectory.FullName);
         Assert.AreNotSame(db.Config, db2.Config);
     }
 }
Beispiel #36
0
 public MockTransport(Core.Repository local, URIish uri, List <Core.Ref> advertisedRefs)
     : base(local, uri)
 {
     advertised = advertisedRefs;
 }