Beispiel #1
0
        /// <exception cref="System.Exception"></exception>
        public virtual void TestCheckoutMixedNewlines()
        {
            // "git config core.autocrlf true"
            StoredConfig config = git.GetRepository().GetConfig();

            config.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF
                              , true);
            config.Save();
            // edit <FILE1>
            FilePath written = WriteTrashFile(FILE1, "4\r\n4");

            NUnit.Framework.Assert.AreEqual("4\r\n4", Read(written));
            // "git add <FILE1>"
            git.Add().AddFilepattern(FILE1).Call();
            // "git commit -m 'CRLF'"
            git.Commit().SetMessage("CRLF").Call();
            // edit <FILE1>
            written = WriteTrashFile(FILE1, "4\n4");
            NUnit.Framework.Assert.AreEqual("4\n4", Read(written));
            // "git add <FILE1>"
            git.Add().AddFilepattern(FILE1).Call();
            // "git checkout -- <FILE1>
            git.Checkout().AddPath(FILE1).Call();
            // "git status" => clean
            Status status = git.Status().Call();

            NUnit.Framework.Assert.AreEqual(0, status.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
        }
        public virtual void WorkingDirectoryEditPreCommit()
        {
            WriteTrashFile(PATH, "content2");
            RevCommit stashed = git.StashCreate().Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.AreEqual("content", Read(committedFile));
            NUnit.Framework.Assert.IsTrue(git.Status().Call().IsClean());
            string path2 = "file2.txt";

            WriteTrashFile(path2, "content3");
            git.Add().AddFilepattern(path2).Call();
            NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("adding file").Call());
            ObjectId unstashed = git.StashApply().Call();

            NUnit.Framework.Assert.AreEqual(stashed, unstashed);
            Status status = git.Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetAdded().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetRemoved().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, status.GetModified().Count);
            NUnit.Framework.Assert.IsTrue(status.GetModified().Contains(PATH));
        }
        public virtual void WorkingDirectoryDeleteIndexEdit()
        {
            WriteTrashFile(PATH, "content2");
            git.Add().AddFilepattern(PATH).Call();
            FileUtils.Delete(committedFile);
            NUnit.Framework.Assert.IsFalse(committedFile.Exists());
            RevCommit stashed = git.StashCreate().Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.AreEqual("content", Read(committedFile));
            ObjectId unstashed = git.StashApply().Call();

            NUnit.Framework.Assert.AreEqual(stashed, unstashed);
            NUnit.Framework.Assert.IsFalse(committedFile.Exists());
            Status status = git.Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetAdded().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetModified().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, status.GetRemoved().Count);
            NUnit.Framework.Assert.IsTrue(status.GetRemoved().Contains(PATH));
        }
        public virtual void MultipleEdits()
        {
            string addedPath = "file2.txt";

            git.Rm().AddFilepattern(PATH).Call();
            FilePath addedFile = WriteTrashFile(addedPath, "content2");

            git.Add().AddFilepattern(addedPath).Call();
            RevCommit stashed = git.StashCreate().Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.IsTrue(committedFile.Exists());
            NUnit.Framework.Assert.IsFalse(addedFile.Exists());
            ObjectId unstashed = git.StashApply().Call();

            NUnit.Framework.Assert.AreEqual(stashed, unstashed);
            Status status = git.Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetModified().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, status.GetRemoved().Count);
            NUnit.Framework.Assert.IsTrue(status.GetRemoved().Contains(PATH));
            NUnit.Framework.Assert.AreEqual(1, status.GetAdded().Count);
            NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(addedPath));
        }
        public virtual void WorkingDirectoryDeleteIndexAdd()
        {
            string   path  = "file2.txt";
            FilePath added = WriteTrashFile(path, "content2");

            NUnit.Framework.Assert.IsTrue(added.Exists());
            git.Add().AddFilepattern(path).Call();
            FileUtils.Delete(added);
            NUnit.Framework.Assert.IsFalse(added.Exists());
            RevCommit stashed = git.StashCreate().Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.IsFalse(added.Exists());
            ObjectId unstashed = git.StashApply().Call();

            NUnit.Framework.Assert.AreEqual(stashed, unstashed);
            NUnit.Framework.Assert.AreEqual("content2", Read(added));
            Status status = git.Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetModified().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetRemoved().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, status.GetAdded().Count);
            NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path));
        }
        public virtual void WorkingDirectoryModifyInSubfolder()
        {
            string   path          = "d1/d2/f.txt";
            FilePath subfolderFile = WriteTrashFile(path, "content");

            git.Add().AddFilepattern(path).Call();
            head = git.Commit().SetMessage("add file").Call();
            WriteTrashFile(path, "content2");
            RevCommit stashed = git.StashCreate().Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.AreEqual("content", Read(subfolderFile));
            ObjectId unstashed = git.StashApply().Call();

            NUnit.Framework.Assert.AreEqual(stashed, unstashed);
            NUnit.Framework.Assert.AreEqual("content2", Read(subfolderFile));
            Status status = git.Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetAdded().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetRemoved().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, status.GetModified().Count);
            NUnit.Framework.Assert.IsTrue(status.GetModified().Contains(path));
        }
        public virtual void StashChangeInANewSubdirectory()
        {
            string subdir      = "subdir";
            string fname       = "file2.txt";
            string path        = subdir + "/" + fname;
            string otherBranch = "otherbranch";

            WriteTrashFile(subdir, fname, "content2");
            git.Add().AddFilepattern(path).Call();
            RevCommit stashed = git.StashCreate().Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.IsTrue(git.Status().Call().IsClean());
            git.BranchCreate().SetName(otherBranch).Call();
            git.Checkout().SetName(otherBranch).Call();
            ObjectId unstashed = git.StashApply().Call();

            NUnit.Framework.Assert.AreEqual(stashed, unstashed);
            Status status = git.Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetRemoved().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetModified().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, status.GetAdded().Count);
            NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path));
        }
        public virtual void WorkingDirectoryModify()
        {
            WriteTrashFile("file.txt", "content2");
            RevCommit stashed = git.StashCreate().Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.AreEqual("content", Read(committedFile));
            ObjectId unstashed = git.StashApply().Call();

            NUnit.Framework.Assert.AreEqual(stashed, unstashed);
            NUnit.Framework.Assert.AreEqual("content2", Read(committedFile));
            Status status = git.Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetAdded().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetRemoved().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, status.GetModified().Count);
            NUnit.Framework.Assert.IsTrue(status.GetModified().Contains(PATH));
        }
        public virtual void IndexDelete()
        {
            git.Rm().AddFilepattern("file.txt").Call();
            RevCommit stashed = git.StashCreate().Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.AreEqual("content", Read(committedFile));
            ObjectId unstashed = git.StashApply().Call();

            NUnit.Framework.Assert.AreEqual(stashed, unstashed);
            NUnit.Framework.Assert.IsFalse(committedFile.Exists());
            Status status = git.Status().Call();

            NUnit.Framework.Assert.IsTrue(status.GetAdded().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetModified().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty());
            NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty());
            NUnit.Framework.Assert.AreEqual(1, status.GetRemoved().Count);
            NUnit.Framework.Assert.IsTrue(status.GetRemoved().Contains(PATH));
        }
Beispiel #10
0
        public virtual void TestAddHugeFile()
        {
            Measure("Commencing test");
            FilePath         file = new FilePath(db.WorkTree, "a.txt");
            RandomAccessFile rf   = new RandomAccessFile(file, "rw");

            rf.SetLength(4429185024L);
            rf.Close();
            Measure("Created file");
            Git git = new Git(db);

            git.Add().AddFilepattern("a.txt").Call();
            Measure("Added file");
            NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, length:134217728, sha1:b8cfba97c2b962a44f080b3ca4e03b3204b6a350]"
                                            , IndexState(LENGTH | CONTENT_ID));
            Status status = git.Status().Call();

            Measure("Status after add");
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetAdded());
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
            // Does not change anything, but modified timestamp
            rf = new RandomAccessFile(file, "rw");
            rf.Write(0);
            rf.Close();
            status = git.Status().Call();
            Measure("Status after non-modifying update");
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetAdded());
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
            // Change something
            rf = new RandomAccessFile(file, "rw");
            rf.Write('a');
            rf.Close();
            status = git.Status().Call();
            Measure("Status after modifying update");
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetAdded());
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetModified());
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
            // Truncate mod 4G and re-establish equality
            rf = new RandomAccessFile(file, "rw");
            rf.SetLength(134217728L);
            rf.Write(0);
            rf.Close();
            status = git.Status().Call();
            Measure("Status after truncating update");
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetAdded());
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetModified());
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
            // Change something
            rf = new RandomAccessFile(file, "rw");
            rf.Write('a');
            rf.Close();
            status = git.Status().Call();
            Measure("Status after modifying and truncating update");
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetAdded());
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetModified());
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
            // Truncate to entry length becomes negative int
            rf = new RandomAccessFile(file, "rw");
            rf.SetLength(3429185024L);
            rf.Write(0);
            rf.Close();
            git.Add().AddFilepattern("a.txt").Call();
            Measure("Added truncated file");
            NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, length:-865782272, sha1:59b3282f8f59f22d953df956ad3511bf2dc660fd]"
                                            , IndexState(LENGTH | CONTENT_ID));
            status = git.Status().Call();
            Measure("Status after status on truncated file");
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetAdded());
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
            // Change something
            rf = new RandomAccessFile(file, "rw");
            rf.Write('a');
            rf.Close();
            status = git.Status().Call();
            Measure("Status after modifying and truncating update");
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetAdded());
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetModified());
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
            git.Commit().SetMessage("make a commit").Call();
            Measure("After commit");
            status = git.Status().Call();
            Measure("After status after commit");
            NUnit.Framework.Assert.AreEqual(0, status.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            AssertCollectionEquals(Arrays.AsList("a.txt"), status.GetModified());
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
            git.Reset().SetMode(ResetCommand.ResetType.HARD).Call();
            Measure("After reset --hard");
            NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, length:-865782272, sha1:59b3282f8f59f22d953df956ad3511bf2dc660fd]"
                                            , IndexState(LENGTH | CONTENT_ID));
            status = git.Status().Call();
            Measure("Status after hard reset");
            NUnit.Framework.Assert.AreEqual(0, status.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetConflicting().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, status.GetUntracked().Count);
        }