mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 12:13:18 +00:00
errors: deploy GIT_EBAREREPO usage
This commit is contained in:
parent
bb2d305c20
commit
ced8d1420a
@ -212,8 +212,10 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
|
||||
const char *workdir;
|
||||
int error;
|
||||
|
||||
if ((error = git_repository__ensure_not_bare(repo, "create blob from file")) < 0)
|
||||
return error;
|
||||
|
||||
workdir = git_repository_workdir(repo);
|
||||
assert(workdir); /* error to call this on bare repo */
|
||||
|
||||
if (git_buf_joinpath(&full_path, workdir, path) < 0) {
|
||||
git_buf_free(&full_path);
|
||||
|
@ -659,11 +659,8 @@ int git_iterator_for_workdir_range(
|
||||
|
||||
assert(iter && repo);
|
||||
|
||||
if (git_repository_is_bare(repo)) {
|
||||
giterr_set(GITERR_INVALID,
|
||||
"Cannot scan working directory for bare repo");
|
||||
return -1;
|
||||
}
|
||||
if ((error = git_repository__ensure_not_bare(repo, "scan working directory")) < 0)
|
||||
return error;
|
||||
|
||||
ITERATOR_BASE_INIT(wi, workdir, WORKDIR);
|
||||
|
||||
|
@ -149,4 +149,19 @@ void git_repository__cvar_cache_clear(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
|
||||
|
@ -34,8 +34,9 @@ int git_reset(
|
||||
if (git_object_owner(target) != repo)
|
||||
return reset_error_invalid("The given target does not belong to this repository.");
|
||||
|
||||
if (reset_type == GIT_RESET_MIXED && git_repository_is_bare(repo))
|
||||
return reset_error_invalid("Mixed reset is not allowed in a bare repository.");
|
||||
if (reset_type == GIT_RESET_MIXED
|
||||
&& git_repository__ensure_not_bare(repo, "reset mixed") < 0)
|
||||
return GIT_EBAREREPO;
|
||||
|
||||
if (git_object_peel(&commit, target, GIT_OBJ_COMMIT) < 0) {
|
||||
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)
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user