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
4a0ac175
Commit
4a0ac175
authored
Jan 10, 2013
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkout: Deploy EMERGECONFLICT usage
parent
635c235c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
1 deletions
+87
-1
src/checkout.c
+1
-1
tests-clar/checkout/tree.c
+86
-0
No files found.
src/checkout.c
View file @
4a0ac175
...
...
@@ -616,7 +616,7 @@ static int checkout_get_actions(
{
giterr_set
(
GITERR_CHECKOUT
,
"%d conflicts prevent checkout"
,
(
int
)
counts
[
CHECKOUT_ACTION__CONFLICT
]);
error
=
-
1
;
error
=
GIT_EMERGECONFLICT
;
goto
fail
;
}
...
...
tests-clar/checkout/tree.c
View file @
4a0ac175
...
...
@@ -356,3 +356,89 @@ void test_checkout_tree__can_disable_pattern_match(void)
cl_assert
(
git_path_isfile
(
"testrepo/branch_file.txt"
));
}
void
assert_conflict
(
const
char
*
entry_path
,
const
char
*
new_content
,
const
char
*
parent_sha
,
const
char
*
commit_sha
)
{
git_index
*
index
;
git_object
*
hack_tree
;
git_reference
*
branch
,
*
head
;
git_buf
file_path
=
GIT_BUF_INIT
;
git_checkout_opts
opts
=
GIT_CHECKOUT_OPTS_INIT
;
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
/* Create a branch pointing at the parent */
cl_git_pass
(
git_revparse_single
(
&
g_object
,
g_repo
,
parent_sha
));
cl_git_pass
(
git_branch_create
(
&
branch
,
g_repo
,
"potential_conflict"
,
(
git_commit
*
)
g_object
,
0
));
/* Make HEAD point to this branch */
cl_git_pass
(
git_reference_symbolic_create
(
&
head
,
g_repo
,
"HEAD"
,
git_reference_name
(
branch
),
1
));
/* Checkout the parent */
opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
;
cl_git_pass
(
git_checkout_tree
(
g_repo
,
g_object
,
&
g_opts
));
/* Hack-ishy workaound to ensure *all* the index entries
* match the content of the tree
*/
cl_git_pass
(
git_object_peel
(
&
hack_tree
,
g_object
,
GIT_OBJ_TREE
));
cl_git_pass
(
git_index_read_tree
(
index
,
(
git_tree
*
)
hack_tree
));
git_object_free
(
hack_tree
);
git_object_free
(
g_object
);
g_object
=
NULL
;
/* Create a conflicting file */
cl_git_pass
(
git_buf_joinpath
(
&
file_path
,
"./testrepo"
,
entry_path
));
cl_git_mkfile
(
git_buf_cstr
(
&
file_path
),
new_content
);
git_buf_free
(
&
file_path
);
/* Trying to checkout the original commit */
cl_git_pass
(
git_revparse_single
(
&
g_object
,
g_repo
,
commit_sha
));
opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
cl_assert_equal_i
(
GIT_EMERGECONFLICT
,
git_checkout_tree
(
g_repo
,
g_object
,
&
g_opts
));
/* Stage the conflicting change */
cl_git_pass
(
git_index_add_from_workdir
(
index
,
entry_path
));
cl_git_pass
(
git_index_write
(
index
));
cl_assert_equal_i
(
GIT_EMERGECONFLICT
,
git_checkout_tree
(
g_repo
,
g_object
,
&
g_opts
));
}
void
test_checkout_tree__checking_out_a_conflicting_type_change_returns_EMERGECONFLICT
(
void
)
{
/*
* 099faba adds a symlink named 'link_to_new.txt'
* a65fedf is the parent of 099faba
*/
assert_conflict
(
"link_to_new.txt"
,
"old.txt"
,
"a65fedf"
,
"099faba"
);
}
void
test_checkout_tree__checking_out_a_conflicting_type_change_returns_EMERGECONFLICT_2
(
void
)
{
/*
* cf80f8d adds a directory named 'a/'
* a4a7dce is the parent of cf80f8d
*/
assert_conflict
(
"a"
,
"hello
\n
"
,
"a4a7dce"
,
"cf80f8d"
);
}
void
test_checkout_tree__checking_out_a_conflicting_content_change_returns_EMERGECONFLICT
(
void
)
{
/*
* c47800c adds a symlink named 'branch_file.txt'
* 5b5b025 is the parent of 763d71a
*/
assert_conflict
(
"branch_file.txt"
,
"hello
\n
"
,
"5b5b025"
,
"c47800c"
);
}
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