Пример #1
0
        //C:\Users\Christoph Handler\Documents\librepo\, für lokal
        //public string Backwards(string lastCheckout, string pathLocalRepo, string userName, string passWord, string projectKey, string repoName)
        public string Backwards(string lastCheckout, string pathLocalRepo) // alle Infos sind eh im Git-Ordner vorhanden
        {
            List <string> CommitIDList = new List <string>();              // Liste mit allen Commits die wir haben, beim forward einfach Liste umdrehen

            using (var repo = new Repository(pathLocalRepo))
            {
                var helpList = repo.Commits.ToList();// mit dem property DateTime haben wir die Commit-Zeite

                foreach (var x in helpList)
                {
                    CommitIDList.Add(x.Sha.Substring(0, 7));
                }
            }

            CommitIDList.Reverse();                              // Liste ist umgekehrt

            List <MyCommit> ReverseList = new List <MyCommit>(); // passt haben jetzt überall Parentwerte
            string          oldValue    = string.Empty;

            foreach (string e in CommitIDList)
            {
                MyCommit rL = new MyCommit
                {
                    CommitID       = e,
                    ParentCommitID = oldValue
                };
                oldValue = e;
                ReverseList.Add(rL);
            }

            if (String.IsNullOrEmpty(lastCheckout))
            {
                CommitIDList.Reverse();
                lastCheckout = CommitIDList.First();
            }


            ReverseList.Reverse();

            foreach (MyCommit c in ReverseList)
            {
                if (c.CommitID == lastCheckout)
                {
                    using (var repo = new Repository(pathLocalRepo))
                    {
                        var             checkoutPaths = new[] { "*" };
                        CheckoutOptions options       = new CheckoutOptions {
                            CheckoutModifiers = CheckoutModifiers.Force
                        };
                        if (String.IsNullOrEmpty(c.ParentCommitID))
                        {
                            c.ParentCommitID = c.CommitID;                            // kein weiteres Rollback mehr möglich
                        }
                        repo.CheckoutPaths(c.ParentCommitID, checkoutPaths, options); // commented out for testing
                        lastCheckout = c.ParentCommitID;
                    }
                    break;  // Commented out for testing
                }
            }


            return(lastCheckout);
        }
Пример #2
0
        //public string Forwards(string lastCheckout, string pathLocalRepo, string userName, string passWord, string projectKey, string repoName)
        public string Forwards(string lastCheckout, string pathLocalRepo)
        {
            List <string> CommitIDList = new List <string>(); // Liste mit allen Commits die wir haben, beim forward einfach Liste umdrehen

            using (var repo = new Repository(pathLocalRepo))
            {
                var helpList = repo.Commits.ToList();

                foreach (var x in helpList)
                {
                    CommitIDList.Add(x.Sha.Substring(0, 7));
                }
            }

            CommitIDList.Reverse();                              // Liste nicht umgekehren

            List <MyCommit> ReverseList = new List <MyCommit>(); // passt haben jetzt überall Parentwerte
            string          oldValue    = string.Empty;

            foreach (string e in CommitIDList)
            {
                MyCommit rL = new MyCommit
                {
                    ParentCommitID = e,
                    CommitID       = oldValue
                };

                oldValue = e;
                ReverseList.Add(rL);
            }

            if (String.IsNullOrEmpty(lastCheckout))
            {
                CommitIDList.Reverse();
                lastCheckout = CommitIDList.First();
            }


            //ReverseList.Reverse(); // hier glaube ich nicht umdrehen

            // Erzeugen einer Liste abgeschlossen



            foreach (MyCommit c in ReverseList)
            {
                if (c.CommitID == lastCheckout)
                {
                    using (var repo = new Repository(pathLocalRepo))
                    {
                        var             checkoutPaths = new[] { "*" };
                        CheckoutOptions options       = new CheckoutOptions {
                            CheckoutModifiers = CheckoutModifiers.Force
                        };
                        if (String.IsNullOrEmpty(c.ParentCommitID))
                        {
                            c.ParentCommitID = c.CommitID;                            // kein weiteres Rollback mehr möglich
                        }
                        repo.CheckoutPaths(c.ParentCommitID, checkoutPaths, options); // commented out for testing

                        lastCheckout = c.ParentCommitID;
                    }
                    break; // Commented out for testing
                }
            }


            return(lastCheckout);
        }