diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index a79965613..05d2f5f6b 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -365,7 +365,9 @@ public virtual Commit CreateCommit(Signature author, Signature committer, string ObjectId commitId = Proxy.git_commit_create(repo.Handle, null, author, committer, message, tree, parentIds); - return repo.Lookup(commitId); + Commit commit = repo.Lookup(commitId); + Ensure.GitObjectIsNotNull(commit, commitId.Sha); + return commit; } /// @@ -454,6 +456,8 @@ public virtual string ShortenObjectId(GitObject gitObject) /// A short string representation of the . public virtual string ShortenObjectId(GitObject gitObject, int minLength) { + Ensure.ArgumentNotNull(gitObject, "gitObject"); + if (minLength <= 0 || minLength > ObjectId.HexSize) { throw new ArgumentOutOfRangeException("minLength", minLength, @@ -462,6 +466,11 @@ public virtual string ShortenObjectId(GitObject gitObject, int minLength) string shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id); + if (shortSha == null) + { + throw new LibGit2SharpException("Unable to abbreviate SHA-1 value for GitObject " + gitObject.Id); + } + if (minLength <= shortSha.Length) { return shortSha; diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 79c9077bc..fef0ccac1 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -476,7 +476,7 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath know using (GitObjectSafeHandle obj = Proxy.git_object_lookup(handle, id, type)) { - if (obj == null) + if (obj == null || obj.IsInvalid) { return null; }