diff options
author | nulltoken <emeric.fermas@gmail.com> | 2013-04-29 21:27:05 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-04-29 21:27:05 +0400 |
commit | 023eaf4ff4346140acb93797b3e9984e4434b1b2 (patch) | |
tree | 71482a6541b927aef757716c9481ad3bdb9b7e0d /LibGit2Sharp/RepositoryExtensions.cs | |
parent | 1465bf31cdfcf59bceab42bb0e8d0543b02503dc (diff) |
Prevent repo.Lookup() to accept GitLink as a target type
Diffstat (limited to 'LibGit2Sharp/RepositoryExtensions.cs')
-rw-r--r-- | LibGit2Sharp/RepositoryExtensions.cs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs index c653e9fe..ae62fab2 100644 --- a/LibGit2Sharp/RepositoryExtensions.cs +++ b/LibGit2Sharp/RepositoryExtensions.cs @@ -21,6 +21,8 @@ namespace LibGit2Sharp /// <returns></returns> public static T Lookup<T>(this IRepository repository, string objectish) where T : GitObject { + EnsureNoGitLink<T>(); + return (T)repository.Lookup(objectish, GitObject.TypeToTypeMap[typeof (T)]); } @@ -33,9 +35,21 @@ namespace LibGit2Sharp /// <returns></returns> public static T Lookup<T>(this IRepository repository, ObjectId id) where T : GitObject { + EnsureNoGitLink<T>(); + return (T)repository.Lookup(id, GitObject.TypeToTypeMap[typeof(T)]); } + private static void EnsureNoGitLink<T>() where T : GitObject + { + if (typeof(T) != typeof(GitLink)) + { + return; + } + + throw new ArgumentException("A GitObject of type 'GitLink' cannot be looked up."); + } + /// <summary> /// Creates a lightweight tag with the specified name. This tag will point at the commit pointed at by the <see cref = "Repository.Head" />. /// </summary> |