Exemple #1
0
        } // End Sub Init

        public virtual string GetRemoteBranchId(string path)
        {
            NGit.Api.Git repository = NGit.Api.Git.Open(path);

            // git ls-remote
            System.Collections.Generic.ICollection <NGit.Ref> refs = repository.LsRemote().SetRemote("origin").Call();

            // NGit.Ref master = refs.FirstOrDefault(a => a.GetName() == "refs/heads/master");
            NGit.Ref master = null;
            string   hash   = null;

            foreach (NGit.Ref a in refs)
            {
                if (a.GetName() == "refs/heads/master")
                {
                    master = a;
                    break;
                } // End if (a.GetName() == "refs/heads/master")
            }     // Next a


            if (master != null)
            {
                hash = master.GetObjectId().Name;
            } // End if (master != null)

            CloseRepository(repository);

            return(hash);
        } // End Function GetRemoteBranchId
Exemple #2
0
        } // End Sub ListBranches

        // https://stackoverflow.com/questions/40590039/how-to-get-the-file-list-for-a-commit-with-jgit
        // https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/api/GetRevCommitFromObjectId.java
        public virtual void ListFilesIncmt(string path, NGit.Revwalk.RevCommit commit)
        {
            NGit.Api.Git  repository = NGit.Api.Git.Open(path);
            NGit.ObjectId treeId     = commit.Tree.Id;

            NGit.Treewalk.TreeWalk treeWalk = new NGit.Treewalk.TreeWalk(repository.GetRepository());

            treeWalk.Reset(treeId);

            while (treeWalk.Next())
            {
                string filePath = treeWalk.PathString;
                System.Console.WriteLine(filePath);
            }

            NGit.Ref      @ref = repository.GetRepository().GetRef("refs/heads/master");
            NGit.ObjectId head = @ref.GetObjectId();
            using (NGit.Revwalk.RevWalk walk = new NGit.Revwalk.RevWalk(repository.GetRepository()))
            {
                NGit.Revwalk.RevCommit headCommit = walk.ParseCommit(head);
            }

            NGit.ObjectId commitIdFromHash = repository.GetRepository().Resolve("revstr");
        }