Commit ced8d142 by nulltoken

errors: deploy GIT_EBAREREPO usage

parent bb2d305c
...@@ -212,8 +212,10 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat ...@@ -212,8 +212,10 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
const char *workdir; const char *workdir;
int error; int error;
if ((error = git_repository__ensure_not_bare(repo, "create blob from file")) < 0)
return error;
workdir = git_repository_workdir(repo); workdir = git_repository_workdir(repo);
assert(workdir); /* error to call this on bare repo */
if (git_buf_joinpath(&full_path, workdir, path) < 0) { if (git_buf_joinpath(&full_path, workdir, path) < 0) {
git_buf_free(&full_path); git_buf_free(&full_path);
......
...@@ -659,11 +659,8 @@ int git_iterator_for_workdir_range( ...@@ -659,11 +659,8 @@ int git_iterator_for_workdir_range(
assert(iter && repo); assert(iter && repo);
if (git_repository_is_bare(repo)) { if ((error = git_repository__ensure_not_bare(repo, "scan working directory")) < 0)
giterr_set(GITERR_INVALID, return error;
"Cannot scan working directory for bare repo");
return -1;
}
ITERATOR_BASE_INIT(wi, workdir, WORKDIR); ITERATOR_BASE_INIT(wi, workdir, WORKDIR);
......
...@@ -149,4 +149,19 @@ void git_repository__cvar_cache_clear(git_repository *repo); ...@@ -149,4 +149,19 @@ void git_repository__cvar_cache_clear(git_repository *repo);
*/ */
extern void git_submodule_config_free(git_repository *repo); extern void git_submodule_config_free(git_repository *repo);
GIT_INLINE(int) git_repository__ensure_not_bare(
git_repository *repo,
const char *operation_name)
{
if (!git_repository_is_bare(repo))
return 0;
giterr_set(
GITERR_REPOSITORY,
"Cannot %s. This operation is not allowed against bare repositories.",
operation_name);
return GIT_EBAREREPO;
}
#endif #endif
...@@ -34,8 +34,9 @@ int git_reset( ...@@ -34,8 +34,9 @@ int git_reset(
if (git_object_owner(target) != repo) if (git_object_owner(target) != repo)
return reset_error_invalid("The given target does not belong to this repository."); return reset_error_invalid("The given target does not belong to this repository.");
if (reset_type == GIT_RESET_MIXED && git_repository_is_bare(repo)) if (reset_type == GIT_RESET_MIXED
return reset_error_invalid("Mixed reset is not allowed in a bare repository."); && git_repository__ensure_not_bare(repo, "reset mixed") < 0)
return GIT_EBAREREPO;
if (git_object_peel(&commit, target, GIT_OBJ_COMMIT) < 0) { if (git_object_peel(&commit, target, GIT_OBJ_COMMIT) < 0) {
reset_error_invalid("The given target does not resolve to a commit"); reset_error_invalid("The given target does not resolve to a commit");
......
...@@ -27,7 +27,7 @@ void test_reset_mixed__cannot_reset_in_a_bare_repository(void) ...@@ -27,7 +27,7 @@ void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO); retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO);
cl_git_fail(git_reset(bare, target, GIT_RESET_MIXED)); cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED));
git_repository_free(bare); git_repository_free(bare);
} }
......
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