summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-07-11 19:03:38 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-07-12 12:11:22 +0200
commit0d98af0911ebf55ba64cc0c9e17a3d450c77a9be (patch)
tree349d805b73f3cdb1da9477db1022ddd3798c4076
parent8a52ed7a482935c74dbb24358e21811dfa6d91c2 (diff)
downloadlibgit2-0d98af0911ebf55ba64cc0c9e17a3d450c77a9be.tar.gz
blob: fail to create a blob from a dir with EDIRECTORY
This also affects `git_index_add_bypath()` by providing a better error message and a specific error code when a directory is passed.
-rw-r--r--src/blob.c6
-rw-r--r--tests/index/bypath.c23
-rw-r--r--tests/submodule/add.c1
3 files changed, 30 insertions, 0 deletions
diff --git a/src/blob.c b/src/blob.c
index 07c4d92c8..ad0f4ac62 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -185,6 +185,12 @@ int git_blob__create_from_paths(
(error = git_repository_odb(&odb, repo)) < 0)
goto done;
+ if (S_ISDIR(st.st_mode)) {
+ giterr_set(GITERR_ODB, "cannot create blob from '%s'; it is a directory", content_path);
+ error = GIT_EDIRECTORY;
+ goto done;
+ }
+
if (out_st)
memcpy(out_st, &st, sizeof(st));
diff --git a/tests/index/bypath.c b/tests/index/bypath.c
new file mode 100644
index 000000000..08c9934ea
--- /dev/null
+++ b/tests/index/bypath.c
@@ -0,0 +1,23 @@
+#include "clar_libgit2.h"
+#include "repository.h"
+#include "../submodule/submodule_helpers.h"
+
+static git_repository *g_repo;
+static git_index *g_idx;
+
+void test_index_bypath__initialize(void)
+{
+ g_repo = setup_fixture_submod2();
+ cl_git_pass(git_repository_index__weakptr(&g_idx, g_repo));
+}
+
+void test_index_bypath__cleanup(void)
+{
+ g_repo = NULL;
+ g_idx = NULL;
+}
+
+void test_index_bypath__add_directory(void)
+{
+ cl_git_fail_with(GIT_EDIRECTORY, git_index_add_bypath(g_idx, "just_a_dir"));
+}
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index 01625d3aa..c3b3e6364 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -4,6 +4,7 @@
#include "submodule_helpers.h"
#include "config/config_helpers.h"
#include "fileops.h"
+#include "repository.h"
static git_repository *g_repo = NULL;