Adds IRepository.IsSha

This commit is contained in:
Jordan Brown
2018-09-06 20:41:59 -04:00
parent 76ca524299
commit f084df02dc
2 changed files with 15 additions and 0 deletions
@@ -45,6 +45,14 @@ namespace Tgstation.Server.Host.Components.Repository
/// </summary>
string Origin { get; }
/// <summary>
/// Checks if a given <paramref name="committish"/> is a sha
/// </summary>
/// <param name="committish">The git object to check</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if <paramref name="committish"/> is a sha, <see langword="false"/> otherwise</returns>
Task<bool> IsSha(string committish, CancellationToken cancellationToken);
/// <summary>
/// Checks out a given <paramref name="committish"/>
/// </summary>
@@ -418,5 +418,12 @@ namespace Tgstation.Server.Host.Components.Repository
}
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false);
}
/// <inheritdoc />
public Task<bool> IsSha(string committish, CancellationToken cancellationToken) => Task.Factory.StartNew(() =>
{
var gitObject = repository.Lookup(committish, ObjectType.Commit);
return gitObject != null;
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
}
}