Commit aafaa491 by Carlos Martín Nieto

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.
parent 7624b91f
...@@ -185,6 +185,12 @@ int git_blob__create_from_paths( ...@@ -185,6 +185,12 @@ int git_blob__create_from_paths(
(error = git_repository_odb(&odb, repo)) < 0) (error = git_repository_odb(&odb, repo)) < 0)
goto done; 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) if (out_st)
memcpy(out_st, &st, sizeof(st)); memcpy(out_st, &st, sizeof(st));
......
#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"));
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "submodule_helpers.h" #include "submodule_helpers.h"
#include "config/config_helpers.h" #include "config/config_helpers.h"
#include "fileops.h" #include "fileops.h"
#include "repository.h"
static git_repository *g_repo = NULL; static git_repository *g_repo = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment