diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-05-16 02:40:19 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-05-16 02:40:19 +0400 |
commit | 8344599c36c65dcfb0ac5547a11c994598b19dcc (patch) | |
tree | a5af47ab8a81aadc083ee459542ea7f423ded0e3 /LibGit2Sharp/ObjectDatabase.cs | |
parent | 6bf14afe223468e11c9630510e88f8c70678ab3f (diff) |
Make ObjectDatabase.CreateBlob() able to work against a bare repository
Additionally, the method will also accept paths leading to files outside of the working directory of a non bare repository.
Diffstat (limited to 'LibGit2Sharp/ObjectDatabase.cs')
-rw-r--r-- | LibGit2Sharp/ObjectDatabase.cs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index dfaf565d..912c99a9 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; @@ -38,17 +39,23 @@ namespace LibGit2Sharp /// <summary> /// Inserts a <see cref="Blob"/> into the object database, created from the content of a file. /// </summary> - /// <param name="path">Relative path to the file in the working directory.</param> + /// <param name="path">Path to the file to create the blob from.</param> /// <returns>The created <see cref="Blob"/>.</returns> public Blob CreateBlob(string path) { - if (repo.Info.IsBare) + Ensure.ArgumentNotNullOrEmptyString(path, "path"); + + var oid = new GitOid(); + + if (!repo.Info.IsBare && !Path.IsPathRooted(path)) { - throw new NotImplementedException(); + 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)); } - var oid = new GitOid(); - Ensure.Success(NativeMethods.git_blob_create_fromfile(ref oid, repo.Handle, path)); return repo.Lookup<Blob>(new ObjectId(oid)); } |