Commit fa5d94a0 by nulltoken

reset: prevent hard reset in a bare repository

parent 1ddc537c
......@@ -39,9 +39,11 @@ 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__ensure_not_bare(repo, "reset mixed") < 0)
return GIT_EBAREREPO;
if (reset_type != GIT_RESET_SOFT
&& git_repository__ensure_not_bare(
repo,
reset_type == GIT_RESET_MIXED ? "reset mixed" : "reset hard") < 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");
......
......@@ -44,3 +44,17 @@ void test_reset_hard__resetting_culls_empty_directories(void)
git_buf_free(&subfile_path);
git_buf_free(&newdir_path);
}
void test_reset_hard__cannot_reset_in_a_bare_repository(void)
{
git_repository *bare;
cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
cl_assert(git_repository_is_bare(bare) == true);
retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO);
cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_HARD));
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