public Task <RebaseInfo> RebaseBranch(string source, string target, Author author, string message) { var signature = getSignature(author); var targetBranch = _repo.Branches[target]; var sourceBranch = _repo.Branches[source]; if (isTransactionInProgress(source)) { var exceptionMessage = $"There is a transaction in progress for branch {source}. Complete the transaction first."; _logger.Warn(exceptionMessage); throw new ArgumentException(exceptionMessage); } lock (getLock(source)) { var mergeRes = _repo.ObjectDatabase.MergeCommits(sourceBranch.Tip, targetBranch.Tip, new MergeTreeOptions()); if (mergeRes.Status != MergeTreeStatus.Succeeded) { var logMessage = $"Could not rebase {source} onto {target} because of conflicts. Please merge manually"; _logger.Trace(logMessage); return(Task.FromResult(new RebaseInfo { Message = logMessage, SourceBranch = source, TargetBranch = target, Status = RebaseResult.Conflicts, Conflicts = mergeRes.Conflicts.Select(c => new ConflictInfo { SourceSha = c.Ours?.Id.Sha, TargetSha = c.Theirs?.Id.Sha, Path = c.Ours?.Path ?? c.Theirs.Path, Type = object.ReferenceEquals(c.Ours, null) || object.ReferenceEquals(c.Theirs, null) ? ConflictType.Remove : ConflictType.Change }).ToList() })); } var previousCommit = targetBranch.Tip; var tree = mergeRes.Tree; if (previousCommit != null && previousCommit.Tree.Id == tree.Id) { return(Task.FromResult(RebaseInfo.Succeeded(source, target, string.Empty))); } var ancestors = previousCommit != null ? new List <Commit> { previousCommit } : new List <Commit>(); var commit = _repo.ObjectDatabase.CreateCommit(signature, signature, message, tree, ancestors, false); _repo.Refs.UpdateTarget(_repo.Refs[sourceBranch.CanonicalName], commit.Id); _logger.Trace($"Squashed and rebased {source} onto {target} with message {message}"); push(source); return(Task.FromResult(RebaseInfo.Succeeded(source, target, commit.Sha))); } }
protected override async Task Because() { await Subject.CreateBranch(new Reference { Name = "test", Pointer = "master" }); await addItem("master"); await addItem("test", changeValuesForKeys : true); _rebaseResult = await Subject.RebaseBranch("test", "master", Author, "This is the rebase commit for branch test"); }
protected override async Task Because() { foreach (var i in Enumerable.Range(0, 5)) { await Subject.Save("master", $"Added {i} (master)", new Document { Key = $"file\\key {i}", Value = i.ToString() }, Author); } _masterCommit = Repo.Branches["master"].Tip.Sha; await Subject.CreateBranch(new Reference { Name = "test", Pointer = "master" }); _rebaseResult = await Subject.RebaseBranch("test", "master", Author, "This is the rebase commit for branch test"); }
protected override async Task Because() { await addItems("master"); await Subject.CreateBranch(new Reference { Name = "test", Pointer = "master" }); await addItems("test"); await addItems("master"); await addItems("test"); await removeItems("master", 1, 2); await removeItems("test", 8, 2); _rebaseResult = await Subject.RebaseBranch("test", "master", Author, "This is the rebase commit for branch test"); }
public void RebaseShouldSuccedWithValidInfo() => _rebaseResult.ShouldBeEquivalentTo(RebaseInfo.Succeeded("test", "master", Repo.Branches["test"].Tip.Sha));
public void RebaseShouldSuccedWithValidInfo() => _rebaseResult.ShouldBeEquivalentTo(RebaseInfo.Succeeded("test", "master", string.Empty));