/// <inheritdoc />
        public ObjectId SaveInNewRepository(Signature signature, string message, RepositoryDescription repositoryDescription, bool isBare = false)
        {
            if (signature == null)
            {
                throw new ArgumentNullException(nameof(signature));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (repositoryDescription == null)
            {
                throw new ArgumentNullException(nameof(repositoryDescription));
            }

            LibGit2Sharp.Repository.Init(repositoryDescription.Path, isBare);

            return(_repositoryProvider.Execute(repositoryDescription, repository =>
            {
                var all = this.Flatten().Select(o => new MetadataTreeEntryChanges(o.GetDataPath(), ChangeKind.Added, @new: o));
                var changes = new MetadataTreeChanges(this, all.ToImmutableList());
                var result = repository.CommitChanges(changes, message, signature, signature, hooks: _hooks);

                if (result != null)
                {
                    SetRepositoryData(repositoryDescription, result.Id);
                }

                return result?.Id;
            }));
        }
        /// <summary>
        /// Inserts a <see cref="LibGit2Sharp.Commit" /> into the object database by applying a <see cref="TreeDefinition"/>.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="changes">The changes.</param>
        /// <param name="message">The message.</param>
        /// <param name="author">The author.</param>
        /// <param name="committer">The committer.</param>
        /// <param name="hooks">The hooks.</param>
        /// <param name="options">The options.</param>
        /// <param name="mergeParent">The parent commit for a merge.</param>
        /// <returns>The created <see cref="LibGit2Sharp.Commit" />.</returns>
        internal static Commit CommitChanges(this IRepository repository, MetadataTreeChanges changes, string message, Signature author, Signature committer, GitHooks hooks, CommitOptions options = null, Commit mergeParent = null)
        {
            TreeDefinition definition;

            if (changes.OldRepository?.CommitId != null)
            {
                if (repository.Head.Tip.Id != changes.OldRepository.CommitId)
                {
                    throw new NotSupportedException("Changes are not based on the HEAD commit.");
                }
                var startCommit = repository.Lookup <Commit>(changes.OldRepository.CommitId);
                definition = TreeDefinition.From(startCommit);
            }
            else if (repository.Info.IsHeadUnborn)
            {
                definition = new TreeDefinition();
            }
            else
            {
                throw new NotSupportedException("Changes are not based on the HEAD commit.");
            }

            if (!hooks.OnCommitStarted(changes, message))
            {
                return(null);
            }

            changes.UpdateTreeDefinition(repository, definition);

            var result = Commit(repository, definition, message, author, committer, options, mergeParent);

            hooks.OnCommitCompleted(changes, message, result.Id);

            return(result);
        }
示例#3
0
        /// <summary>
        /// Called when a commit is about to be started.
        /// </summary>
        /// <param name="changes">The changes.</param>
        /// <param name="message">The message.</param>
        /// <param name="commitId">The commit identifier.</param>
        internal void OnCommitCompleted(MetadataTreeChanges changes, string message, ObjectId commitId)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var args = new CommitCompletedEventArgs(changes, message, commitId);

            CommitCompleted?.Invoke(this, args);
        }
示例#4
0
        /// <summary>
        /// Called when a commit is about to be started.
        /// </summary>
        /// <param name="changes">The changes.</param>
        /// <param name="message">The message.</param>
        /// <returns>The <see cref="CancelEventArgs"/>.</returns>
        internal bool OnCommitStarted(MetadataTreeChanges changes, string message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var args = new CommitStartedEventArgs(changes, message);

            CommitStarted?.Invoke(this, args);
            return(!args.Cancel);
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommitCompletedEventArgs"/> class.
 /// </summary>
 /// <param name="changes">The changes.</param>
 /// <param name="message">The message.</param>
 /// <param name="commitId">The commit identifier.</param>
 /// <exception cref="ArgumentNullException">message</exception>
 public CommitCompletedEventArgs(MetadataTreeChanges changes, string message, ObjectId commitId)
 {
     Changes  = changes ?? throw new ArgumentNullException(nameof(changes));
     Message  = message ?? throw new ArgumentNullException(nameof(message));
     CommitId = commitId ?? throw new ArgumentNullException(nameof(commitId));
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommitStartedEventArgs"/> class.
 /// </summary>
 /// <param name="changes">The changes.</param>
 /// <param name="message">The message.</param>
 /// <exception cref="ArgumentNullException">message</exception>
 public CommitStartedEventArgs(MetadataTreeChanges changes, string message)
 {
     Changes = changes ?? throw new ArgumentNullException(nameof(changes));
     Message = message ?? throw new ArgumentNullException(nameof(message));
 }