/// <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> /// <param name="compareOptions">Additional options to define patch generation behavior.</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, CompareOptions compareOptions) where T : class, IDiffResult { var comparer = HandleRetrieverDispatcher[diffTargets](repo); ObjectId oldTreeId = oldTree != null ? oldTree.Id : null; DiffModifiers diffOptions = diffTargets.HasFlag(DiffTargets.WorkingDirectory) ? DiffModifiers.IncludeUntracked : DiffModifiers.None; if (explicitPathsOptions != null) { diffOptions |= DiffModifiers.DisablePathspecMatch; if (explicitPathsOptions.ShouldFailOnUnmatchedPath || explicitPathsOptions.OnUnmatchedPath != null) { diffOptions |= DiffModifiers.IncludeUnmodified; } } using (DiffSafeHandle diff = BuildDiffList(oldTreeId, null, comparer, diffOptions, paths, explicitPathsOptions, compareOptions)) { return(BuildDiffResult <T>(diff)); } }
private bool UntrackedFileChanges(int index) { if (repo == null) { throw new InvalidOperationException("Repository not initialized"); } Stash stash = repo.Stashes.ElementAt(index); if (stash.Untracked == null) { return(false); } IList <string> p = stash.Untracked.Tree.Select(t => t.Path).ToList(); if (p.Count() == 0) { return(false); } DiffTargets dt = DiffTargets.WorkingDirectory; var r = repo.Diff.Compare <TreeChanges>(stash.Untracked.Tree, dt, p); if (r.Modified.Count() > 0) { return(true); } return(false); }
/// <summary> /// Constructs a diff item. /// </summary> /// <param name="diffType">The type of the diff.</param> /// <param name="path">The path of the difference.</param> /// <param name="targets">Indicates which XML fragment is targeted by the diff.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is null.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is empty.</exception> public Diff(DiffType diffType, IXmlPathStrict path, DiffTargets targets) { if (diffType == null) throw new ArgumentNullException("diffType"); if (path == null) throw new ArgumentNullException("path"); this.diffType = diffType; this.path = path; this.targets = targets; }
/// <summary> /// Show changes between a <see cref = "Tree"/> and the Index, the Working Directory, or both. /// </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> /// <returns>A <see cref = "TreeChanges"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns> public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnumerable <string> paths = null) { var comparer = handleRetrieverDispatcher[diffTargets](repo); DiffOptions diffOptions = diffTargets.HasFlag(DiffTargets.WorkingDirectory) ? DiffOptions.IncludeUntracked : DiffOptions.None; using (GitDiffOptions options = BuildOptions(diffOptions, paths)) using (DiffListSafeHandle dl = BuildDiffListFromTreeAndComparer( oldTree != null ? oldTree.Id : null, comparer, options)) { return(new TreeChanges(dl)); } }
/// <summary> /// Constructs a diff item. /// </summary> /// <param name="diffType">The type of the diff.</param> /// <param name="path">The path of the difference.</param> /// <param name="targets">Indicates which XML fragment is targeted by the diff.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is null.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is empty.</exception> public Diff(DiffType diffType, IXmlPathStrict path, DiffTargets targets) { if (diffType == null) { throw new ArgumentNullException("diffType"); } if (path == null) { throw new ArgumentNullException("path"); } this.diffType = diffType; this.path = path; this.targets = targets; }
private void LogFilesInStash(Stash stash) { if (stash == null) { throw new ArgumentException("stash parameter can not be null"); } if (repo == null) { throw new InvalidOperationException("Repository not initialized"); } Tree commitTree = stash.WorkTree.Tree; IList <string> paths = commitTree.Select(t => t.Path).ToList(); DiffTargets dt = DiffTargets.WorkingDirectory; var patch = repo.Diff.Compare <TreeChanges>(commitTree, dt, paths); foreach (var ptc in patch) { Logger.WriteLine(ptc.Status + " -> " + ptc.Path); // Status -> File Path } }
/// <summary> /// Show changes between a <see cref = "Tree"/> and the Index, the Working Directory, or both. /// </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> /// <param name = "compareOptions">Additional options to define comparison behavior.</param> /// <returns>A <see cref = "TreeChanges"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns> public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnumerable <string> paths = null, ExplicitPathsOptions explicitPathsOptions = null, CompareOptions compareOptions = null) { var comparer = handleRetrieverDispatcher[diffTargets](repo); ObjectId oldTreeId = oldTree != null ? oldTree.Id : null; DiffOptions diffOptions = diffTargets.HasFlag(DiffTargets.WorkingDirectory) ? DiffOptions.IncludeUntracked : DiffOptions.None; if (explicitPathsOptions != null) { diffOptions |= DiffOptions.DisablePathspecMatch; if (explicitPathsOptions.ShouldFailOnUnmatchedPath || explicitPathsOptions.OnUnmatchedPath != null) { diffOptions |= DiffOptions.IncludeUnmodified; } } return(BuildTreeChangesFromComparer(oldTreeId, null, comparer, diffOptions, paths, explicitPathsOptions, compareOptions)); }
/// <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> /// <param name="compareOptions">Additional options to define patch generation behavior.</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 = null, ExplicitPathsOptions explicitPathsOptions = null, CompareOptions compareOptions = null) where T : class { Func <DiffSafeHandle, object> builder; if (!ChangesBuilders.TryGetValue(typeof(T), out builder)) { throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unexpected type '{0}' passed to Compare. Supported values are either '{1}' or '{2}'.", typeof(T), typeof(TreeChanges), typeof(Patch))); } var comparer = HandleRetrieverDispatcher[diffTargets](repo); ObjectId oldTreeId = oldTree != null ? oldTree.Id : null; DiffModifiers diffOptions = diffTargets.HasFlag(DiffTargets.WorkingDirectory) ? DiffModifiers.IncludeUntracked : DiffModifiers.None; if (explicitPathsOptions != null) { diffOptions |= DiffModifiers.DisablePathspecMatch; if (explicitPathsOptions.ShouldFailOnUnmatchedPath || explicitPathsOptions.OnUnmatchedPath != null) { diffOptions |= DiffModifiers.IncludeUnmodified; } } using (DiffSafeHandle diff = BuildDiffList(oldTreeId, null, comparer, diffOptions, paths, explicitPathsOptions, compareOptions)) { return((T)builder(diff)); } }
public IList <string> GetUntrackedChangesList(int stashIndex) { lock (lockObject) { if (repo == null) { throw new InvalidOperationException("Repository not initialized"); } Stash stash = repo.Stashes.ElementAt(stashIndex); IList <string> paths = new List <string>(); IList <string> p = stash.Untracked.Tree.Select(t => t.Path).ToList(); if (p.Count() == 0) { return(paths); } DiffTargets dt = DiffTargets.WorkingDirectory; var r = repo.Diff.Compare <TreeChanges>(stash.Untracked.Tree, dt, p); if (!r.Any()) { return(paths); } return(r.Modified.Select(c => c.Path).ToList()); } }
/// <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)); }
/// <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)); }
/// <summary> /// Show changes between a <see cref="Tree"/> and the Index, the Working Directory, or both. /// </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> /// <param name="compareOptions">Additional options to define comparison behavior.</param> /// <returns>A <see cref="TreeChanges"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns> public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnumerable<string> paths = null, ExplicitPathsOptions explicitPathsOptions = null, CompareOptions compareOptions = null) { var comparer = handleRetrieverDispatcher[diffTargets](repo); ObjectId oldTreeId = oldTree != null ? oldTree.Id : null; DiffModifiers diffOptions = diffTargets.HasFlag(DiffTargets.WorkingDirectory) ? DiffModifiers.IncludeUntracked : DiffModifiers.None; if (explicitPathsOptions != null) { diffOptions |= DiffModifiers.DisablePathspecMatch; if (explicitPathsOptions.ShouldFailOnUnmatchedPath || explicitPathsOptions.OnUnmatchedPath != null) { diffOptions |= DiffModifiers.IncludeUnmodified; } } return BuildTreeChangesFromComparer(oldTreeId, null, comparer, diffOptions, paths, explicitPathsOptions, compareOptions); }
/// <summary> /// Show changes between a <see cref = "Tree"/> and the Index, the Working Directory, or both. /// </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> /// <returns>A <see cref = "TreeChanges"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns> public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnumerable<string> paths = null) { var comparer = handleRetrieverDispatcher[diffTargets](repo); DiffOptions diffOptions = diffTargets.HasFlag(DiffTargets.WorkingDirectory) ? DiffOptions.IncludeUntracked : DiffOptions.None; using (GitDiffOptions options = BuildOptions(diffOptions, paths)) using (DiffListSafeHandle dl = BuildDiffListFromTreeAndComparer( oldTree != null ? oldTree.Id : null, comparer, options)) { return new TreeChanges(dl); } }