public static Branch SwitchToTargetBranch(this IGitRepository repository, CherryPickConfig config) { GetLocalAndRemoteBranch(repository, config.TargetBranch, config.TargetBranchRemote, out var targetBranch, out var targetBranchRemote); if (targetBranch == null && targetBranchRemote != null) { targetBranch = repository.CreateBranch(config.TargetBranch, targetBranchRemote.Tip); } if (targetBranch is null) { throw new InvalidOperationException(string.Format("Branch {0} not found", config.TargetBranch)); } // Checkout target branch repository.Checkout(targetBranch); if (config.SyncTargetBranch && targetBranchRemote != null) { try { // And try pull with fast forward from remote repository.Merge( targetBranchRemote, repository.Config.BuildSignature(DateTimeOffset.Now), new MergeOptions { FastForwardStrategy = FastForwardStrategy.FastForwardOnly }); } catch (NonFastForwardException) { } } return(targetBranch); }
MergeResult Merge(Branch targetBranch, bool fastForward) => repository.Merge( targetBranch, repository.Config.BuildSignature(DateTimeOffset.Now), new MergeOptions() { CommitOnSuccess = true, FastForwardStrategy = fastForward ? FastForwardStrategy.FastForwardOnly : FastForwardStrategy.NoFastForward });