RunGitCmd() public method

Run git command, console window is hidden, wait for exit, redirect output
public RunGitCmd ( string arguments, Encoding encoding = null, byte stdInput = null ) : string
arguments string
encoding Encoding
stdInput byte
return string
Exemplo n.º 1
0
 public void Execute(GitModule module)
 {
     if (Dto.Amend)
         Dto.Result = module.RunGitCmd("commit --amend -m \"" + Dto.Message + "\"");
     else
         Dto.Result = module.RunGitCmd("commit -m \"" + Dto.Message + "\"");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the commit info for submodule.
        /// </summary>
        public static void UpdateCommitMessage(CommitData data, GitModule module, string sha1, ref string error)
        {
            if (module == null)
                throw new ArgumentNullException("module");
            if (sha1 == null)
                throw new ArgumentNullException("sha1");

            //Do not cache this command, since notes can be added
            string arguments = string.Format(CultureInfo.InvariantCulture,
                    "log -1 --pretty=\"format:" + ShortLogFormat + "\" {0}", sha1);
            var info = module.RunGitCmd(arguments, GitModule.LosslessEncoding);

            if (info.Trim().StartsWith("fatal"))
            {
                error = "Cannot find commit " + sha1;
                return;
            }

            int index = info.IndexOf(sha1) + sha1.Length;

            if (index < 0)
            {
                error = "Cannot find commit " + sha1;
                return;
            }
            if (index >= info.Length)
            {
                error = info;
                return;
            }

            UpdateBodyInCommitData(data, info, module);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets branches which contain the given commit.
        /// If both local and remote branches are requested, remote branches are prefixed with "remotes/"
        /// (as returned by git branch -a)
        /// </summary>
        /// <param name="sha1">The sha1.</param>
        /// <param name="getLocal">Pass true to include local branches</param>
        /// <param name="getRemote">Pass true to include remote branches</param>
        /// <returns></returns>
        public static IEnumerable<string> GetAllBranchesWhichContainGivenCommit(GitModule module, string sha1, bool getLocal, bool getRemote)
        {
            string args = "--contains " + sha1;
            if (getRemote && getLocal)
                args = "-a "+args;
            else if (getRemote)
                args = "-r "+args;
            else if (!getLocal)
                return new string[]{};
            string info = module.RunGitCmd("branch " + args, GitModule.SystemEncoding);
            if (info.Trim().StartsWith("fatal") || info.Trim().StartsWith("error:"))
                return new List<string>();

            string[] result = info.Split(new[] { '\r', '\n', '*' }, StringSplitOptions.RemoveEmptyEntries);

            // Remove symlink targets as in "origin/HEAD -> origin/master"
            for (int i = 0; i < result.Length; i++)
            {
                string item = result[i].Trim();
                int idx;
                if (getRemote && ((idx = item.IndexOf(" ->")) >= 0))
                {
                    item = item.Substring(0, idx);
                }
                result[i] = item;
            }

            return result;
        }
Exemplo n.º 4
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 aModule, string fileName)
        {
            string[] diffvals = { "set", "astextplain", "ada", "bibtext", "cpp", "csharp", "fortran", "html", "java", "matlab", "objc", "pascal", "perl", "php", "python", "ruby", "tex" };
            string cmd = "check-attr -z diff text crlf eol -- " + fileName;
            string result = aModule.RunGitCmd(cmd);
            var lines = result.Split(new[] { '\n', '\0' }, StringSplitOptions.RemoveEmptyEntries);
            var attributes = new Dictionary<string, string>();
            foreach (var line in lines)
            {
                var values = line.Split(':');
                if (values.Length == 3)
                    attributes[values[1].Trim()] = values[2].Trim();
            }

            string val;
            if (attributes.TryGetValue("diff", out val))
            {
                if (val == "unset")
                    return true;
                if (diffvals.Contains(val))
                    return false;
            }
            if (attributes.TryGetValue("text", out val))
            {
                if (val != "unset" && val != "unspecified")
                    return false;
            }
            if (attributes.TryGetValue("crlf", out val))
            {
                if (val != "unset" && val != "unspecified")
                    return false;
            }
            if (attributes.TryGetValue("eol", out val))
            {
                if (val != "unset" && val != "unspecified")
                    return false;
            }
            return null;
        }
Exemplo n.º 5
0
        private void generateListOfChangesInSubmodulesChangesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var stagedFiles = Staged.AllItems;

            Dictionary<string, string> modules = stagedFiles.Where(it => it.IsSubmodule).
                Select(item => item.Name).ToDictionary(item => Module.GetSubmoduleNameByPath(item));
            if (modules.Count == 0)
                return;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Submodule" + (modules.Count == 1 ? " " : "s ") +
                String.Join(", ", modules.Keys) + " updated.");
            sb.AppendLine();
            foreach (var item in modules)
            {
                string diff = Module.RunGitCmd(
                     string.Format("diff --cached -z -- {0}", item.Value));
                var lines = diff.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                const string subprojCommit = "Subproject commit ";
                var from = lines.Single(s => s.StartsWith("-" + subprojCommit)).Substring(subprojCommit.Length + 1);
                var to = lines.Single(s => s.StartsWith("+" + subprojCommit)).Substring(subprojCommit.Length + 1);
                if (!String.IsNullOrEmpty(from) && !String.IsNullOrEmpty(to))
                {
                    sb.AppendLine("Submodule " + item.Key + ":");
                    GitModule module = new GitModule(Module.WorkingDir + item.Value + Settings.PathSeparator);
                    string log = module.RunGitCmd(
                         string.Format("log --pretty=format:\"    %m %h - %s\" --no-merges {0}...{1}", from, to));
                    if (log.Length != 0)
                        sb.AppendLine(log);
                    else
                        sb.AppendLine("    * Revision changed to " + to.Substring(0, 7));
                    sb.AppendLine();
                }
            }
            Message.Text = sb.ToString().TrimEnd();
        }
 public static string GetConfigSvnRemoteFetch(GitModule aModule)
 {
     return aModule.RunGitCmd("config svn-remote.svn.fetch");
 }
            private static string GetLostCommitLog(GitModule aModule, string hash)
            {
                if (string.IsNullOrEmpty(hash) || !GitRevision.Sha1HashRegex.IsMatch(hash))
                    throw new ArgumentOutOfRangeException("hash", hash, "Hash must be a valid SHA1 hash.");

                return aModule.RunGitCmd(string.Format(LogCommandArgumentsFormat, hash), GitModule.LosslessEncoding);
            }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the commit info for submodule.
        /// </summary>
        /// <param name="sha1">The sha1.</param>
        /// <returns></returns>
        public static CommitData GetCommitData(GitModule module, string sha1, ref string error)
        {
            if (module == null)
                throw new ArgumentNullException("module");
            if (sha1 == null)
                throw new ArgumentNullException("sha1");

            //Do not cache this command, since notes can be added
            string info = module.RunGitCmd(
                string.Format(
                    "log -1 --pretty=raw --show-notes=* {0}", sha1));

            if (info.Trim().StartsWith("fatal"))
            {
                error = "Cannot find commit" + sha1;
                return null;
            }

            info = RemoveRedundancies(info);

            int index = info.IndexOf(sha1) + sha1.Length;

            if (index < 0)
            {
                error = "Cannot find commit" + sha1;
                return null;
            }
            if (index >= info.Length)
            {
                error = info;
                return null;
            }

            CommitData commitInformation = CreateFromRawData(info);

            return commitInformation;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets all tags which contain the given commit.
        /// </summary>
        /// <param name="sha1">The sha1.</param>
        /// <returns></returns>
        public static IEnumerable<string> GetAllTagsWhichContainGivenCommit(GitModule module, string sha1)
        {
            string info = module.RunGitCmd("tag --contains " + sha1, GitModule.SystemEncoding);

            if (info.Trim().StartsWith("fatal") || info.Trim().StartsWith("error:"))
                return new List<string>();
            return info.Split(new[] { '\r', '\n', '*', ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }
Exemplo n.º 10
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 aModule, string fileName)
 {
     string cmd = "check-attr diff -z -- " + fileName;
     string result = aModule.RunGitCmd(cmd);
     var lines = result.Split(new[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
     foreach (var line in lines)
     {
         var values = line.Split(':');
         if (values.Length == 3 && values[1].Trim() == "diff")
         {
             if (values[2].Trim() == "unset")
                 return true;
             if (values[2].Trim() == "set")
                 return false;
         }
     }
     return null;
 }