Ejemplo n.º 1
0
        private bool IsValidBranchName(string name)
        {
            // Rules taken from https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
            var isValidName = !string.IsNullOrEmpty(name) &&
                              !LocalBranches.Contains(name) &&
                              !name.Any(char.IsWhiteSpace) &&
                              !name.Contains("..") &&
                              !name.Contains("~") &&
                              !name.Contains("^") &&
                              !name.Contains(":") &&
                              !name.Contains("?") &&
                              !name.Contains("*") &&
                              !name.Contains("[") &&
                              !name.Contains("//") &&
                              name.FirstOrDefault() != '/' &&
                              name.LastOrDefault() != '/' &&
                              name.LastOrDefault() != '.' &&
                              name != "@" &&
                              !name.Contains("@{") &&
                              !name.Contains("\\");

            if (!isValidName)
            {
                return(false);
            }
            foreach (var section in name.Split('/'))
            {
                isValidName = section.FirstOrDefault() != '.' &&
                              !section.EndsWith(".lock");
            }

            return(isValidName);
        }
Ejemplo n.º 2
0
        public GitResponse Merge(string fromBranch, string toBranch)
        {
            Refresh();

            if (!LocalBranches.Contains(fromBranch))
            {
                return(new GitResponse(false, EnumGitResponse.BRANCH_DOESNT_EXISTS,
                                       $"The branch {fromBranch} doesn't exists."));
            }

            if (!LocalBranches.Contains(toBranch))
            {
                return(new GitResponse(false, EnumGitResponse.BRANCH_DOESNT_EXISTS,
                                       $"The branch {toBranch} doesn't exists."));
            }

            var response = Checkout(toBranch);

            if (!response.Success)
            {
                return(response);
            }

            response = ExecuteGitCommand($"merge {fromBranch}");
            if (!response.Success)
            {
                SpectreHelper.WriteError("Merge failed, aborting !");
                var abortResponse = ExecuteGitCommand("merge --abort");
                return(new(false, EnumGitResponse.FATAL_ERROR, $"{response.Message}\n{abortResponse.Message}"));
            }

            return(response);
        }
Ejemplo n.º 3
0
        public GitResponse Checkout(string branchName)
        {
            Refresh();

            if (!LocalBranches.Contains(branchName))
            {
                return(new GitResponse(false, EnumGitResponse.BRANCH_DOESNT_EXISTS,
                                       $"The branch {branchName} doesn't exists."));
            }

            var output = ExecuteGitCommand($"checkout {branchName}");

            return(output);
        }
Ejemplo n.º 4
0
        public GitResponse PushBranchToOrigin(string branchName)
        {
            Refresh();

            if (!HasOrigin)
            {
                return(new GitResponse(false, EnumGitResponse.REPOSITORY_HAS_NO_ORIGIN,
                                       "The repository has no origin."));
            }

            if (!LocalBranches.Contains(branchName))
            {
                return(new GitResponse(false, EnumGitResponse.BRANCH_DOESNT_EXISTS,
                                       $"The branch {branchName} doesn't exists."));
            }

            return(ExecuteGitCommand($"push -u origin {branchName}"));
        }
Ejemplo n.º 5
0
        public GitResponse DeleteBranch(string branchName)
        {
            Refresh();

            if (!LocalBranches.Contains(branchName))
            {
                return(new GitResponse(false, EnumGitResponse.BRANCH_DOESNT_EXISTS,
                                       $"The branch {branchName} doesn't exists."));
            }

            var output = ExecuteGitCommand($"branch -D {branchName}");

            if (output.Success)
            {
                _needsRefresh = true;
            }

            return(output);
        }
Ejemplo n.º 6
0
        public GitResponse CreateBranchChekout(string branchName)
        {
            Refresh();

            if (LocalBranches.Contains(branchName))
            {
                return(new GitResponse(false, EnumGitResponse.BRANCH_ALREADY_EXISTS,
                                       $"The branch {branchName} already exists."));
            }

            var output = ExecuteGitCommand($"checkout -b {branchName}");

            if (output.Success)
            {
                _needsRefresh = true;
            }

            return(new GitResponse(true, EnumGitResponse.NONE,
                                   $"Branch {branchName} created successfully\n{output.Message}"));
        }