mirror of
https://git.proxmox.com/git/libgit2
synced 2025-10-18 17:13:37 +00:00
reset: prevent hard reset in a bare repository
This commit is contained in:
parent
1ddc537c77
commit
fa5d94a0d4
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user