public virtual Commit <TValue, TMeta> MergeWith(RepositoryBranch <TValue, TMeta> sourceBranch) { if (sourceBranch == null) { throw new ArgumentNullException(nameof(sourceBranch)); } if (sourceBranch.Head == null) { throw new ArgumentException("Source branch is empty"); } if (Head == null) { throw new InvalidOperationException("Current branch is empty"); } if (Head.Equals(sourceBranch.Head)) { return(Head); } lock (syncRoot) { var commonAncestor = FindCommonAcestor(Head, sourceBranch.Head); if (commonAncestor == null) { throw new MergeOperationException("Current and source branch have no common acenstor."); } // Current branch is ahead of source branch if (commonAncestor.Equals(sourceBranch.Head)) { return(Head); } // Simple Forward merge if (commonAncestor.Equals(Head)) { Head = sourceBranch.Head; return(Head); } // Do merge otherwise; TValue mergedValue = Repository.MergeHandler.Merge(commonAncestor.Value, Head.Value, sourceBranch.Head.Value, ConflictResolutionOptions.RaiseException); // TODO Find a more suitable solution for TMeta TMeta meta = GreateMergeMetadata(sourceBranch, commonAncestor); var mergeCommit = new Commit <TValue, TMeta>(mergedValue, meta, Head, sourceBranch.Head); Head = mergeCommit; } return(Head); }
public RepositoryBranch <TValue, TMeta> CreateBranch(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Branch name may not be null or empty string."); } if (CurrentBranch.Head == null) { throw new InvalidOperationException("Can't create new Branch from an empty one."); } var branch = new RepositoryBranch <TValue, TMeta>(name, this, CurrentBranch.Head); _branches.Add(branch.Name, branch); return(branch); }
public Repository() { CurrentBranch = new RepositoryBranch <TValue, TMeta>(defaultBranchName, this, null); _branches.Add(CurrentBranch.Name, CurrentBranch); MergeHandler = new DumbMergehandler <TValue>(); }
protected virtual TMeta GreateMergeMetadata(RepositoryBranch <TValue, TMeta> branch, Commit <TValue, TMeta> commonAncestor) { return(default(TMeta)); }