Exemplo n.º 1
0
        public static ArgumentString RebaseCmd(
            string branch, bool interactive, bool preserveMerges, bool autosquash, bool autoStash, bool ignoreDate, bool committerDateIsAuthorDate, string from = null, string onto = null)
        {
            if (from == null ^ onto == null)
            {
                throw new ArgumentException($"For arguments \"{nameof(from)}\" and \"{nameof(onto)}\", either both must have values, or neither may.");
            }

            var builder = new GitArgumentBuilder("rebase");

            if (ignoreDate)
            {
                builder.Add("--ignore-date");
            }
            else if (committerDateIsAuthorDate)
            {
                builder.Add("--committer-date-is-author-date");
            }
            else
            {
                if (interactive)
                {
                    builder.Add("-i");
                    builder.Add(autosquash ? "--autosquash" : "--no-autosquash");
                }

                if (preserveMerges)
                {
                    builder.Add(GitVersion.Current.SupportRebaseMerges ? "--rebase-merges" : "--preserve-merges");
                }
            }

            builder.Add(autoStash, "--autostash");
            builder.Add(from.QuoteNE());
            builder.Add(branch.Quote());
            builder.Add(onto != null, $"--onto {onto}");

            return(builder);
        }
Exemplo n.º 2
0
        /// <returns>null if no info in .gitattributes (or ambiguous). True if marked as binary, false if marked as text</returns>
        private static bool?IsBinaryAccordingToGitAttributes(GitModule module, string fileName)
        {
            string[] diffValues = { "set", "astextplain", "ada", "bibtext", "cpp", "csharp", "fortran", "html", "java", "matlab", "objc", "pascal", "perl", "php", "python", "ruby", "tex" };
            var      cmd        = new GitArgumentBuilder("check-attr")
            {
                "-z",
                "diff",
                "text",
                "crlf",
                "eol",
                "--",
                fileName.Quote()
            };
            string result     = module.GitExecutable.GetOutput(cmd);
            var    lines      = result.Split('\n', '\0');
            var    attributes = new Dictionary <string, string>();

            for (int i = 0; i < lines.Length - 2; i += 3)
            {
                attributes[lines[i + 1].Trim()] = lines[i + 2].Trim();
            }

            if (attributes.TryGetValue("diff", out var diff))
            {
                if (diff == "unset")
                {
                    return(true);
                }

                if (diffValues.Contains(diff))
                {
                    return(false);
                }
            }

            if (attributes.TryGetValue("text", out var text))
            {
                if (text != "unset" && text != "unspecified")
                {
                    return(false);
                }
            }

            if (attributes.TryGetValue("crlf", out var crlf))
            {
                if (crlf != "unset" && crlf != "unspecified")
                {
                    return(false);
                }
            }

            if (attributes.TryGetValue("eol", out var eol))
            {
                if (eol != "unset" && eol != "unspecified")
                {
                    return(false);
                }
            }

            return(null);
        }