예제 #1
0
        [Test] public void Create_Repo_Add_Files_Check_Head()
        {
            var nGit     = new API_NGit();
            var tempRepo = "_tempRepo".tempDir(true);

            "TestRepo is: {0}".info(tempRepo);
            //Creating a local temp Repo
            Assert.IsFalse(tempRepo.isGitRepository(), "Should not be a repo");
            nGit.init(tempRepo);
            Assert.IsTrue(tempRepo.isGitRepository(), "Should be a repo");
            Assert.IsNull(nGit.head());

            //Adding a file (using method 1)
            nGit.file_Create("testFile.txt", "some Text");
            nGit.add_and_Commit_using_Status();
            var head1 = nGit.head();

            Assert.IsNotNull(head1);

            //Adding another file (using method 2)
            nGit.file_Create("testFile2.txt", "some Text");
            nGit.add("testFile2.txt");
            nGit.commit("Adding Another file");

            //making sure the head has changed
            var head2 = nGit.head();

            Assert.AreNotEqual(head1, head2);

            nGit.delete_Repository_And_Files();
        }
예제 #2
0
        public static RevCommit add_and_Commit_Random_File(this API_NGit nGit)
        {
            var randomFile = nGit.file_Create_Random_File();

            nGit.add(randomFile);
            var commitMessage = "Adding random file: {0}".format(randomFile);

            return(nGit.commit(commitMessage));
        }
예제 #3
0
        public ActionResult FileDiff(string path, string fromSha1, string toSha1)
        {
            Func <Repository, string, string, string, string> getDiff =
                (gitRepo, repoPath, fromCommitId, toCommitId) =>
            {
                var fromCommit = gitRepo.Resolve(fromCommitId);
                var toCommit   = gitRepo.Resolve(toCommitId);

                var outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast <OutputStream>();
                //return "diffing from {0} to  {1}".format(fromCommit, toCommit);
                var diffFormater = new DiffFormatter(outputStream);
                var pathFilter   = PathFilter.Create(repoPath);
                diffFormater.SetRepository(gitRepo);
                diffFormater.SetPathFilter(pathFilter);
                //diffFormater.Format(refLog.GetNewId(), refLog.GetOldId());
                diffFormater.Format(fromCommit, toCommit);
                return("result: " + outputStream.str());
            };

            Func <Repository, string, string, string> getFistValue =
                (gitRepo, commitSha1, repoPath) =>
            {
                var revCommit    = nGit.commit(commitSha1);
                var outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast <OutputStream>();
                var diffFormater = new DiffFormatter(outputStream);
                var pathFilter   = PathFilter.Create(repoPath);
                diffFormater.SetRepository(gitRepo);
                diffFormater.SetPathFilter(pathFilter);

                var revWalk             = new RevWalk(gitRepo);
                var canonicalTreeParser = new CanonicalTreeParser(null, revWalk.GetObjectReader(), revCommit.Tree);
                diffFormater.Format(new EmptyTreeIterator(), canonicalTreeParser);
                return(outputStream.str().fix_CRLF());
            };

            var rawDiff = fromSha1 == NGit_Consts.EMPTY_SHA1
                            ? getFistValue(nGit.repository(), fromSha1, path)
                            :  getDiff(nGit.repository(), path, fromSha1, toSha1);


            var viewFile = new View_GitFileDiff()
            {
                FilePath = path,
                FromSha1 = fromSha1,
                ToSha1   = toSha1,
                Diff     = rawDiff
            };

            return(View("~/Views/GitUserData/FileDiff.cshtml", viewFile));
        }
예제 #4
0
 public static RevCommit       commit_using_Status(this API_NGit nGit)
 {
     return(nGit.commit(nGit.status()));
 }
예제 #5
0
        public static RevCommit       commit(this API_NGit nGit, string commitMessage, string name, string email)
        {
            var person = name.personIdent(email);

            return(nGit.commit(commitMessage, person, person));
        }
예제 #6
0
 public static RevCommit       commit(this API_NGit nGit, string commitMessage)
 {
     return(nGit.commit(commitMessage, nGit.Author, nGit.Committer));
 }