예제 #1
0
 /// <summary>
 /// Get the list of changes between two commits.
 /// </summary>
 /// <param name="firstTree">The first commit.</param>
 /// <param name="secondTree">The second commit.</param>
 /// <returns>The changes.</returns>
 public static TreeChanges GetChanges(LibGit2Sharp.Tree firstTree, LibGit2Sharp.Tree secondTree)
 {
     using (var repo = new Repository(repoPath))
     {
         return(repo.Diff.Compare <TreeChanges>(firstTree, secondTree));
     }
 }
        public GitCommitDetailsWindow(Commit commit)
        {
            this.commit = commit;
            commitTree  = commit.Tree;
            Commit parentCommit = commit.Parents.FirstOrDefault();

            if (parentCommit != null)
            {
                changes = GitManager.Repository.Diff.Compare <TreeChanges>(parentCommit.Tree, commitTree);
            }

            commitMessageStyle = new GUIStyle("TL SelectionButton")
            {
                alignment = TextAnchor.UpperLeft, padding = new RectOffset(4, 4, 4, 4), wordWrap = true
            };
        }
 private void DrawTreeEntry(Tree tree, int depth)
 {
     foreach (var file in tree)
     {
         if (file.TargetType == TreeEntryTargetType.Tree)
         {
             EditorGUI.indentLevel = depth;
             EditorGUILayout.LabelField(Path.GetFileName(file.Path));
             DrawTreeEntry(file.Target as Tree, depth + 1);
         }
         else if (!file.Path.EndsWith(".meta"))
         {
             EditorGUI.indentLevel = depth;
             EditorGUILayout.LabelField(file.Path);
         }
     }
 }
예제 #4
0
        public GitCommitDetailsWindow(GitManager gitManager, GitExternalManager externalManager, Commit commit, GitOverlay gitOverlay)
        {
            this.gitManager      = gitManager;
            this.commit          = commit;
            this.externalManager = externalManager;
            this.gitOverlay      = gitOverlay;
            commitTree           = commit.Tree;
            Commit parentCommit = commit.Parents.FirstOrDefault();

            if (parentCommit != null)
            {
                changes = gitManager.Repository.Diff.Compare <TreeChanges>(parentCommit.Tree, commitTree);
            }

            commitMessageStyle = new GUIStyle("TL SelectionButton")
            {
                alignment = TextAnchor.UpperLeft, padding = new RectOffset(4, 4, 4, 4), wordWrap = true, normal = { textColor = Color.black }
            };
        }
예제 #5
0
        /// <summary>
        /// Use LibGit2Sharp to perform a Git diff procedure on the given file, comparing the current working directory
        /// against the file version at the given commit index.  Returns the total number of lines changed.
        /// </summary>
        public int DiffFile(CustomFile file, int commitIndex)
        {
            //Ensure any previous changes detected by Git are removed before considering other changes
            if (file != null)
            {
                file.ClearPreviousChanges();
            }
            // Return if the given file was null or if user selected "NO SELECTION" index from DependencyWindow drop-down
            if (file == null || commitIndex == -1)
            {
                return(0);
            }

            // Select the Git tree and file path for the given CustomFile
            LibGit2Sharp.Tree chosenTree     = commitList[commitIndex].Tree;
            List <string>     chosenFilePath = new List <string>()
            {
                file.relPath
            };

            // Perform the Git diff and create a string for the resulting patch
            Patch             patch     = repo.Diff.Compare <Patch>(chosenTree, DiffTargets.WorkingDirectory, chosenFilePath, pathOptions, compareOptions);
            PatchEntryChanges changes   = patch[file.relPath];
            string            patchText = changes.Patch; // If no changes b/w commits, then "", or if notIncludeModified, null changes

            // Update the CustomFile with this patchText for future direct access
            file.diffPatchText = patchText;

            // Parse the patch to localize additions and deletions to the appropriate CustomTypes and CustomMethods
            int totalFileChanges = ParseDiffPatch(patchText, file);

            //Debugging output for checking where changes were found in file
            //List<CustomType> typesInFile = file.types;
            //foreach (CustomType t in typesInFile) {
            //    Debug.LogError("Total changes in " + t + ": " + t + ", inMethods: " + t.totalChangesInMethods + ", outMethods: " + t.totalChangesOutsideMethods);
            //    foreach (CustomMethod m in t.methods) {
            //        Debug.LogWarning("   Total changes in " + m + ": " + (m.additions + m.deletions) + "(Adds: " + m.additions + ", Dels: " + m.deletions + ")");
            //    }
            //}

            return(totalFileChanges);
        }
예제 #6
0
파일: Diff.cs 프로젝트: kidaak/libgit2sharp
 /// <summary>
 /// Show changes between a <see cref="Tree"/> and the Index, the Working Directory, or both.
 /// <para>
 /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/>
 /// or <see cref="Patch"/> type as the generic parameter.
 /// </para>
 /// </summary>
 /// <param name="oldTree">The <see cref="Tree"/> to compare from.</param>
 /// <param name="diffTargets">The targets to compare to.</param>
 /// <param name="paths">The list of paths (either files or directories) that should be compared.</param>
 /// <param name="explicitPathsOptions">
 /// If set, the passed <paramref name="paths"/> will be treated as explicit paths.
 /// Use these options to determine how unmatched explicit paths should be handled.
 /// </param>
 /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or
 /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam>
 /// <returns>A <typeparamref name="T"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns>
 public virtual T Compare <T>(Tree oldTree, DiffTargets diffTargets, IEnumerable <string> paths,
                              ExplicitPathsOptions explicitPathsOptions) where T : class, IDiffResult
 {
     return(Compare <T>(oldTree, diffTargets, paths, explicitPathsOptions, null));
 }
예제 #7
0
파일: Diff.cs 프로젝트: kidaak/libgit2sharp
 /// <summary>
 /// Show changes between a <see cref="Tree"/> and the Index, the Working Directory, or both.
 /// <para>
 /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/>
 /// or <see cref="Patch"/> type as the generic parameter.
 /// </para>
 /// </summary>
 /// <param name="oldTree">The <see cref="Tree"/> to compare from.</param>
 /// <param name="diffTargets">The targets to compare to.</param>
 /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or
 /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam>
 /// <returns>A <typeparamref name="T"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns>
 public virtual T Compare <T>(Tree oldTree, DiffTargets diffTargets) where T : class, IDiffResult
 {
     return(Compare <T>(oldTree, diffTargets, null, null, null));
 }
예제 #8
0
파일: Diff.cs 프로젝트: kidaak/libgit2sharp
 /// <summary>
 /// Show changes between two <see cref="Tree"/>s.
 /// </summary>
 /// <param name="oldTree">The <see cref="Tree"/> you want to compare from.</param>
 /// <param name="newTree">The <see cref="Tree"/> you want to compare to.</param>
 /// <param name="compareOptions">Additional options to define patch generation behavior.</param>
 /// <returns>A <see cref="TreeChanges"/> containing the changes between the <paramref name="oldTree"/> and the <paramref name="newTree"/>.</returns>
 public virtual T Compare <T>(Tree oldTree, Tree newTree, CompareOptions compareOptions) where T : class, IDiffResult
 {
     return(Compare <T>(oldTree, newTree, null, null, compareOptions));
 }
예제 #9
0
파일: Diff.cs 프로젝트: kidaak/libgit2sharp
 /// <summary>
 /// Show changes between two <see cref="Tree"/>s.
 /// </summary>
 /// <param name="oldTree">The <see cref="Tree"/> you want to compare from.</param>
 /// <param name="newTree">The <see cref="Tree"/> you want to compare to.</param>
 /// <param name="paths">The list of paths (either files or directories) that should be compared.</param>
 /// <param name="compareOptions">Additional options to define patch generation behavior.</param>
 /// <returns>A <see cref="TreeChanges"/> containing the changes between the <paramref name="oldTree"/> and the <paramref name="newTree"/>.</returns>
 public virtual T Compare <T>(Tree oldTree, Tree newTree, IEnumerable <string> paths, CompareOptions compareOptions) where T : class, IDiffResult
 {
     return(Compare <T>(oldTree, newTree, paths, null, compareOptions));
 }
예제 #10
0
        /// <summary>
        /// Internal implementation of Checkout that expects the ID of the checkout target
        /// to already be in the form of a canonical branch name or a commit ID.
        /// </summary>
        /// <param name="repository">The repository to act on</param>
        /// <param name="tree">The <see cref="Tree"/> to checkout.</param>
        /// <param name="checkoutOptions"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <param name="refLogHeadSpec">The spec which will be written as target in the reflog.</param>
        public static void Checkout(IRepository repository, Tree tree, CheckoutOptions checkoutOptions, string refLogHeadSpec)
        {
            repository.Checkout(tree, null, checkoutOptions);

            repository.Refs.MoveHeadTarget(refLogHeadSpec);
        }
예제 #11
0
        /// <summary>
        /// Inserts a <see cref="Commit"/> into the object database, referencing an existing <see cref="Tree"/>.
        /// <para>
        /// Prettifing the message includes:
        /// * Removing empty lines from the beginning and end.
        /// * Removing trailing spaces from every line.
        /// * Turning multiple consecutive empty lines between paragraphs into just one empty line.
        /// * Ensuring the commit message ends with a newline.
        /// * Removing every line starting with "#".
        /// </para>
        /// </summary>
        /// <param name="author">The <see cref="Signature"/> of who made the change.</param>
        /// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
        /// <param name="message">The description of why a change was made to the repository.</param>
        /// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param>
        /// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param>
        /// <param name="prettifyMessage">True to prettify the message, or false to leave it as is.</param>
        /// <param name="commentChar">Character that lines start with to be stripped if prettifyMessage is true.</param>
        /// <returns>The created <see cref="Commit"/>.</returns>
        public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable <Commit> parents, bool prettifyMessage, char?commentChar = null)
        {
            Ensure.ArgumentNotNull(message, "message");
            Ensure.ArgumentDoesNotContainZeroByte(message, "message");
            Ensure.ArgumentNotNull(author, "author");
            Ensure.ArgumentNotNull(committer, "committer");
            Ensure.ArgumentNotNull(tree, "tree");
            Ensure.ArgumentNotNull(parents, "parents");

            if (prettifyMessage)
            {
                message = Proxy.git_message_prettify(message, commentChar);
            }
            GitOid[] parentIds = parents.Select(p => p.Id.Oid).ToArray();

            ObjectId commitId = Proxy.git_commit_create(repo.Handle, null, author, committer, message, tree, parentIds);

            return(repo.Lookup <Commit>(commitId));
        }