diff options
author | Jameson Miller <jamill@microsoft.com> | 2014-04-22 17:25:49 +0400 |
---|---|---|
committer | Jameson Miller <jamill@microsoft.com> | 2014-05-03 07:03:28 +0400 |
commit | 90155789aedd51bc8f2ccb122f48977bc0fccc66 (patch) | |
tree | 4ee1020c8e6b75552193894fbaa547d54275efad /LibGit2Sharp/MergeOptions.cs | |
parent | 81cb7603bd106ab6d9eefda97dbebe56039d35bb (diff) |
Update Checkout and Merge options
Checkout methods now use CheckoutOptions
Merge now takes several options:
- Option to specify what is checked out for file conflicts.
- Report CheckoutProgress and CheckoutNotify
- Option to specify MergeFileFavor
Updates for code review feedback
Diffstat (limited to 'LibGit2Sharp/MergeOptions.cs')
-rw-r--r-- | LibGit2Sharp/MergeOptions.cs | 120 |
1 files changed, 116 insertions, 4 deletions
diff --git a/LibGit2Sharp/MergeOptions.cs b/LibGit2Sharp/MergeOptions.cs index 06eb13ce..be25665e 100644 --- a/LibGit2Sharp/MergeOptions.cs +++ b/LibGit2Sharp/MergeOptions.cs @@ -1,22 +1,40 @@ - +using LibGit2Sharp.Core; +using LibGit2Sharp.Handlers; + namespace LibGit2Sharp { /// <summary> /// Options controlling Merge behavior. /// </summary> - public sealed class MergeOptions + public sealed class MergeOptions : IConvertableToGitCheckoutOpts { /// <summary> /// Initializes a new instance of the <see cref="MergeOptions"/> class. - /// By default, a fast-forward merge will be performed if possible, and - /// if a merge commit is created, then it will be commited. + /// <para> + /// Default behavior: + /// A fast-forward merge will be performed if possible. + /// A merge commit will be committed, if one was created. + /// Merge will attempt to find renames. + /// </para> /// </summary> public MergeOptions() { CommitOnSuccess = true; + + FindRenames = true; + // TODO: libgit2 should provide reasonable defaults for these + // values, but it currently does not. + RenameThreshold = 50; + TargetLimit = 200; } /// <summary> + /// The Flags specifying what conditions are + /// reported through the OnCheckoutNotify delegate. + /// </summary> + public CheckoutNotifyFlags CheckoutNotifyFlags { get; set; } + + /// <summary> /// Commit the merge if the merge is successful and this is a non-fast-forward merge. /// If this is a fast-forward merge, then there is no merge commit and this option /// will not affect the merge. @@ -27,6 +45,63 @@ namespace LibGit2Sharp /// The type of merge to perform. /// </summary> public FastForwardStrategy FastForwardStrategy { get; set; } + + /// <summary> + /// How conflicting index entries should be written out during checkout. + /// </summary> + public CheckoutFileConflictStrategy FileConflictStrategy { get; set; } + + /// <summary> + /// Find renames. Default is true. + /// </summary> + public bool FindRenames { get; set; } + + /// <summary> + /// Similarity to consider a file renamed. + /// </summary> + public int RenameThreshold; + + /// <summary> + /// Maximum similarity sources to examine (overrides + /// 'merge.renameLimit' config (default 200) + /// </summary> + public int TargetLimit; + + /// <summary> + /// How to handle conflicts encountered during a merge. + /// </summary> + public MergeFileFavor MergeFileFavor { get; set; } + + /// <summary> + /// Delegate that the checkout will report progress through. + /// </summary> + public CheckoutProgressHandler OnCheckoutProgress { get; set; } + + /// <summary> + /// Delegate that checkout will notify callers of + /// certain conditions. The conditions that are reported is + /// controlled with the CheckoutNotifyFlags property. + /// </summary> + public CheckoutNotifyHandler OnCheckoutNotify { get; set; } + + #region IConvertableToGitCheckoutOpts + + CheckoutCallbacks IConvertableToGitCheckoutOpts.GenerateCallbacks() + { + return CheckoutCallbacks.From(OnCheckoutProgress, OnCheckoutNotify); + } + + CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy + { + get + { + return CheckoutStrategy.GIT_CHECKOUT_SAFE| + CheckoutStrategy.GIT_CHECKOUT_ALLOW_CONFLICTS | + GitCheckoutOptsWrapper.CheckoutStrategyFromFileConflictStrategy(FileConflictStrategy); + } + } + + #endregion } /// <summary> @@ -51,4 +126,41 @@ namespace LibGit2Sharp /// </summary> FastForwardOnly = 2, /* GIT_MERGE_FASTFORWARD_ONLY */ } + + /// <summary> + /// Enum specifying how merge should deal with conflicting regions + /// of the files. + /// </summary> + public enum MergeFileFavor + { + /// <summary> + /// When a region of a file is changed in both branches, a conflict + /// will be recorded in the index so that the checkout operation can produce + /// a merge file with conflict markers in the working directory. + /// This is the default. + /// </summary> + Normal = 0, + + /// <summary> + /// When a region of a file is changed in both branches, the file + /// created in the index will contain the "ours" side of any conflicting + /// region. The index will not record a conflict. + /// </summary> + Ours = 1, + + /// <summary> + /// When a region of a file is changed in both branches, the file + /// created in the index will contain the "theirs" side of any conflicting + /// region. The index will not record a conflict. + /// </summary> + Theirs = 2, + + /// <summary> + /// When a region of a file is changed in both branches, the file + /// created in the index will contain each unique line from each side, + /// which has the result of combining both files. The index will not + /// record a conflict. + /// </summary> + Union = 3, + } } |