Exemple #1
0
        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);
        }
Exemple #2
0
        public static Branch?GetBaseBranch(this IRepository repository, CherryPickConfig config)
        {
            repository.GetLocalAndRemoteBranch(config.BaseBranch, config.BaseBranchRemote, out var localBranch, out var remoteBranch);

            return(localBranch ?? remoteBranch);
        }