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
bb815157
Commit
bb815157
authored
May 18, 2015
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
diff conflicts: add tests for tree to index
parent
7877146f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
2 deletions
+78
-2
tests/diff/diff_helpers.c
+1
-1
tests/diff/diff_helpers.h
+1
-1
tests/diff/index.c
+76
-0
No files found.
tests/diff/diff_helpers.c
View file @
bb815157
...
@@ -68,7 +68,7 @@ int diff_file_cb(
...
@@ -68,7 +68,7 @@ int diff_file_cb(
if
((
delta
->
flags
&
GIT_DIFF_FLAG_BINARY
)
!=
0
)
if
((
delta
->
flags
&
GIT_DIFF_FLAG_BINARY
)
!=
0
)
e
->
files_binary
++
;
e
->
files_binary
++
;
cl_assert
(
delta
->
status
<=
GIT_DELTA_
TYPECHANGE
);
cl_assert
(
delta
->
status
<=
GIT_DELTA_
CONFLICTED
);
e
->
file_status
[
delta
->
status
]
+=
1
;
e
->
file_status
[
delta
->
status
]
+=
1
;
...
...
tests/diff/diff_helpers.h
View file @
bb815157
...
@@ -8,7 +8,7 @@ typedef struct {
...
@@ -8,7 +8,7 @@ typedef struct {
int
files
;
int
files
;
int
files_binary
;
int
files_binary
;
int
file_status
[
1
0
];
/* indexed by git_delta_t value */
int
file_status
[
1
1
];
/* indexed by git_delta_t value */
int
hunks
;
int
hunks
;
int
hunk_new_lines
;
int
hunk_new_lines
;
...
...
tests/diff/index.c
View file @
bb815157
...
@@ -163,3 +163,79 @@ void test_diff_index__checks_options_version(void)
...
@@ -163,3 +163,79 @@ void test_diff_index__checks_options_version(void)
git_tree_free
(
a
);
git_tree_free
(
a
);
}
}
static
void
do_conflicted_diff
(
diff_expects
*
exp
,
unsigned
long
flags
)
{
const
char
*
a_commit
=
"26a125ee1bf"
;
/* the current HEAD */
git_tree
*
a
=
resolve_commit_oid_to_tree
(
g_repo
,
a_commit
);
git_diff_options
opts
=
GIT_DIFF_OPTIONS_INIT
;
git_index_entry
ancestor
=
{
0
},
ours
=
{
0
},
theirs
=
{
0
};
git_diff
*
diff
=
NULL
;
git_index
*
index
;
cl_assert
(
a
);
opts
.
context_lines
=
1
;
opts
.
interhunk_lines
=
1
;
opts
.
flags
|=
flags
;
memset
(
exp
,
0
,
sizeof
(
diff_expects
));
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
ancestor
.
path
=
ours
.
path
=
theirs
.
path
=
"staged_changes"
;
ancestor
.
mode
=
ours
.
mode
=
theirs
.
mode
=
0100644
;
git_oid_fromstr
(
&
ancestor
.
id
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
);
git_oid_fromstr
(
&
ours
.
id
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
);
git_oid_fromstr
(
&
theirs
.
id
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
);
cl_git_pass
(
git_index_conflict_add
(
index
,
&
ancestor
,
&
ours
,
&
theirs
));
cl_git_pass
(
git_diff_tree_to_index
(
&
diff
,
g_repo
,
a
,
index
,
&
opts
));
cl_git_pass
(
git_diff_foreach
(
diff
,
diff_file_cb
,
diff_hunk_cb
,
diff_line_cb
,
exp
));
git_diff_free
(
diff
);
git_tree_free
(
a
);
git_index_free
(
index
);
}
void
test_diff_index__reports_conflicts
(
void
)
{
diff_expects
exp
;
do_conflicted_diff
(
&
exp
,
0
);
cl_assert_equal_i
(
8
,
exp
.
files
);
cl_assert_equal_i
(
3
,
exp
.
file_status
[
GIT_DELTA_ADDED
]);
cl_assert_equal_i
(
2
,
exp
.
file_status
[
GIT_DELTA_DELETED
]);
cl_assert_equal_i
(
2
,
exp
.
file_status
[
GIT_DELTA_MODIFIED
]);
cl_assert_equal_i
(
1
,
exp
.
file_status
[
GIT_DELTA_CONFLICTED
]);
cl_assert_equal_i
(
7
,
exp
.
hunks
);
cl_assert_equal_i
(
9
,
exp
.
lines
);
cl_assert_equal_i
(
2
,
exp
.
line_ctxt
);
cl_assert_equal_i
(
5
,
exp
.
line_adds
);
cl_assert_equal_i
(
2
,
exp
.
line_dels
);
}
void
test_diff_index__reports_conflicts_when_reversed
(
void
)
{
diff_expects
exp
;
do_conflicted_diff
(
&
exp
,
GIT_DIFF_REVERSE
);
cl_assert_equal_i
(
8
,
exp
.
files
);
cl_assert_equal_i
(
2
,
exp
.
file_status
[
GIT_DELTA_ADDED
]);
cl_assert_equal_i
(
3
,
exp
.
file_status
[
GIT_DELTA_DELETED
]);
cl_assert_equal_i
(
2
,
exp
.
file_status
[
GIT_DELTA_MODIFIED
]);
cl_assert_equal_i
(
1
,
exp
.
file_status
[
GIT_DELTA_CONFLICTED
]);
cl_assert_equal_i
(
7
,
exp
.
hunks
);
cl_assert_equal_i
(
9
,
exp
.
lines
);
cl_assert_equal_i
(
2
,
exp
.
line_ctxt
);
cl_assert_equal_i
(
2
,
exp
.
line_adds
);
cl_assert_equal_i
(
5
,
exp
.
line_dels
);
}
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