Exemple #1
0
        private void StartSelectCheckout()
        {
            const string selectDescription = "Select a branch to check out";

            using Repository repo = new Repository(Environment.CurrentDirectory);

            var availableBranches = repo.Branches.OrderBy(b => b.IsRemote).ToArray();

            if (availableBranches.Length < 1)
            {
                Log.Error("No branches found.");
                Environment.Exit(1);
            }

            string[] branchNames = availableBranches.Select(b => b.FriendlyName).ToArray();

            int selectedIndex = new SimpleSelect(selectDescription, branchNames).Show();

            if (selectedIndex < 0)
            {
                return;
            }

            if (availableBranches[selectedIndex].IsRemote)
            {
                CheckoutRemote(repo, availableBranches[selectedIndex]);
                return;
            }

            GitUtils.CheckOutBranch(repo, availableBranches[selectedIndex]);
            GitUtils.ShowLatestCommit(repo);
        }
Exemple #2
0
        private void StartSelectReview(Branch[] options = null)
        {
            var selectDescription = "There were more than one results. Select a branch to review:";

            if (options == null)
            {
                selectDescription = "Select a branch to review";
                GitUtils.PerformFetch();
            }
            using Repository repo = new Repository(Environment.CurrentDirectory);

            var availableBranches = options ?? repo.Branches.Where(b => b.IsRemote).ToArray();

            if (availableBranches.Length < 1)
            {
                Log.Error("No remote branches found.");
                Environment.Exit(1);
            }

            string[] branchNames = availableBranches.Select(b => b.FriendlyName).ToArray();

            int selectedIndex = new SimpleSelect(selectDescription, branchNames).Show();

            if (selectedIndex < 0)
            {
                return;
            }

            GitUtils.CheckOutBranch(repo, availableBranches[selectedIndex]);
            GitUtils.ShowLatestCommit(repo);
        }
Exemple #3
0
 private void CheckoutRemote(Repository repo, Branch branch)
 {
     Log.Blue("Only remote found.");
     GitUtils.PerformFetch();
     Console.WriteLine();
     GitUtils.CheckOutBranch(GetLocalName(branch));
     GitUtils.ShowLatestCommit(repo);
 }
Exemple #4
0
        private void PullOriginHead()
        {
            using Repository repo = new Repository(Environment.CurrentDirectory);
            string currentHead = repo.Head.FriendlyName;

            GitUtils.PerformPull(currentHead);
            GitUtils.ShowLatestCommit(repo);
        }
Exemple #5
0
        public void RunShortcut(string action)
        {
            GitUtils.CheckIfRepository();
            using Repository repo = new Repository(Environment.CurrentDirectory);

            Branch branch;

            try
            {
                branch = repo.Branches.First(b => !b.IsRemote && IsRequiredBranch(action, b));
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException)
                {
                    branch = null;
                }
                else
                {
                    throw;
                }
            }

            if (branch == null)
            {
                Log.Error("No such branch found.");
                return;
            }

            GitUtils.CheckOutBranch(repo, branch);
            GitUtils.ShowLatestCommit(repo);

            if (Args.Length == 1 && Args[0] == "-r")
            {
                GitUtils.PerformPull(branch.FriendlyName);
                GitUtils.ShowLatestCommit(repo);
                return;
            }

            if (Args.Length > 0)
            {
                HandleUnknownParam();
            }
        }
Exemple #6
0
        private void StartCheckout(string arg)
        {
            using Repository repo = new Repository(Environment.CurrentDirectory);
            Branch branch;

            try
            {
                branch = repo.Branches
                         .OrderBy(b => b.IsRemote)
                         .First(b => b.FriendlyName.Contains(arg));
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException)
                {
                    branch = null;
                }
                else
                {
                    throw;
                }
            }

            if (branch == null)
            {
                Log.Error("No such branch found.");
                return;
            }

            if (branch.IsRemote)
            {
                CheckoutRemote(repo, branch);
                return;
            }

            GitUtils.CheckOutBranch(repo, branch);
            GitUtils.ShowLatestCommit(repo);
        }
Exemple #7
0
        private void StartReview(string arg)
        {
            GitUtils.PerformFetch();

            using Repository repo = new Repository(Environment.CurrentDirectory);
            var results = repo.Branches
                          .Where(b => b.IsRemote && b.FriendlyName.Contains(arg))
                          .ToArray();

            if (results.Length == 0)
            {
                Log.Error("No such branch found.");
                return;
            }
            if (results.Length > 1)
            {
                StartSelectReview(results);
                return;
            }

            GitUtils.CheckOutBranch(repo, results[0]);
            GitUtils.ShowLatestCommit(repo);
        }