using LibGit2Sharp.Core; using LibGit2Sharp.Handlers; namespace LibGit2Sharp { /// /// Options controlling Merge behavior. /// public sealed class MergeOptions : IConvertableToGitCheckoutOpts { /// /// Initializes a new instance of the class. /// /// Default behavior: /// A fast-forward merge will be performed if possible, unless the merge.ff configuration option is set. /// A merge commit will be committed, if one was created. /// Merge will attempt to find renames. /// /// public MergeOptions() { CommitOnSuccess = true; FindRenames = true; // TODO: libgit2 should provide reasonable defaults for these // values, but it currently does not. RenameThreshold = 50; TargetLimit = 200; } /// /// The Flags specifying what conditions are /// reported through the OnCheckoutNotify delegate. /// public CheckoutNotifyFlags CheckoutNotifyFlags { get; set; } /// /// 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. /// public bool CommitOnSuccess { get; set; } /// /// The type of merge to perform. /// public FastForwardStrategy FastForwardStrategy { get; set; } /// /// How conflicting index entries should be written out during checkout. /// public CheckoutFileConflictStrategy FileConflictStrategy { get; set; } /// /// Find renames. Default is true. /// public bool FindRenames { get; set; } /// /// Similarity to consider a file renamed. /// public int RenameThreshold; /// /// Maximum similarity sources to examine (overrides /// 'merge.renameLimit' config (default 200) /// public int TargetLimit; /// /// How to handle conflicts encountered during a merge. /// public MergeFileFavor MergeFileFavor { get; set; } /// /// Delegate that the checkout will report progress through. /// public CheckoutProgressHandler OnCheckoutProgress { get; set; } /// /// Delegate that checkout will notify callers of /// certain conditions. The conditions that are reported is /// controlled with the CheckoutNotifyFlags property. /// public CheckoutNotifyHandler OnCheckoutNotify { get; set; } #region IConvertableToGitCheckoutOpts CheckoutCallbacks IConvertableToGitCheckoutOpts.GenerateCallbacks() { return CheckoutCallbacks.From(OnCheckoutProgress, OnCheckoutNotify); } CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy { get { return CheckoutStrategy.GIT_CHECKOUT_SAFE | GitCheckoutOptsWrapper.CheckoutStrategyFromFileConflictStrategy(FileConflictStrategy); } } #endregion } /// /// Strategy used for merging. /// public enum FastForwardStrategy { /// /// Default fast-forward strategy. If the merge.ff configuration option is set, /// it will be used. If it is not set, this will perform a fast-forward merge if /// possible, otherwise a non-fast-forward merge that results in a merge commit. /// Default = 0, /// /// Do not fast-forward. Always creates a merge commit. /// NoFastFoward = 1, /* GIT_MERGE_NO_FASTFORWARD */ /// /// Only perform fast-forward merges. /// FastForwardOnly = 2, /* GIT_MERGE_FASTFORWARD_ONLY */ } /// /// Enum specifying how merge should deal with conflicting regions /// of the files. /// public enum MergeFileFavor { /// /// 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. /// Normal = 0, /// /// 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. /// Ours = 1, /// /// 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. /// Theirs = 2, /// /// 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. /// Union = 3, } }