RunCmd() public static method

Run command, console window is hidden, wait for exit, redirect output
public static RunCmd ( string cmd, string arguments ) : string
cmd string
arguments string
return string
Ejemplo n.º 1
0
        /// <summary>
        /// Gets the commit info.
        /// </summary>
        /// <param name="sha1">The sha1.</param>
        /// <returns></returns>
        public static CommitInformation GetCommitInfo(string sha1)
        {
            //Do not cache this command, since notes can be added
            string info = GitCommandHelpers.RunCmd(
                Settings.GitCommand,
                string.Format(
                    "show -s --pretty=raw --show-notes=* {0}", sha1));

            if (info.Trim().StartsWith("fatal"))
            {
                return(new CommitInformation("Cannot find commit" + sha1, ""));
            }

            info = RemoveRedundancies(info);

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

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

            CommitInformation commitInformation = CreateFromRawData(info);

            return(commitInformation);
        }
        public IList <IGitSubmodule> GetSubmodules()
        {
            var submodules = GitCommandHelpers.RunCmd(Settings.GitCommand, "submodule status").Split('\n');

            IList <IGitSubmodule> submoduleList = new List <IGitSubmodule>();

            string lastLine = null;

            foreach (var submodule in submodules)
            {
                if (submodule.Length < 43)
                {
                    continue;
                }

                if (submodule.Equals(lastLine))
                {
                    continue;
                }

                lastLine = submodule;

                submoduleList.Add(GitCommandHelpers.CreateGitSubmodule(submodule));
            }

            return(submoduleList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets all tags which contain the given commit.
        /// </summary>
        /// <param name="sha1">The sha1.</param>
        /// <returns></returns>
        public static IEnumerable <string> GetAllTagsWhichContainGivenCommit(string sha1)
        {
            string info = GitCommandHelpers.RunCmd(Settings.GitCommand, "tag --contains " + sha1);


            if (info.Trim().StartsWith("fatal") || info.Trim().StartsWith("error:"))
            {
                return(new List <string>());
            }
            return(info.Split(new[] { '\r', '\n', '*', ' ' }, StringSplitOptions.RemoveEmptyEntries));
        }
Ejemplo n.º 4
0
 public void Execute()
 {
     if (Dto.Amend)
     {
         Dto.Result = GitCommandHelpers.RunCmd(Settings.GitCommand, "commit --amend -m \"" + Dto.Message + "\"");
     }
     else
     {
         Dto.Result = GitCommandHelpers.RunCmd(Settings.GitCommand, "commit -m \"" + Dto.Message + "\"");
     }
 }
Ejemplo n.º 5
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="getLocal">Pass true to include remote branches</param>
        /// <returns></returns>
        public static IEnumerable <string> GetAllBranchesWhichContainGivenCommit(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 = GitCommandHelpers.RunCmd(Settings.GitCommand, "branch " + args);

            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);
        }
Ejemplo n.º 6
0
 public void Execute()
 {
     Dto.Result = GitCommandHelpers.RunCmd(Settings.GitCommand, "push");
 }
Ejemplo n.º 7
0
 public void Execute()
 {
     Dto.Result = GitCommandHelpers.RunCmd(Settings.GitCommand, "checkout " + Dto.Name);
 }
Ejemplo n.º 8
0
 public void Execute()
 {
     Dto.Result = GitCommandHelpers.RunCmd(Settings.GitCommand, "diff -z \"" + Dto.From + "\"..\"" + Dto.To + "\" -- \"" + Dto.FileName + "\"");
 }
 public string RunGit(string arguments)
 {
     return(GitCommandHelpers.RunCmd(Settings.GitCommand, arguments));
 }