Ejemplo n.º 1
0
 public void Popout(RepositoryItem selectionDetails)
 {
     if (selectionDetails != null)
     {
         new GitShellVisible(selectionDetails.Path).InstantiateVisibleShell();
     }
 }
Ejemplo n.º 2
0
 public void ChangeRepository(RepositoryItem selectionDetails)
 {
     if (selectionDetails != null)
     {
         GitListDataContext.ConsoleControl.ClearOutput();
         GitListDataContext.ConsoleControl.WriteInput(string.Format("cd \"{0}\"", selectionDetails.Path.ToLower()),
             Color.FromRgb(1, 100, 3), false);
     }
 }
Ejemplo n.º 3
0
        public List<string> CommitLog(RepositoryItem repository)
        {
            var repo = new LibGit2Sharp.Repository(repository.Path);

            var commitLog = new List<string>();

            repo.Commits.ToList().ForEach(commit =>
            {
                commitLog.Add(string.Format("{0} - {1} : {2}", commit.Author.When.LocalDateTime, commit.Author.Name, commit.Message));
            });

            return commitLog;
        }
Ejemplo n.º 4
0
        public void ChangeRepositoryBranch(RepositoryItem item)
        {
            if (item != null && !string.IsNullOrEmpty(item.CurrentBranch))
            {
                SetRootRefreshInProgress(item.Parent);

                new Thread(() =>
                {
                    ChangeBranch(item);

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    DispatchInvoker.InvokeBackground(() =>
                    {
                        RefreshRepositories(item.Parent, false);
                    });
                }).Start();
            }
        }
Ejemplo n.º 5
0
 public List<string> Branches(RepositoryItem repository)
 {
     var repo = new LibGit2Sharp.Repository(repository.Path);
     return repo.Branches.Select(x => x.Name).Distinct().ToList();
 }
Ejemplo n.º 6
0
 public int BehindBy(RepositoryItem repository)
 {
     var repo = new LibGit2Sharp.Repository(repository.Path);
     var behindBy = repo.Head.TrackingDetails.BehindBy ?? 0;
     return behindBy;
 }
Ejemplo n.º 7
0
 public int Aheadby(RepositoryItem repository)
 {
     var repo = new LibGit2Sharp.Repository(repository.Path);
     var aheadBy = repo.Head.TrackingDetails.AheadBy ?? 0;
     return aheadBy;
 }
Ejemplo n.º 8
0
 private LibGit2Sharp.Repository CurrentBranch(RepositoryItem repository)
 {
     return new LibGit2Sharp.Repository(repository.Path);
 }
Ejemplo n.º 9
0
        public string GetCurrentBranchName(RepositoryItem item)
        {
            var branchName = new GitManager().CurrentBranchName(item);

            if (branchName == "(no branch)")
            {
                branchName = "DETACHED HEAD";
            }

            return branchName;
        }
Ejemplo n.º 10
0
        //public void Reset(RepositoryItem repository)
        //{
        //    try
        //    {
        //        var repo = new LibGit2Sharp.Repository(repository.Path);
        //        repo.RemoveUntrackedFiles();
        //        repo.Reset(ResetMode.Hard);
        //    }
        //    catch(Exception e)
        //    {
        //    }
        //}
        public void FetchAndReset(RepositoryItem repository)
        {
            var repo = new LibGit2Sharp.Repository(repository.Path);
            var currentBranch = CurrentBranch(repository);

            //foreach (Remote remote in repo.Network.Remotes)
            //{
            //    //FetchOptions options = new FetchOptions();
            //    //options.CredentialsProvider = new CredentialsHandler(
            //    //    (url, usernameFromUrl, types) =>
            //    //        new UsernamePasswordCredentials()
            //    //        {
            //    //            Username = "******",
            //    //            Password = "******"
            //    //        });
            //    //repo.Network.Pull(new Signature(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now), new PullOptions());
            //}

            List<string> Commands = new List<string>()
            {
                "git fetch --all --prune",
                //below line works ok if you are on master, not if you are on a different branch.
                //string.Format("git reset --hard {0}", string.Format("{0}/{1}",currentBranch.Head.Remote.Name, currentBranch.Head.Name)),
                //"git reset --hard",
                //string.Format("git reset --hard {0}", currentBranch.Head.TrackedBranch.UpstreamBranchCanonicalName),
                "git reset --hard HEAD^",
                "git clean -d -f -f",
                "git pull"
            };

            RunGitCommands(repository.Path, Commands);
        }
Ejemplo n.º 11
0
        private ObservableCollection<string> GetBranchList(RepositoryItem item)
        {
            var list = new ObservableCollection<string>();
            new GitManager().Branches(item).ForEach(list.Add);

            if (list.Count == 0)
            {
                list.Add("master");
            }
            list.Add("DETACHED HEAD");

            return list;
        }
Ejemplo n.º 12
0
        private void ChangeBranch(RepositoryItem item)
        {
            item.Message = null;

            new Thread(() =>
            {
                try
                {
                    if (item.CurrentBranch == "DETACHED HEAD")
                    {
                        item.Message = "You cannot checkout branch 'DETACHED HEAD'";
                    }
                    else
                    {
                        new GitManager().ChangeBranch(item, item.CurrentBranch);
                    }
                }
                catch (Exception e)
                {
                    DispatchInvoker.InvokeBackground(() =>
                    {
                        item.Message = e.Message;
                        item.InProgress = false;
                    });
                }

                DispatchInvoker.InvokeBackground(() =>
                {
                    item.CurrentBranch = GetCurrentBranchName(item);
                    item.InProgress = false;
                });

            }).Start();
        }
Ejemplo n.º 13
0
        public List<string> Changes(RepositoryItem repository)
        {
            var repo = new LibGit2Sharp.Repository(repository.Path);

            return repo.RetrieveStatus().Where(x => x.State != FileStatus.Ignored).Select(x => x.FilePath).ToList();
        }
Ejemplo n.º 14
0
 public bool IsValidRepository(RepositoryItem repository)
 {
     return LibGit2Sharp.Repository.IsValid(repository.Path);
 }
Ejemplo n.º 15
0
 public string CurrentBranchName(RepositoryItem repository)
 {
     return CurrentBranch(repository).Head.Name;
 }
Ejemplo n.º 16
0
 //public void Reset(RepositoryItem item)
 //{
 //    new GitManager().Reset(item);
 //}
 public void Fetch(RepositoryItem item)
 {
     new GitManager().FetchAndReset(item);
     DispatchInvoker.InvokeBackground(() => { item.InProgress = false; });
 }
Ejemplo n.º 17
-1
        public void ChangeBranch(RepositoryItem repository, string BranchName)
        {
            var repo = new LibGit2Sharp.Repository(repository.Path);

            var branches = repo.Branches.Where(b => b.Name == BranchName).ToList();
            if (branches.Any())
            {
                var localBranch = branches.FirstOrDefault(x => !x.IsRemote);
                if (localBranch != null)
                {
                    repo.Checkout(localBranch, new CheckoutOptions(), new Signature(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now));
                }
                else
                {
                    throw new Exception("You must checkout manually the first time");

                    //COMMENTED THIS OUT AS IT CREATES DUPLICATE REMOTE BRANCHES, For instance R15_Release will duplicate as origin/R15_Release.
                    //Current work around is to get them to check out the branch manually the first time around.

                    //var remoteBranch = branches.FirstOrDefault(x => x.IsRemote);
                    //if (remoteBranch != null)
                    //{
                    //    var newLocalBranch = repo.CreateBranch(BranchName, remoteBranch.Tip);
                    //    newLocalBranch = repo.Branches.Update(newLocalBranch,
                    //        b =>
                    //        {
                    //            b.TrackedBranch = remoteBranch.CanonicalName;
                    //        });
                    //    repo.Checkout(newLocalBranch, new CheckoutOptions(), new Signature(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now));
                    //}
                }
            }
        }