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
dd83e602
Commit
dd83e602
authored
Nov 07, 2014
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2692 from ethomson/bug2515
checkout_index: handle other stages
parents
64dc2485
2d24816b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
280 additions
and
64 deletions
+280
-64
src/checkout.c
+154
-51
tests/checkout/index.c
+39
-10
tests/checkout/tree.c
+87
-3
No files found.
src/checkout.c
View file @
dd83e602
This diff is collapsed.
Click to expand it.
tests/checkout/index.c
View file @
dd83e602
...
...
@@ -619,17 +619,14 @@ void test_checkout_index__can_get_repo_from_index(void)
git_index_free
(
index
);
}
static
void
add_conflict
(
void
)
static
void
add_conflict
(
git_index
*
index
,
const
char
*
path
)
{
git_index
*
index
;
git_index_entry
entry
;
memset
(
&
entry
,
0
,
sizeof
(
git_index_entry
));
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
entry
.
mode
=
0100644
;
entry
.
path
=
"conflicting.txt"
;
entry
.
path
=
path
;
git_oid_fromstr
(
&
entry
.
id
,
"d427e0b2e138501a3d15cc376077a3631e15bd46"
);
entry
.
flags
=
(
1
<<
GIT_IDXENTRY_STAGESHIFT
);
...
...
@@ -642,17 +639,19 @@ static void add_conflict(void)
git_oid_fromstr
(
&
entry
.
id
,
"2bd0a343aeef7a2cf0d158478966a6e587ff3863"
);
entry
.
flags
=
(
3
<<
GIT_IDXENTRY_STAGESHIFT
);
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
cl_git_pass
(
git_index_write
(
index
));
git_index_free
(
index
);
}
void
test_checkout_index__writes_conflict_file
(
void
)
{
git_index
*
index
;
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_buf
conflicting_buf
=
GIT_BUF_INIT
;
add_conflict
();
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
add_conflict
(
index
,
"conflicting.txt"
);
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
git_checkout_index
(
g_repo
,
NULL
,
&
opts
));
cl_git_pass
(
git_futils_readbuffer
(
&
conflicting_buf
,
"testrepo/conflicting.txt"
));
...
...
@@ -663,18 +662,46 @@ void test_checkout_index__writes_conflict_file(void)
"this file is changed in branch and master
\n
"
">>>>>>> theirs
\n
"
)
==
0
);
git_buf_free
(
&
conflicting_buf
);
git_index_free
(
index
);
}
void
test_checkout_index__adding_conflict_removes_stage_0
(
void
)
{
git_index
*
new_index
,
*
index
;
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
cl_git_pass
(
git_index_new
(
&
new_index
));
add_conflict
(
new_index
,
"new.txt"
);
cl_git_pass
(
git_checkout_index
(
g_repo
,
new_index
,
&
opts
));
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
cl_assert
(
git_index_get_bypath
(
index
,
"new.txt"
,
0
)
==
NULL
);
cl_assert
(
git_index_get_bypath
(
index
,
"new.txt"
,
1
)
!=
NULL
);
cl_assert
(
git_index_get_bypath
(
index
,
"new.txt"
,
2
)
!=
NULL
);
cl_assert
(
git_index_get_bypath
(
index
,
"new.txt"
,
3
)
!=
NULL
);
git_index_free
(
index
);
git_index_free
(
new_index
);
}
void
test_checkout_index__conflicts_honor_coreautocrlf
(
void
)
{
#ifdef GIT_WIN32
git_index
*
index
;
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_buf
conflicting_buf
=
GIT_BUF_INIT
;
cl_git_pass
(
p_unlink
(
"./testrepo/.gitattributes"
));
cl_repo_set_bool
(
g_repo
,
"core.autocrlf"
,
true
);
add_conflict
();
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
add_conflict
(
index
,
"conflicting.txt"
);
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
git_checkout_index
(
g_repo
,
NULL
,
&
opts
));
cl_git_pass
(
git_futils_readbuffer
(
&
conflicting_buf
,
"testrepo/conflicting.txt"
));
...
...
@@ -685,5 +712,7 @@ void test_checkout_index__conflicts_honor_coreautocrlf(void)
"this file is changed in branch and master
\r\n
"
">>>>>>> theirs
\r\n
"
)
==
0
);
git_buf_free
(
&
conflicting_buf
);
git_index_free
(
index
);
#endif
}
tests/checkout/tree.c
View file @
dd83e602
...
...
@@ -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