Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b46c7ee

Browse files
author
Edward Thomson
committed
refs: complain when a directory exists at ref
When a (non-empty) directory exists at the reference target location, complain with a more actionable error message.
1 parent ec50b23 commit b46c7ee

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/refdb_fs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,11 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
733733

734734
error = git_filebuf_open(file, ref_path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE);
735735

736+
if (error == GIT_EDIRECTORY)
737+
giterr_set(GITERR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
738+
736739
git_buf_free(&ref_path);
737-
return error;
740+
return error;
738741
}
739742

740743
static int loose_commit(git_filebuf *file, const git_reference *ref)

tests/refs/create.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ void test_refs_create__propagate_eexists(void)
151151
cl_assert(error == GIT_EEXISTS);
152152
}
153153

154+
void test_refs_create__existing_dir_propagates_edirectory(void)
155+
{
156+
git_reference *new_reference, *fail_reference;
157+
git_oid id;
158+
const char *dir_head = "refs/heads/new-dir/new-head",
159+
*fail_head = "refs/heads/new-dir";
160+
161+
git_oid_fromstr(&id, current_master_tip);
162+
163+
/* Create and write the new object id reference */
164+
cl_git_pass(git_reference_create(&new_reference, g_repo, dir_head, &id, 1, NULL));
165+
cl_git_fail_with(GIT_EDIRECTORY,
166+
git_reference_create(&fail_reference, g_repo, fail_head, &id, false, NULL));
167+
168+
git_reference_free(new_reference);
169+
}
170+
154171
static void test_invalid_name(const char *name)
155172
{
156173
git_reference *new_reference;

0 commit comments

Comments
 (0)