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
94e488a0
Commit
94e488a0
authored
Apr 24, 2016
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patch: differentiate not found and invalid patches
parent
17572f67
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
7 deletions
+77
-7
src/patch_parse.c
+2
-1
tests/patch/parse.c
+75
-6
No files found.
src/patch_parse.c
View file @
94e488a0
...
@@ -671,7 +671,8 @@ static int parse_patch_header(
...
@@ -671,7 +671,8 @@ static int parse_patch_header(
continue
;
continue
;
}
}
error
=
parse_err
(
"no header in patch file"
);
giterr_set
(
GITERR_PATCH
,
"no patch found"
);
error
=
GIT_ENOTFOUND
;
done:
done:
return
error
;
return
error
;
...
...
tests/patch/parse.c
View file @
94e488a0
...
@@ -4,16 +4,11 @@
...
@@ -4,16 +4,11 @@
#include "patch_common.h"
#include "patch_common.h"
void
test_patch_parse__original_to_change_middle
(
void
)
static
void
ensure_patch_validity
(
git_patch
*
patch
)
{
{
git_patch
*
patch
;
const
git_diff_delta
*
delta
;
const
git_diff_delta
*
delta
;
char
idstr
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
char
idstr
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
cl_git_pass
(
git_patch_from_buffer
(
&
patch
,
PATCH_ORIGINAL_TO_CHANGE_MIDDLE
,
strlen
(
PATCH_ORIGINAL_TO_CHANGE_MIDDLE
),
NULL
));
cl_assert
((
delta
=
git_patch_get_delta
(
patch
))
!=
NULL
);
cl_assert
((
delta
=
git_patch_get_delta
(
patch
))
!=
NULL
);
cl_assert_equal_i
(
2
,
delta
->
nfiles
);
cl_assert_equal_i
(
2
,
delta
->
nfiles
);
...
@@ -30,6 +25,80 @@ void test_patch_parse__original_to_change_middle(void)
...
@@ -30,6 +25,80 @@ void test_patch_parse__original_to_change_middle(void)
git_oid_nfmt
(
idstr
,
delta
->
new_file
.
id_abbrev
,
&
delta
->
new_file
.
id
);
git_oid_nfmt
(
idstr
,
delta
->
new_file
.
id_abbrev
,
&
delta
->
new_file
.
id
);
cl_assert_equal_s
(
idstr
,
"cd8fd12"
);
cl_assert_equal_s
(
idstr
,
"cd8fd12"
);
cl_assert_equal_i
(
0
,
delta
->
new_file
.
size
);
cl_assert_equal_i
(
0
,
delta
->
new_file
.
size
);
}
void
test_patch_parse__original_to_change_middle
(
void
)
{
git_patch
*
patch
;
cl_git_pass
(
git_patch_from_buffer
(
&
patch
,
PATCH_ORIGINAL_TO_CHANGE_MIDDLE
,
strlen
(
PATCH_ORIGINAL_TO_CHANGE_MIDDLE
),
NULL
));
ensure_patch_validity
(
patch
);
git_patch_free
(
patch
);
git_patch_free
(
patch
);
}
}
void
test_patch_parse__leading_and_trailing_garbage
(
void
)
{
git_patch
*
patch
;
const
char
*
leading
=
"This is some leading garbage.
\n
"
"Maybe it's email headers?
\n
"
"
\n
"
PATCH_ORIGINAL_TO_CHANGE_MIDDLE
;
const
char
*
trailing
=
PATCH_ORIGINAL_TO_CHANGE_MIDDLE
"
\n
"
"This is some trailing garbage.
\n
"
"Maybe it's an email signature?
\n
"
;
const
char
*
both
=
"Here's some leading garbage
\n
"
PATCH_ORIGINAL_TO_CHANGE_MIDDLE
"And here's some trailing.
\n
"
;
cl_git_pass
(
git_patch_from_buffer
(
&
patch
,
leading
,
strlen
(
leading
),
NULL
));
ensure_patch_validity
(
patch
);
git_patch_free
(
patch
);
cl_git_pass
(
git_patch_from_buffer
(
&
patch
,
trailing
,
strlen
(
trailing
),
NULL
));
ensure_patch_validity
(
patch
);
git_patch_free
(
patch
);
cl_git_pass
(
git_patch_from_buffer
(
&
patch
,
both
,
strlen
(
both
),
NULL
));
ensure_patch_validity
(
patch
);
git_patch_free
(
patch
);
}
void
test_patch_parse__nonpatches_fail_with_notfound
(
void
)
{
git_patch
*
patch
;
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_patch_from_buffer
(
&
patch
,
PATCH_NOT_A_PATCH
,
strlen
(
PATCH_NOT_A_PATCH
),
NULL
));
}
void
test_patch_parse__invalid_patches_fails
(
void
)
{
git_patch
*
patch
;
cl_git_fail_with
(
GIT_ERROR
,
git_patch_from_buffer
(
&
patch
,
PATCH_CORRUPT_GIT_HEADER
,
strlen
(
PATCH_CORRUPT_GIT_HEADER
),
NULL
));
cl_git_fail_with
(
GIT_ERROR
,
git_patch_from_buffer
(
&
patch
,
PATCH_CORRUPT_MISSING_NEW_FILE
,
strlen
(
PATCH_CORRUPT_MISSING_NEW_FILE
),
NULL
));
cl_git_fail_with
(
GIT_ERROR
,
git_patch_from_buffer
(
&
patch
,
PATCH_CORRUPT_MISSING_OLD_FILE
,
strlen
(
PATCH_CORRUPT_MISSING_OLD_FILE
),
NULL
));
cl_git_fail_with
(
GIT_ERROR
,
git_patch_from_buffer
(
&
patch
,
PATCH_CORRUPT_NO_CHANGES
,
strlen
(
PATCH_CORRUPT_NO_CHANGES
),
NULL
));
cl_git_fail_with
(
GIT_ERROR
,
git_patch_from_buffer
(
&
patch
,
PATCH_CORRUPT_MISSING_HUNK_HEADER
,
strlen
(
PATCH_CORRUPT_MISSING_HUNK_HEADER
),
NULL
));
}
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