Exemple #1
0
        async private Task run_async(string arguments, Action <string> onProgressChange)
        {
            Progress <string> progress = onProgressChange != null ? new Progress <string>() : null;

            if (onProgressChange != null)
            {
                progress.ProgressChanged += (sender, status) =>
                {
                    onProgressChange(status);
                };
            }

            Trace.TraceInformation(String.Format("[GitClient] async operation -- begin -- {0}: {1}",
                                                 _projectName, arguments));
            _descriptor = GitUtils.gitAsync(arguments, progress);
            try
            {
                await _descriptor.TaskCompletionSource.Task;
                Trace.TraceInformation(String.Format("[GitClient] async operation -- end --  {0}: {1}",
                                                     _projectName, arguments));
            }
            catch (GitOperationException ex)
            {
                int    cancellationExitCode = 130;
                string status = ex.ExitCode == cancellationExitCode ? "cancel" : "error";
                Trace.TraceInformation(String.Format("[GitClient] async operation -- {2} --  {0}: {1}",
                                                     _projectName, arguments, status));
                ex.Cancelled = ex.ExitCode == cancellationExitCode;
                throw;
            }
            finally
            {
                _descriptor = null;
            }
        }
Exemple #2
0
        // 'null' filename strings will be replaced with empty strings
        public List <string> Diff(string leftcommit, string rightcommit, string filename1, string filename2, int context)
        {
            DiffCacheKey key = new DiffCacheKey
            {
                sha1      = leftcommit,
                sha2      = rightcommit,
                filename1 = filename1,
                filename2 = filename2,
                context   = context
            };

            if (_cachedDiffs.ContainsKey(key))
            {
                return(_cachedDiffs[key]);
            }

            List <string> result = (List <string>)run_in_path(() =>
            {
                string arguments =
                    "diff -U" + context.ToString() + " " + leftcommit + " " + rightcommit
                    + " -- " + (filename1 ?? "") + " " + (filename2 ?? "");
                return(GitUtils.git(arguments).Output);
            }, Path);

            _cachedDiffs[key] = result;
            return(result);
        }
        /// <summary>
        /// Removes a section for the difftool with the passed name from the global git configuration.
        /// Throws GitOperationException in case of problems with git.
        /// </summary>
        public void RemoveGlobalDiffTool(string name)
        {
            // No need to change current directory because we're changing a global setting
            string arguments = "config --global --remove-section difftool." + name;

            GitUtils.git(arguments);
        }
        /// <summary>
        /// Adds a difftool with the given name and command to the global git configuration.
        /// Throws GitOperationException in case of problems with git.
        /// </summary>
        public void SetGlobalDiffTool(string name, string command)
        {
            // No need to change current directory because we're changing a global setting
            string arguments = "config --global difftool." + name + ".cmd " + command;

            GitUtils.git(arguments);
        }
Exemple #5
0
 /// <summary>
 /// Launches 'git difftool --dir-diff' command
 /// </summary>
 public int DiffTool(string name, string leftCommit, string rightCommit)
 {
     return((int)run_in_path(() =>
     {
         string arguments = "difftool --dir-diff --tool=" + name + " " + leftCommit + " " + rightCommit;
         return GitUtils.git(arguments, false).PID;
     }, Path));
 }
Exemple #6
0
 public List <string> GetListOfRenames(string leftcommit, string rightcommit)
 {
     return((List <string>)run_in_path(() =>
     {
         string arguments = "diff " + leftcommit + " " + rightcommit + " --numstat --diff-filter=R";
         return GitUtils.git(arguments).Output;
     }, Path));
 }
Exemple #7
0
        static private bool isValidRepository(string path)
        {
            if (!Directory.Exists(path))
            {
                return(false);
            }

            return((bool)run_in_path(() =>
            {
                try
                {
                    var arguments = "rev-parse --is-inside-work-tree";
                    GitUtils.GitOutput output = GitUtils.git(arguments);
                    return output.Errors.Count == 0;
                }
                catch (GitOperationException)
                {
                    return false;
                }
            }, path));
        }
Exemple #8
0
        /// <summary>
        /// Cancel currently running git async operation
        /// InvalidOperationException if no async operation is running
        /// </summary>
        public void CancelAsyncOperation()
        {
            if (_descriptor == null)
            {
                return;
            }

            Process p = _descriptor.Process;

            _descriptor.Cancelled = true;
            try
            {
                GitUtils.cancelGit(_descriptor.Process);
            }
            catch (InvalidOperationException)
            {
                // already exited
            }

            p.Dispose();
        }
Exemple #9
0
        public List <string> ShowFileByRevision(string filename, string sha)
        {
            RevisionCacheKey key = new RevisionCacheKey
            {
                filename = filename,
                sha      = sha
            };

            if (_cachedRevisions.ContainsKey(key))
            {
                return(_cachedRevisions[key]);
            }

            List <string> result = (List <string>)run_in_path(() =>
            {
                string arguments = "show " + sha + ":" + filename;
                return(GitUtils.git(arguments).Output);
            }, Path);

            _cachedRevisions[key] = result;
            return(result);
        }