Ejemplo n.º 1
0
		private static string FormatMergeMessage(MergeOptions options)
		{
			if (options.Branches.Length > 0 && options.Branches[0] is Branch)
				return string.Format("Merge branch '{0}' into {1}", options.Branches[1].Name, options.Branches[0].Name);
			else
				return "Merge commits: " + string.Join(", ", options.Commits.Select(c => c.Hash).ToArray()); // todo: replace this fallback message with something sensible.
		}
Ejemplo n.º 2
0
		public static MergeResult Execute(MergeOptions options)
		{
			options.Validate();

			var merger = SelectMerger(options);
			bool success = merger.Merge(options.Commits.Select(c => ((Core.Commit)c).CommitId).ToArray());
			var result = new MergeResult { Success = success };
			result.Tree = new Tree(options.Repository, merger.GetResultTreeId());
			if (options.NoCommit)
			{

			}
			else
			{
				if (string.IsNullOrEmpty(options.Message))
				{
					options.Message = FormatMergeMessage(options);
				}
				var author = Author.GetDefaultAuthor(options.Repository);
				result.Commit = Commit.Create(options.Message, options.Commits, result.Tree, author, author, DateTimeOffset.Now);
				if (options.Branches.Length >= 1 && options.Branches[0] is Branch)
					Ref.Update("refs/heads/" + options.Branches[0].Name, result.Commit);
			}
			return result;
		}
Ejemplo n.º 3
0
		private static Merger SelectMerger(MergeOptions options)
		{
			switch (options.MergeStrategy)
			{
				case MergeStrategy.Ours:
					return Core.Merge.MergeStrategy.Ours.NewMerger(options.Repository);
				case MergeStrategy.Theirs:
					return Core.Merge.MergeStrategy.Theirs.NewMerger(options.Repository);
				case MergeStrategy.Recursive:
					return Core.Merge.MergeStrategy.SimpleTwoWayInCore.NewMerger(options.Repository);
			}
			throw new ArgumentException("Invalid merge option: "+options.MergeStrategy);
		}
Ejemplo n.º 4
0
 public static MergeResult Merge(MergeOptions options)
 {
     return MergeCommand.Execute(options);
 }