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
0d847a31
Commit
0d847a31
authored
Feb 03, 2014
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reset helpers: use revparse instead
parent
3b6a5bac
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
23 additions
and
32 deletions
+23
-32
tests/index/names.c
+2
-2
tests/index/reuc.c
+3
-3
tests/refs/branches/create.c
+5
-4
tests/reset/hard.c
+4
-5
tests/reset/mixed.c
+2
-2
tests/reset/reset_helpers.c
+0
-7
tests/reset/reset_helpers.h
+0
-1
tests/reset/soft.c
+7
-8
No files found.
tests/index/names.c
View file @
0d847a31
...
@@ -86,7 +86,7 @@ void test_index_names__cleaned_on_reset_hard(void)
...
@@ -86,7 +86,7 @@ void test_index_names__cleaned_on_reset_hard(void)
{
{
git_object
*
target
;
git_object
*
target
;
retrieve_target_from_oid
(
&
target
,
repo
,
"3a34580a35add43a4cf361e8e9a30060a905c876"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"3a34580"
)
);
test_index_names__add
();
test_index_names__add
();
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
...
@@ -99,7 +99,7 @@ void test_index_names__cleaned_on_reset_mixed(void)
...
@@ -99,7 +99,7 @@ void test_index_names__cleaned_on_reset_mixed(void)
{
{
git_object
*
target
;
git_object
*
target
;
retrieve_target_from_oid
(
&
target
,
repo
,
"3a34580a35add43a4cf361e8e9a30060a905c876"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"3a34580"
)
);
test_index_names__add
();
test_index_names__add
();
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
));
...
...
tests/index/reuc.c
View file @
0d847a31
...
@@ -295,7 +295,7 @@ void test_index_reuc__cleaned_on_reset_hard(void)
...
@@ -295,7 +295,7 @@ void test_index_reuc__cleaned_on_reset_hard(void)
{
{
git_object
*
target
;
git_object
*
target
;
retrieve_target_from_oid
(
&
target
,
repo
,
"3a34580a35add43a4cf361e8e9a30060a905c876"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"3a34580"
)
);
test_index_reuc__add
();
test_index_reuc__add
();
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
...
@@ -308,7 +308,7 @@ void test_index_reuc__cleaned_on_reset_mixed(void)
...
@@ -308,7 +308,7 @@ void test_index_reuc__cleaned_on_reset_mixed(void)
{
{
git_object
*
target
;
git_object
*
target
;
retrieve_target_from_oid
(
&
target
,
repo
,
"3a34580a35add43a4cf361e8e9a30060a905c876"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"3a34580"
)
);
test_index_reuc__add
();
test_index_reuc__add
();
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
));
...
@@ -321,7 +321,7 @@ void test_index_reuc__retained_on_reset_soft(void)
...
@@ -321,7 +321,7 @@ void test_index_reuc__retained_on_reset_soft(void)
{
{
git_object
*
target
;
git_object
*
target
;
retrieve_target_from_oid
(
&
target
,
repo
,
"3a34580a35add43a4cf361e8e9a30060a905c876"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"3a34580"
)
);
git_reset
(
repo
,
target
,
GIT_RESET_HARD
);
git_reset
(
repo
,
target
,
GIT_RESET_HARD
);
...
...
tests/refs/branches/create.c
View file @
0d847a31
...
@@ -29,15 +29,16 @@ void test_refs_branches_create__cleanup(void)
...
@@ -29,15 +29,16 @@ void test_refs_branches_create__cleanup(void)
static
void
retrieve_target_from_oid
(
git_commit
**
out
,
git_repository
*
repo
,
const
char
*
sha
)
static
void
retrieve_target_from_oid
(
git_commit
**
out
,
git_repository
*
repo
,
const
char
*
sha
)
{
{
git_o
id
oid
;
git_o
bject
*
obj
;
cl_git_pass
(
git_oid_fromstr
(
&
oid
,
sha
));
cl_git_pass
(
git_revparse_single
(
&
obj
,
repo
,
sha
));
cl_git_pass
(
git_commit_lookup
(
out
,
repo
,
&
oid
));
cl_git_pass
(
git_commit_lookup
(
out
,
repo
,
git_object_id
(
obj
)));
git_object_free
(
obj
);
}
}
static
void
retrieve_known_commit
(
git_commit
**
commit
,
git_repository
*
repo
)
static
void
retrieve_known_commit
(
git_commit
**
commit
,
git_repository
*
repo
)
{
{
retrieve_target_from_oid
(
commit
,
repo
,
"e90810b8df3
e80c413d903f631643c716887138d
"
);
retrieve_target_from_oid
(
commit
,
repo
,
"e90810b8df3"
);
}
}
#define NEW_BRANCH_NAME "new-branch-on-the-block"
#define NEW_BRANCH_NAME "new-branch-on-the-block"
...
...
tests/reset/hard.c
View file @
0d847a31
...
@@ -69,8 +69,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
...
@@ -69,8 +69,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_assert_equal_s
(
before
[
i
],
content
.
ptr
);
cl_assert_equal_s
(
before
[
i
],
content
.
ptr
);
}
}
retrieve_target_from_oid
(
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"26a125e"
));
&
target
,
repo
,
"26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f"
);
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
...
@@ -95,7 +94,7 @@ void test_reset_hard__cannot_reset_in_a_bare_repository(void)
...
@@ -95,7 +94,7 @@ void test_reset_hard__cannot_reset_in_a_bare_repository(void)
cl_git_pass
(
git_repository_open
(
&
bare
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_repository_open
(
&
bare
,
cl_fixture
(
"testrepo.git"
)));
cl_assert
(
git_repository_is_bare
(
bare
)
==
true
);
cl_assert
(
git_repository_is_bare
(
bare
)
==
true
);
retrieve_target_from_oid
(
&
target
,
bare
,
KNOWN_COMMIT_IN_BARE_REPO
);
cl_git_pass
(
git_revparse_single
(
&
target
,
bare
,
KNOWN_COMMIT_IN_BARE_REPO
)
);
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_reset
(
bare
,
target
,
GIT_RESET_HARD
));
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_reset
(
bare
,
target
,
GIT_RESET_HARD
));
...
@@ -152,7 +151,7 @@ void test_reset_hard__resetting_reverts_unmerged(void)
...
@@ -152,7 +151,7 @@ void test_reset_hard__resetting_reverts_unmerged(void)
unmerged_index_init
(
index
,
entries
);
unmerged_index_init
(
index
,
entries
);
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
git_index_write
(
index
));
retrieve_target_from_oid
(
&
target
,
repo
,
"26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"26a125e"
)
);
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
cl_assert
(
git_path_exists
(
"status/conflicting_file"
)
==
0
);
cl_assert
(
git_path_exists
(
"status/conflicting_file"
)
==
0
);
...
@@ -183,7 +182,7 @@ void test_reset_hard__cleans_up_merge(void)
...
@@ -183,7 +182,7 @@ void test_reset_hard__cleans_up_merge(void)
cl_git_pass
(
git_buf_joinpath
(
&
orig_head_path
,
git_repository_path
(
repo
),
"ORIG_HEAD"
));
cl_git_pass
(
git_buf_joinpath
(
&
orig_head_path
,
git_repository_path
(
repo
),
"ORIG_HEAD"
));
cl_git_mkfile
(
git_buf_cstr
(
&
orig_head_path
),
"0017bd4ab1ec30440b17bae1680cff124ab5f1f6"
);
cl_git_mkfile
(
git_buf_cstr
(
&
orig_head_path
),
"0017bd4ab1ec30440b17bae1680cff124ab5f1f6"
);
retrieve_target_from_oid
(
&
target
,
repo
,
"0017bd4ab1ec30440b17bae1680cff124ab5f1f6"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"0017bd4"
)
);
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
));
cl_assert
(
!
git_path_exists
(
git_buf_cstr
(
&
merge_head_path
)));
cl_assert
(
!
git_path_exists
(
git_buf_cstr
(
&
merge_head_path
)));
...
...
tests/reset/mixed.c
View file @
0d847a31
...
@@ -27,7 +27,7 @@ void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
...
@@ -27,7 +27,7 @@ void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
cl_git_pass
(
git_repository_open
(
&
bare
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_repository_open
(
&
bare
,
cl_fixture
(
"testrepo.git"
)));
cl_assert
(
git_repository_is_bare
(
bare
)
==
true
);
cl_assert
(
git_repository_is_bare
(
bare
)
==
true
);
retrieve_target_from_oid
(
&
target
,
bare
,
KNOWN_COMMIT_IN_BARE_REPO
);
cl_git_pass
(
git_revparse_single
(
&
target
,
bare
,
KNOWN_COMMIT_IN_BARE_REPO
)
);
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_reset
(
bare
,
target
,
GIT_RESET_MIXED
));
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_reset
(
bare
,
target
,
GIT_RESET_MIXED
));
...
@@ -40,7 +40,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
...
@@ -40,7 +40,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
cl_git_pass
(
git_status_file
(
&
status
,
repo
,
"macro_bad"
));
cl_git_pass
(
git_status_file
(
&
status
,
repo
,
"macro_bad"
));
cl_assert
(
status
==
GIT_STATUS_CURRENT
);
cl_assert
(
status
==
GIT_STATUS_CURRENT
);
retrieve_target_from_oid
(
&
target
,
repo
,
"605812ab7fe421fdd325a935d35cb06a9234a7d7"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"605812a"
)
);
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
));
...
...
tests/reset/reset_helpers.c
View file @
0d847a31
#include "clar_libgit2.h"
#include "clar_libgit2.h"
#include "reset_helpers.h"
#include "reset_helpers.h"
void
retrieve_target_from_oid
(
git_object
**
object_out
,
git_repository
*
repo
,
const
char
*
sha
)
{
git_oid
oid
;
cl_git_pass
(
git_oid_fromstr
(
&
oid
,
sha
));
cl_git_pass
(
git_object_lookup
(
object_out
,
repo
,
&
oid
,
GIT_OBJ_ANY
));
}
tests/reset/reset_helpers.h
View file @
0d847a31
...
@@ -3,4 +3,3 @@
...
@@ -3,4 +3,3 @@
#define KNOWN_COMMIT_IN_BARE_REPO "e90810b8df3e80c413d903f631643c716887138d"
#define KNOWN_COMMIT_IN_BARE_REPO "e90810b8df3e80c413d903f631643c716887138d"
#define KNOWN_COMMIT_IN_ATTR_REPO "217878ab49e1314388ea2e32dc6fdb58a1b969e0"
#define KNOWN_COMMIT_IN_ATTR_REPO "217878ab49e1314388ea2e32dc6fdb58a1b969e0"
extern
void
retrieve_target_from_oid
(
git_object
**
object_out
,
git_repository
*
repo
,
const
char
*
sha
);
tests/reset/soft.c
View file @
0d847a31
...
@@ -26,8 +26,7 @@ static void assert_reset_soft(bool should_be_detached)
...
@@ -26,8 +26,7 @@ static void assert_reset_soft(bool should_be_detached)
cl_git_pass
(
git_reference_name_to_id
(
&
oid
,
repo
,
"HEAD"
));
cl_git_pass
(
git_reference_name_to_id
(
&
oid
,
repo
,
"HEAD"
));
cl_git_fail
(
git_oid_streq
(
&
oid
,
KNOWN_COMMIT_IN_BARE_REPO
));
cl_git_fail
(
git_oid_streq
(
&
oid
,
KNOWN_COMMIT_IN_BARE_REPO
));
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
KNOWN_COMMIT_IN_BARE_REPO
));
retrieve_target_from_oid
(
&
target
,
repo
,
KNOWN_COMMIT_IN_BARE_REPO
);
cl_assert
(
git_repository_head_detached
(
repo
)
==
should_be_detached
);
cl_assert
(
git_repository_head_detached
(
repo
)
==
should_be_detached
);
...
@@ -60,7 +59,7 @@ void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_ch
...
@@ -60,7 +59,7 @@ void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_ch
git_oid_fmt
(
raw_head_oid
,
&
oid
);
git_oid_fmt
(
raw_head_oid
,
&
oid
);
raw_head_oid
[
GIT_OID_HEXSZ
]
=
'\0'
;
raw_head_oid
[
GIT_OID_HEXSZ
]
=
'\0'
;
retrieve_target_from_oid
(
&
target
,
repo
,
raw_head_oid
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
raw_head_oid
)
);
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
...
@@ -73,7 +72,7 @@ void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void
...
@@ -73,7 +72,7 @@ void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void
git_oid
oid
;
git_oid
oid
;
/* b25fa35 is a tag, pointing to another tag which points to commit e90810b */
/* b25fa35 is a tag, pointing to another tag which points to commit e90810b */
retrieve_target_from_oid
(
&
target
,
repo
,
"b25fa35b38051e4ae45d4222e795f9df2e43f1d1"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"b25fa35"
)
);
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
...
@@ -85,13 +84,13 @@ void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void
...
@@ -85,13 +84,13 @@ void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void
void
test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit
(
void
)
void
test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit
(
void
)
{
{
/* 53fc32d is the tree of commit e90810b */
/* 53fc32d is the tree of commit e90810b */
retrieve_target_from_oid
(
&
target
,
repo
,
"53fc32d17276939fc79ed05badaef2db09990016"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"53fc32d"
)
);
cl_git_fail
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
cl_git_fail
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
git_object_free
(
target
);
git_object_free
(
target
);
/* 521d87c is an annotated tag pointing to a blob */
/* 521d87c is an annotated tag pointing to a blob */
retrieve_target_from_oid
(
&
target
,
repo
,
"521d87c1ec3aef9824daf6d96cc0ae3710766d91"
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"521d87c"
)
);
cl_git_fail
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
cl_git_fail
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
}
}
...
@@ -99,7 +98,7 @@ void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_lo
...
@@ -99,7 +98,7 @@ void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_lo
{
{
git_reference
*
head
;
git_reference
*
head
;
retrieve_target_from_oid
(
&
target
,
repo
,
KNOWN_COMMIT_IN_BARE_REPO
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
KNOWN_COMMIT_IN_BARE_REPO
)
);
make_head_unborn
(
repo
,
NON_EXISTING_HEAD
);
make_head_unborn
(
repo
,
NON_EXISTING_HEAD
);
...
@@ -123,7 +122,7 @@ void test_reset_soft__fails_when_merging(void)
...
@@ -123,7 +122,7 @@ void test_reset_soft__fails_when_merging(void)
cl_git_pass
(
git_buf_joinpath
(
&
merge_head_path
,
git_repository_path
(
repo
),
"MERGE_HEAD"
));
cl_git_pass
(
git_buf_joinpath
(
&
merge_head_path
,
git_repository_path
(
repo
),
"MERGE_HEAD"
));
cl_git_mkfile
(
git_buf_cstr
(
&
merge_head_path
),
"beefbeefbeefbeefbeefbeefbeefbeefbeefbeef
\n
"
);
cl_git_mkfile
(
git_buf_cstr
(
&
merge_head_path
),
"beefbeefbeefbeefbeefbeefbeefbeefbeefbeef
\n
"
);
retrieve_target_from_oid
(
&
target
,
repo
,
KNOWN_COMMIT_IN_BARE_REPO
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
KNOWN_COMMIT_IN_BARE_REPO
)
);
cl_assert_equal_i
(
GIT_EUNMERGED
,
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
cl_assert_equal_i
(
GIT_EUNMERGED
,
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
));
cl_git_pass
(
p_unlink
(
git_buf_cstr
(
&
merge_head_path
)));
cl_git_pass
(
p_unlink
(
git_buf_cstr
(
&
merge_head_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