Exemplo n.º 1
0
        //Returns list of stashes, in order by index
        //Returned stash is in form "branch:message"
        public static void ListStash(Action <CommandOutput, List <string> > onComplete)
        {
            GitGud.RunCommand("stash list", (output) =>
            {
                //Error catching
                if (output.errorData != null)
                {
                    onComplete(output, null);
                    return;
                }

                //Split lines
                List <string> stashes = new List <string>();
                foreach (string line in output.outputData.Split('\n'))
                {
                    //Each line is in form "@stash{index}: on branch: message"
                    string[] parts = line.Split(':');
                    string branch  = parts[1].Replace("On ", "");
                    string message = "";
                    if (parts.Length > 2)
                    {
                        message = parts[2];
                    }

                    stashes.Add(branch + ":" + message);
                }

                onComplete(output, stashes);
            });
        }
Exemplo n.º 2
0
 public static void Commit(string message, Action <CommandOutput> onComplete)
 {
     if (message == "")
     {
         GitGud.RunCommand("commit", onComplete);
     }
     else
     {
         GitGud.RunCommand("commit --message=\"" + message + "\"", onComplete);
     }
 }
Exemplo n.º 3
0
 public static void Status(bool shortMode, Action <CommandOutput> onComplete)
 {
     if (shortMode)
     {
         GitGud.RunCommand("status -s --untracked-files=all", onComplete);
     }
     else
     {
         GitGud.RunCommand("status", onComplete);
     }
 }
Exemplo n.º 4
0
 //Simple push command
 public static void Push(bool all, Action <CommandOutput> onComplete)
 {
     if (all)
     {
         GitGud.RunCommand("push --all", onComplete);
     }
     else
     {
         GitGud.RunCommand("push", onComplete);
     }
 }
Exemplo n.º 5
0
 //Create a new stash
 public static void PushStash(string message, Action <CommandOutput> onComplete)
 {
     if (message == "" || message == null)
     {
         GitGud.RunCommand("stash push", onComplete);
     }
     else
     {
         GitGud.RunCommand("stash push --message=\"" + message + "\"", onComplete);
     }
 }
Exemplo n.º 6
0
 //TODO: Use this new form of error checking in future functions
 public static void CurrentBranch(Action <string> onSuccess, Action <string> onError = null)
 {
     GitGud.RunCommand("rev-parse --abbrev-ref HEAD", (output) =>
     {
         if (output.errorData != null)
         {
             onError(null);
             return;
         }
         onSuccess(output.outputData);
     });
 }
Exemplo n.º 7
0
        //Log with a internal format, which returns a list of commit objects
        public static void Log(string filter, Action <CommandOutput, List <Commit> > onComplete)
        {
            Action <CommandOutput> onLogComplete = (output) =>
            {
                //Error catching
                if (output.errorData != null)
                {
                    onComplete(output, null);
                    return;
                }

                List <Commit> commits = new List <Commit>();

                if (output.outputData == null)
                {
                    onComplete(output, commits);
                    return;
                }

                //Convert log string into commit format
                string[] commitStrings = output.outputData.Split('\n');

                foreach (string commitStr in commitStrings)
                {
                    string[] components = commitStr.Split(',');
                    Commit   commit     = new Commit();
                    commit.hash         = components[0];
                    commit.tree         = components[1];
                    commit.parent       = components[2];
                    commit.author_name  = components[3];
                    commit.author_email = components[4];
                    commit.date         = components[5];
                    commit.subject      = components[6];

                    commits.Add(commit);
                }

                onComplete(output, commits);
            };


            string format = "%H,%T,%P,%an,%ae,%ad,'%s";

            if (filter == "" || filter == null)
            {
                GitGud.RunCommand("log --pretty=\"" + format + "\"", onLogComplete);
            }
            else
            {
                GitGud.RunCommand("log --pretty=\"" + format + "\" " + filter, onLogComplete);
            }
        }
Exemplo n.º 8
0
        //Log with a custom format, returns raw output string
        public static void LogFormat(string format, string filter, Action <CommandOutput, string> onComplete)
        {
            Action <CommandOutput> onLogComplete = (output) =>
            {
                onComplete(output, output.outputData);
            };

            if (filter == "" || filter == null)
            {
                GitGud.RunCommand("log --pretty=\"" + format + "\"", onLogComplete);
            }
            else
            {
                GitGud.RunCommand("log --pretty=\"" + format + "\" " + filter, onLogComplete);
            }
        }
Exemplo n.º 9
0
 //Unstage a single path
 public static void UnstagePath(string path, Action <CommandOutput> onComplete)
 {
     GitGud.RunCommand("reset -- \"" + path + "\"", onComplete);
 }
Exemplo n.º 10
0
 public static void DiscardAll(Action <CommandOutput> onComplete)
 {
     GitGud.RunCommand("checkout .", onComplete);
 }
Exemplo n.º 11
0
        //Unstage a list of paths
        public static void UnstagePaths(List <string> paths, Action <CommandOutput> onComplete)
        {
            string combinedPaths = GitUtility.QuoteAndCombinePaths(paths.ToArray());

            GitGud.RunCommand("reset -- " + combinedPaths, onComplete);
        }
Exemplo n.º 12
0
 //Simple fetch command
 public static void Fetch(Action <CommandOutput> onComplete)
 {
     GitGud.RunCommand("fetch", onComplete);
 }
Exemplo n.º 13
0
        public static void DiscardFiles(List <string> paths, Action <CommandOutput> onComplete)
        {
            string combinedPaths = GitUtility.QuoteAndCombinePaths(paths.ToArray());

            GitGud.RunCommand("checkout " + combinedPaths, onComplete);
        }
Exemplo n.º 14
0
        //Log with a internal format, which returns a list of commit objects
        public static void Log(string filter, Action <CommandOutput, Dictionary <string, Commit> > onComplete)
        {
            string currentHash = null;

            //Run to scan all commits
            Action <CommandOutput> onLogAllComplete = (output) =>
            {
                //Error catching
                if (output.errorData != null)
                {
                    onComplete(output, null);
                    return;
                }

                Dictionary <string, Commit> commits = new Dictionary <string, Commit>();

                if (output.outputData == null)
                {
                    onComplete(output, commits);
                    return;
                }

                //Convert log string into commit format
                string[] commitStrings = output.outputData.Split('\n');

                foreach (string commitStr in commitStrings)
                {
                    string[] components = commitStr.Split(',');
                    Commit   commit     = new Commit();
                    commit.hash         = components[0];
                    commit.tree         = components[1];
                    commit.parent       = components[2];
                    commit.author_name  = components[3];
                    commit.author_email = components[4];
                    commit.date         = components[5];
                    commit.subject      = components[6];
                    commit.isCurrent    = currentHash == commit.hash;
                    commits.Add(commit.hash, commit);
                }

                onComplete(output, commits);
            };

            Action <CommandOutput> onLogCurrentComplete = (output) =>
            {
                //Error catching
                if (output.errorData != null)
                {
                    onComplete(output, null);
                    return;
                }

                currentHash = output.outputData;

                string format = "%H,%T,%P,%an,%ae,%ad,%s";

                if (filter == "" || filter == null)
                {
                    GitGud.RunCommand("log --pretty=\"" + format + "\"", onLogAllComplete);
                }
                else
                {
                    GitGud.RunCommand("log --pretty=\"" + format + "\" " + filter, onLogAllComplete);
                }
            };

            //Get current hash
            GitGud.RunCommand("log -1 --pretty=\"%H\"", onLogCurrentComplete);
        }
Exemplo n.º 15
0
 public static void AddFile(string filename, Action <CommandOutput> onComplete)
 {
     GitGud.RunCommand("add " + filename, onComplete);
 }
Exemplo n.º 16
0
 public static void CheckoutCommit(Commit commit, Action <CommandOutput> onComplete)
 {
     GitGud.RunCommand("checkout " + commit.hash + " .", onComplete);
 }
Exemplo n.º 17
0
 public static void DiscardFile(string path, Action <CommandOutput> onComplete)
 {
     GitGud.RunCommand("checkout -- " + path, onComplete);
 }
Exemplo n.º 18
0
 //Simple pull command
 public static void Pull(Action <CommandOutput> onComplete)
 {
     GitGud.RunCommand("pull", onComplete);
 }
Exemplo n.º 19
0
 public static void CreateBranch(string branchname, Action <CommandOutput> onComplete)
 {
     GitGud.RunCommand("checkout -b " + branchname, onComplete);
 }