Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
fa5d94a0
Commit
fa5d94a0
authored
Oct 13, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reset: prevent hard reset in a bare repository
parent
1ddc537c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
src/reset.c
+5
-3
tests-clar/reset/hard.c
+14
-0
No files found.
src/reset.c
View file @
fa5d94a0
...
@@ -39,9 +39,11 @@ int git_reset(
...
@@ -39,9 +39,11 @@ 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
if
(
reset_type
!=
GIT_RESET_SOFT
&&
git_repository__ensure_not_bare
(
repo
,
"reset mixed"
)
<
0
)
&&
git_repository__ensure_not_bare
(
return
GIT_EBAREREPO
;
repo
,
reset_type
==
GIT_RESET_MIXED
?
"reset mixed"
:
"reset hard"
)
<
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"
);
...
...
tests-clar/reset/hard.c
View file @
fa5d94a0
...
@@ -44,3 +44,17 @@ void test_reset_hard__resetting_culls_empty_directories(void)
...
@@ -44,3 +44,17 @@ void test_reset_hard__resetting_culls_empty_directories(void)
git_buf_free
(
&
subfile_path
);
git_buf_free
(
&
subfile_path
);
git_buf_free
(
&
newdir_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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment