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
ee8bb8ba
Commit
ee8bb8ba
authored
Aug 19, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reset: add support for GIT_RESET_HARD mode
parent
e93af304
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
1 deletions
+64
-1
include/git2/reset.h
+3
-0
include/git2/types.h
+1
-0
src/reset.c
+14
-1
tests-clar/reset/hard.c
+46
-0
No files found.
include/git2/reset.h
View file @
ee8bb8ba
...
...
@@ -24,6 +24,9 @@ GIT_BEGIN_DECL
* Specifying a Mixed kind of reset will trigger a Soft reset and the index will
* be replaced with the content of the commit tree.
*
* Specifying a Hard kind of reset will trigger a Mixed reset and the working
* directory will be replaced with the content of the index.
*
* TODO: Implement remaining kinds of resets.
*
* @param repo Repository where to perform the reset operation.
...
...
include/git2/types.h
View file @
ee8bb8ba
...
...
@@ -173,6 +173,7 @@ typedef enum {
typedef
enum
{
GIT_RESET_SOFT
=
1
,
GIT_RESET_MIXED
=
2
,
GIT_RESET_HARD
=
3
,
}
git_reset_type
;
/** Valid modes for index and tree entries. */
...
...
src/reset.c
View file @
ee8bb8ba
...
...
@@ -9,6 +9,7 @@
#include "commit.h"
#include "tag.h"
#include "git2/reset.h"
#include "git2/checkout.h"
#define ERROR_MSG "Cannot perform reset"
...
...
@@ -29,7 +30,9 @@ int git_reset(
int
error
=
-
1
;
assert
(
repo
&&
target
);
assert
(
reset_type
==
GIT_RESET_SOFT
||
reset_type
==
GIT_RESET_MIXED
);
assert
(
reset_type
==
GIT_RESET_SOFT
||
reset_type
==
GIT_RESET_MIXED
||
reset_type
==
GIT_RESET_HARD
);
if
(
git_object_owner
(
target
)
!=
repo
)
return
reset_error_invalid
(
"The given target does not belong to this repository."
);
...
...
@@ -73,6 +76,16 @@ int git_reset(
goto
cleanup
;
}
if
(
reset_type
==
GIT_RESET_MIXED
)
{
error
=
0
;
goto
cleanup
;
}
if
(
git_checkout_index
(
repo
,
NULL
,
NULL
,
NULL
)
<
0
)
{
giterr_set
(
GITERR_INDEX
,
"%s - Failed to checkout the index."
,
ERROR_MSG
);
goto
cleanup
;
}
error
=
0
;
cleanup:
...
...
tests-clar/reset/hard.c
0 → 100644
View file @
ee8bb8ba
#include "clar_libgit2.h"
#include "posix.h"
#include "reset_helpers.h"
#include "path.h"
#include "fileops.h"
static
git_repository
*
repo
;
static
git_object
*
target
;
void
test_reset_hard__initialize
(
void
)
{
repo
=
cl_git_sandbox_init
(
"status"
);
target
=
NULL
;
}
void
test_reset_hard__cleanup
(
void
)
{
git_object_free
(
target
);
cl_git_sandbox_cleanup
();
}
void
test_reset_hard__resetting_culls_empty_directories
(
void
)
{
git_buf
subdir_path
=
GIT_BUF_INIT
;
git_buf
subfile_path
=
GIT_BUF_INIT
;
git_buf
newdir_path
=
GIT_BUF_INIT
;
cl_git_pass
(
git_buf_joinpath
(
&
newdir_path
,
git_repository_workdir
(
repo
),
"newdir/"
));
cl_git_pass
(
git_buf_joinpath
(
&
subfile_path
,
git_buf_cstr
(
&
newdir_path
),
"with/nested/file.txt"
));
cl_git_pass
(
git_futils_mkpath2file
(
git_buf_cstr
(
&
subfile_path
),
0755
));
cl_git_mkfile
(
git_buf_cstr
(
&
subfile_path
),
"all anew...
\n
"
);
cl_git_pass
(
git_buf_joinpath
(
&
subdir_path
,
git_repository_workdir
(
repo
),
"subdir/"
));
cl_assert
(
git_path_isdir
(
git_buf_cstr
(
&
subdir_path
))
==
true
);
retrieve_target_from_oid
(
&
target
,
repo
,
"0017bd4ab1ec30440b17bae1680cff124ab5f1f6"
);
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
cl_assert
(
git_path_isdir
(
git_buf_cstr
(
&
subdir_path
))
==
false
);
cl_assert
(
git_path_isdir
(
git_buf_cstr
(
&
newdir_path
))
==
false
);
git_buf_free
(
&
subdir_path
);
git_buf_free
(
&
subfile_path
);
git_buf_free
(
&
newdir_path
);
}
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