{"thread":{"id":"58695","subject":"[PATCH] apply: Allow creating files with git patches","startedAt":"2022-10-26T08:32:18Z","lastAt":"2022-10-26T08:57:09Z","messageCount":2,"participants":["Michal Suchanek","Michal Suchánek"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"465757","messageId":"20221026083204.21333-1-msuchanek@suse.de","threadId":"58695","inReplyTo":null,"subject":"[PATCH] apply: Allow creating files with git patches","fromName":"Michal Suchanek","fromEmail":"msuchanek@suse.de","sentAt":"2022-10-26T08:32:04Z","receivedAt":"2022-10-26T08:32:18Z","isPatch":true,"sender":{"key":"msuchanek@suse.de","avatar":"https://avatars.githubusercontent.com/u/787652?v=4"},"body":"In git 2.38.0 it is not possible to create a file with apply when the diff\nlooks like git diff.\n\nIt either complains that the source file is not /dev/null or that it is\nnot the same as the destination.\n\nsomething.patch\nNo author found in something.patch\n---\nSometext\n\nAuthor: A. U. Thor <au@thor.com>\ngitdiff_verify_name: line: b/somefile.c\n@@ -0,0 +1,379 @@\n+/*\n...\n, isnull: 0, *name: somefile.c, side: 1, another: (null)\nerror: git apply: bad git-diff - inconsistent new filename on line 80\n\nsomething.patch\nNo author found in something.patch\n---\nSometext\n\nAuthor: A. U. Thor <au@thor.com>\ngitdiff_verify_name: line: a/somefile.c\n+++ b/somefile.c\n@@ -0,0 +1,379 @@\n+/*\n...\n, isnull: 1, *name: (null), side: 0\nerror: git apply: bad git-diff - expected /dev/null on line 80\n\nSigned-off-by: Michal Suchanek <msuchanek@suse.de>\n---\n apply.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/apply.c b/apply.c\nindex 2b7cd930ef..9dd01da271 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -928,7 +928,7 @@ static int gitdiff_verify_name(struct gitdiff_data *state,\n \t\t\treturn error(_(\"git apply: bad git-diff - expected /dev/null, got %s on line %d\"),\n \t\t\t\t     *name, state->linenr);\n \t\tanother = find_name(state->root, line, NULL, state->p_value, TERM_TAB);\n-\t\tif (!another || strcmp(another, *name)) {\n+\t\tif (another && strcmp(another, *name)) {\n \t\t\tfree(another);\n \t\t\treturn error((side == DIFF_NEW_NAME) ?\n \t\t\t    _(\"git apply: bad git-diff - inconsistent new filename on line %d\") :\n-- \n2.38.0\n\n"},{"id":"465759","messageId":"20221026085700.GC28810@kitsune.suse.cz","threadId":"58695","inReplyTo":"20221026083204.21333-1-msuchanek@suse.de","subject":"Re: [PATCH] apply: Allow creating files with git patches","fromName":"Michal Suchánek","fromEmail":"msuchanek@suse.de","sentAt":"2022-10-26T08:57:00Z","receivedAt":"2022-10-26T08:57:09Z","isPatch":true,"sender":{"key":"msuchanek@suse.de","avatar":"https://avatars.githubusercontent.com/u/787652?v=4"},"body":"Hello,\n\nlooking closer the patch really is malformed:\n\n--------- series --------\nnewfile.patch -p2\n----- newfile.patch -----\nPatch description\n\ndiff --git a/someproject/uselesss.c b/someproject/uselesss.c\nnew file mode 100644\n--- /dev/null\n+++ b/uselesss.c\n@@ -0,0 +1,3 @@\n+/*\n+ * This patch creates a useless file\n+ */\n-------------------------\n\nNot sure if it is desirable to handle better, and if there is even a\nbetter way.\n\nThanks\n\nMichal\n\n\nOn Wed, Oct 26, 2022 at 10:32:04AM +0200, Michal Suchanek wrote:\n> In git 2.38.0 it is not possible to create a file with apply when the diff\n> looks like git diff.\n> \n> It either complains that the source file is not /dev/null or that it is\n> not the same as the destination.\n> \n> something.patch\n> No author found in something.patch\n> ---\n> Sometext\n> \n> Author: A. U. Thor <au@thor.com>\n> gitdiff_verify_name: line: b/somefile.c\n> @@ -0,0 +1,379 @@\n> +/*\n> ...\n> , isnull: 0, *name: somefile.c, side: 1, another: (null)\n> error: git apply: bad git-diff - inconsistent new filename on line 80\n> \n> something.patch\n> No author found in something.patch\n> ---\n> Sometext\n> \n> Author: A. U. Thor <au@thor.com>\n> gitdiff_verify_name: line: a/somefile.c\n> +++ b/somefile.c\n> @@ -0,0 +1,379 @@\n> +/*\n> ...\n> , isnull: 1, *name: (null), side: 0\n> error: git apply: bad git-diff - expected /dev/null on line 80\n> \n> Signed-off-by: Michal Suchanek <msuchanek@suse.de>\n> ---\n>  apply.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/apply.c b/apply.c\n> index 2b7cd930ef..9dd01da271 100644\n> --- a/apply.c\n> +++ b/apply.c\n> @@ -928,7 +928,7 @@ static int gitdiff_verify_name(struct gitdiff_data *state,\n>  \t\t\treturn error(_(\"git apply: bad git-diff - expected /dev/null, got %s on line %d\"),\n>  \t\t\t\t     *name, state->linenr);\n>  \t\tanother = find_name(state->root, line, NULL, state->p_value, TERM_TAB);\n> -\t\tif (!another || strcmp(another, *name)) {\n> +\t\tif (another && strcmp(another, *name)) {\n>  \t\t\tfree(another);\n>  \t\t\treturn error((side == DIFF_NEW_NAME) ?\n>  \t\t\t    _(\"git apply: bad git-diff - inconsistent new filename on line %d\") :\n> -- \n> 2.38.0\n> \n"}]}