diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-08-23 13:28:19 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-08-23 13:28:19 +0400 |
commit | 0bcfb51563b9aef4ae79e705ae0b626de5f0a5c2 (patch) | |
tree | 8f1ab4b33359c48092759b6791c9c887d4a39373 /LibGit2Sharp/ObjectDatabase.cs | |
parent | 64c052e316a0b83b50c9f4407b51a87ef9dd172e (diff) |
Straighten the creation of a Blob in the database
Diffstat (limited to 'LibGit2Sharp/ObjectDatabase.cs')
-rw-r--r-- | LibGit2Sharp/ObjectDatabase.cs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index 48ff2e43..373081fa 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -48,7 +48,9 @@ namespace LibGit2Sharp /// <summary> /// Inserts a <see cref="Blob"/> into the object database, created from the content of a file. /// </summary> - /// <param name="path">Path to the file to create the blob from.</param> + /// <param name="path">Path to the file to create the blob from. A relative path is allowed to + /// be passed if the <see cref="Repository" /> is a standard, non-bare, repository. The path + /// will then be considered as a path relative to the root of the working directory.</param> /// <returns>The created <see cref="Blob"/>.</returns> public virtual Blob CreateBlob(string path) { @@ -56,15 +58,15 @@ namespace LibGit2Sharp var oid = new GitOid(); - if (!repo.Info.IsBare && !Path.IsPathRooted(path)) + if (repo.Info.IsBare && !Path.IsPathRooted(path)) { - Ensure.Success(NativeMethods.git_blob_create_fromfile(ref oid, repo.Handle, path)); - } - else - { - Ensure.Success(NativeMethods.git_blob_create_fromdisk(ref oid, repo.Handle, path)); + throw new InvalidOperationException(string.Format("Cannot create a blob in a bare repository from a relative path ('{0}').", path)); } + Ensure.Success(Path.IsPathRooted(path) + ? NativeMethods.git_blob_create_fromdisk(ref oid, repo.Handle, path) + : NativeMethods.git_blob_create_fromfile(ref oid, repo.Handle, path)); + return repo.Lookup<Blob>(new ObjectId(oid)); } |