/// <inheritdoc />
        public Task ResetToSha(string sha, Action <int> progressReporter, CancellationToken cancellationToken) => Task.Factory.StartNew(() =>
        {
            if (sha == null)
            {
                throw new ArgumentNullException(nameof(sha));
            }
            if (progressReporter == null)
            {
                throw new ArgumentNullException(nameof(progressReporter));
            }

            logger.LogDebug("Reset to sha: {0}", sha.Substring(0, 7));

            repository.RemoveUntrackedFiles();
            cancellationToken.ThrowIfCancellationRequested();

            var gitObject = repository.Lookup(sha, ObjectType.Commit);
            cancellationToken.ThrowIfCancellationRequested();

            if (gitObject == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot reset to non-existent SHA: {0}", sha));
            }

            repository.Reset(ResetMode.Hard, gitObject.Peel <Commit>(), new CheckoutOptions
            {
                OnCheckoutProgress = CheckoutProgressHandler(progressReporter)
            });
        }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
Example #2
0
 /// <inheritdoc />
 public Task ResetToSha(string sha, CancellationToken cancellationToken) => Task.Factory.StartNew(() =>
 {
     repository.Reset(ResetMode.Hard, sha);
     cancellationToken.ThrowIfCancellationRequested();
     repository.RemoveUntrackedFiles();
 }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);