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
9f664347
Commit
9f664347
authored
Nov 06, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkout_index: remove conflicts when checking out new files
parent
64dc2485
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
224 additions
and
51 deletions
+224
-51
src/checkout.c
+137
-48
tests/checkout/tree.c
+87
-3
No files found.
src/checkout.c
View file @
9f664347
This diff is collapsed.
Click to expand it.
tests/checkout/tree.c
View file @
9f664347
...
...
@@ -882,7 +882,7 @@ void test_checkout_tree__extremely_long_file_name(void)
cl_assert
(
!
git_path_exists
(
path
));
}
static
void
create_conflict
(
void
)
static
void
create_conflict
(
const
char
*
path
)
{
git_index
*
index
;
git_index_entry
entry
;
...
...
@@ -893,7 +893,7 @@ static void create_conflict(void)
entry
.
mode
=
0100644
;
entry
.
flags
=
1
<<
GIT_IDXENTRY_STAGESHIFT
;
git_oid_fromstr
(
&
entry
.
id
,
"d427e0b2e138501a3d15cc376077a3631e15bd46"
);
entry
.
path
=
"conflicts.txt"
;
entry
.
path
=
path
;
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
entry
.
flags
=
2
<<
GIT_IDXENTRY_STAGESHIFT
;
...
...
@@ -919,7 +919,7 @@ void test_checkout_tree__fails_when_conflicts_exist_in_index(void)
cl_git_pass
(
git_reference_name_to_id
(
&
oid
,
g_repo
,
"HEAD"
));
cl_git_pass
(
git_object_lookup
(
&
obj
,
g_repo
,
&
oid
,
GIT_OBJ_ANY
));
create_conflict
();
create_conflict
(
"conflicts.txt"
);
cl_git_fail
(
git_checkout_tree
(
g_repo
,
obj
,
&
opts
));
...
...
@@ -948,3 +948,87 @@ void test_checkout_tree__filemode_preserved_in_index(void)
git_commit_free
(
commit
);
git_index_free
(
index
);
}
void
test_checkout_tree__removes_conflicts
(
void
)
{
git_oid
commit_id
;
git_commit
*
commit
;
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_index
*
index
;
cl_git_pass
(
git_oid_fromstr
(
&
commit_id
,
"afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6"
));
cl_git_pass
(
git_commit_lookup
(
&
commit
,
g_repo
,
&
commit_id
));
opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
;
cl_git_pass
(
git_checkout_tree
(
g_repo
,
(
const
git_object
*
)
commit
,
&
opts
));
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
cl_git_pass
(
git_index_remove
(
index
,
"executable.txt"
,
0
));
create_conflict
(
"executable.txt"
);
cl_git_mkfile
(
"testrepo/executable.txt"
,
"This is the conflict file.
\n
"
);
create_conflict
(
"other.txt"
);
cl_git_mkfile
(
"testrepo/other.txt"
,
"This is another conflict file.
\n
"
);
git_index_write
(
index
);
cl_git_pass
(
git_checkout_tree
(
g_repo
,
(
const
git_object
*
)
commit
,
&
opts
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"executable.txt"
,
1
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"executable.txt"
,
2
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"executable.txt"
,
3
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"other.txt"
,
1
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"other.txt"
,
2
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"other.txt"
,
3
));
cl_assert
(
!
git_path_exists
(
"testrepo/other.txt"
));
git_index_free
(
index
);
}
void
test_checkout_tree__removes_conflicts_only_by_pathscope
(
void
)
{
git_oid
commit_id
;
git_commit
*
commit
;
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_index
*
index
;
const
char
*
path
=
"executable.txt"
;
cl_git_pass
(
git_oid_fromstr
(
&
commit_id
,
"afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6"
));
cl_git_pass
(
git_commit_lookup
(
&
commit
,
g_repo
,
&
commit_id
));
opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
;
opts
.
paths
.
count
=
1
;
opts
.
paths
.
strings
=
(
char
**
)
&
path
;
cl_git_pass
(
git_checkout_tree
(
g_repo
,
(
const
git_object
*
)
commit
,
&
opts
));
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
cl_git_pass
(
git_index_remove
(
index
,
"executable.txt"
,
0
));
create_conflict
(
"executable.txt"
);
cl_git_mkfile
(
"testrepo/executable.txt"
,
"This is the conflict file.
\n
"
);
create_conflict
(
"other.txt"
);
cl_git_mkfile
(
"testrepo/other.txt"
,
"This is another conflict file.
\n
"
);
git_index_write
(
index
);
cl_git_pass
(
git_checkout_tree
(
g_repo
,
(
const
git_object
*
)
commit
,
&
opts
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"executable.txt"
,
1
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"executable.txt"
,
2
));
cl_assert_equal_p
(
NULL
,
git_index_get_bypath
(
index
,
"executable.txt"
,
3
));
cl_assert
(
git_index_get_bypath
(
index
,
"other.txt"
,
1
)
!=
NULL
);
cl_assert
(
git_index_get_bypath
(
index
,
"other.txt"
,
2
)
!=
NULL
);
cl_assert
(
git_index_get_bypath
(
index
,
"other.txt"
,
3
)
!=
NULL
);
cl_assert
(
git_path_exists
(
"testrepo/other.txt"
));
git_index_free
(
index
);
}
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