Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
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));
 }
Ejemplo n.º 5
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));
 }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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);
        }