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
ac7012a8
Commit
ac7012a8
authored
May 25, 2015
by
Edward Thomson
Committed by
Edward Thomson
Jun 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
binary diff: test index->workdir binary diffs
parent
6995b18a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
+99
-0
tests/diff/binary.c
+99
-0
No files found.
tests/diff/binary.c
View file @
ac7012a8
...
...
@@ -261,3 +261,102 @@ void test_diff_binary__delta_append(void)
git_index_free
(
index
);
}
void
test_diff_binary__index_to_workdir
(
void
)
{
git_index
*
index
;
git_diff
*
diff
;
git_patch
*
patch
;
git_buf
actual
=
GIT_BUF_INIT
;
git_diff_options
opts
=
GIT_DIFF_OPTIONS_INIT
;
const
char
*
expected
=
"diff --git a/untimely.txt b/untimely.txt
\n
"
\
"index 9a69d960ae94b060f56c2a8702545e2bb1abb935..1111d4f11f4b35bf6759e0fb714fe09731ef0840 100644
\n
"
\
"GIT binary patch
\n
"
\
"delta 32
\n
"
\
"nc%1vf+QYWt3zLL@hC)e3Vu?a>QDRl4f_G*?PG(-ZA}<#J$+QbW
\n
"
\
"
\n
"
\
"delta 7
\n
"
\
"Oc%18D`@*{63ljhg(E~C7
\n
"
;
opts
.
flags
=
GIT_DIFF_SHOW_BINARY
|
GIT_DIFF_FORCE_BINARY
;
opts
.
id_abbrev
=
GIT_OID_HEXSZ
;
repo
=
cl_git_sandbox_init
(
"renames"
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_append2file
(
"renames/untimely.txt"
,
"Oh that crazy Kipling!
\r\n
"
);
cl_git_pass
(
git_diff_index_to_workdir
(
&
diff
,
repo
,
index
,
&
opts
));
cl_git_pass
(
git_patch_from_diff
(
&
patch
,
diff
,
0
));
cl_git_pass
(
git_patch_to_buf
(
&
actual
,
patch
));
cl_assert_equal_s
(
expected
,
actual
.
ptr
);
cl_git_pass
(
git_index_add_bypath
(
index
,
"untimely.txt"
));
cl_git_pass
(
git_index_write
(
index
));
test_patch
(
"19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13"
,
NULL
,
&
opts
,
expected
);
git_buf_free
(
&
actual
);
git_patch_free
(
patch
);
git_diff_free
(
diff
);
git_index_free
(
index
);
}
static
int
print_cb
(
const
git_diff_delta
*
delta
,
const
git_diff_hunk
*
hunk
,
const
git_diff_line
*
line
,
void
*
payload
)
{
git_buf
*
buf
=
(
git_buf
*
)
payload
;
if
(
hunk
)
git_buf_put
(
buf
,
hunk
->
header
,
hunk
->
header_len
);
if
(
line
)
git_buf_put
(
buf
,
line
->
content
,
line
->
content_len
);
return
git_buf_oom
(
buf
)
?
-
1
:
0
;
}
void
test_diff_binary__print_patch_from_diff
(
void
)
{
git_index
*
index
;
git_diff
*
diff
;
git_buf
actual
=
GIT_BUF_INIT
;
git_diff_options
opts
=
GIT_DIFF_OPTIONS_INIT
;
const
char
*
expected
=
"diff --git a/untimely.txt b/untimely.txt
\n
"
\
"index 9a69d960ae94b060f56c2a8702545e2bb1abb935..1111d4f11f4b35bf6759e0fb714fe09731ef0840 100644
\n
"
\
"GIT binary patch
\n
"
\
"delta 32
\n
"
\
"nc%1vf+QYWt3zLL@hC)e3Vu?a>QDRl4f_G*?PG(-ZA}<#J$+QbW
\n
"
\
"
\n
"
\
"delta 7
\n
"
\
"Oc%18D`@*{63ljhg(E~C7
\n
"
;
opts
.
flags
=
GIT_DIFF_SHOW_BINARY
|
GIT_DIFF_FORCE_BINARY
;
opts
.
id_abbrev
=
GIT_OID_HEXSZ
;
repo
=
cl_git_sandbox_init
(
"renames"
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_append2file
(
"renames/untimely.txt"
,
"Oh that crazy Kipling!
\r\n
"
);
cl_git_pass
(
git_diff_index_to_workdir
(
&
diff
,
repo
,
index
,
&
opts
));
cl_git_pass
(
git_diff_print
(
diff
,
GIT_DIFF_FORMAT_PATCH
,
print_cb
,
&
actual
));
cl_assert_equal_s
(
expected
,
actual
.
ptr
);
git_buf_free
(
&
actual
);
git_diff_free
(
diff
);
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