Patching within RPM spec file not working (previously applied patch detected)

I would like to know what the best way is to create a custom patch and apply it in a spec file.

I created the following patch.

--- neofetch.orig	2020-08-02 20:37:41.000000000 +0200
+++ neofetch	2021-10-06 21:42:20.251855166 +0200
@@ -6943,25 +6943,27 @@
         ;;
 
         "Fedora"* | "RFRemix"*)
-            set_colors 4 7 1
+            set_colors 12 7
             read -rd '' ascii_data <<'EOF'
-${c1}          /:-------------:\\
-       :-------------------::
-     :-----------${c2}/shhOHbmp${c1}---:\\
-   /-----------${c2}omMMMNNNMMD  ${c1}---:
-  :-----------${c2}sMMMMNMNMP${c1}.    ---:
- :-----------${c2}:MMMdP${c1}-------    ---\\
-,------------${c2}:MMMd${c1}--------    ---:
-:------------${c2}:MMMd${c1}-------    .---:
-:----    ${c2}oNMMMMMMMMMNho${c1}     .----:
-:--     .${c2}+shhhMMMmhhy++${c1}   .------/
-:-    -------${c2}:MMMd${c1}--------------:
-:-   --------${c2}/MMMd${c1}-------------;
-:-    ------${c2}/hMMMy${c1}------------:
-:--${c2} :dMNdhhdNMMNo${c1}------------;
-:---${c2}:sdNMMMMNds:${c1}------------:
-:------${c2}:://:${c1}-------------::
-:---------------------://
+${c1}             .',;::::;,'.
+         .';:cccccccccccc:;,.
+      .;cccccccccccccccccccccc;.
+    .:cccccccccccccccccccccccccc:.
+  .;ccccccccccccc;${c2}.:dddl:.${c1};ccccccc;.
+ .:ccccccccccccc;${c2}OWMKOOXMWd${c1};ccccccc:.
+.:ccccccccccccc;${c2}KMMc${c1};cc;${c2}xMMc${c1}:ccccccc:.
+,cccccccccccccc;${c2}MMM.${c1};cc;${c2};WW:${c1}:cccccccc,
+:cccccccccccccc;${c2}MMM.${c1};cccccccccccccccc:
+:ccccccc;${c2}oxOOOo${c1};${c2}MMM0OOk.${c1};cccccccccccc:
+cccccc:${c2}0MMKxdd:${c1};${c2}MMMkddc.${c1};cccccccccccc;
+ccccc:${c2}XM0'${c1};cccc;${c2}MMM.${c1};cccccccccccccccc'
+ccccc;${c2}MMo${c1};ccccc;${c2}MMW.${c1};ccccccccccccccc;
+ccccc;${c2}0MNc.${c1}ccc${c2}.xMMd${c1}:ccccccccccccccc;
+cccccc;${c2}dNMWXXXWM0:${c1}:cccccccccccccc:,
+cccccccc;${c2}.:odl:.${c1};cccccccccccccc:,.
+:cccccccccccccccccccccccccccc:'.
+.:cccccccccccccccccccccc:;,..
+  '::cccccccccccccc::;,.
 EOF
         ;;

I simply want to substitute the Fedora logo in this, with the new logo. But when I run this in the spec file, I get:

+ echo 'Patch #0 (fedora_logo.patch):'
Patch #0 (fedora_logo.patch):
+ /usr/bin/patch --no-backup-if-mismatch -p0 --fuzz=0
patching file neofetch
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file neofetch.rej
error: Bad exit status from /var/tmp/rpm-tmp.ZiaIC7 (%prep)

So obviously Iā€™m doing something wrong here. Maybe I create the patch not correctly? Any pointers are welcome.

What I did was:

  • Make a copy of the original neofetch file
  • Add the changes in the original file
  • Then I ran of the original file and the patched one diff -u neofetch.orig neofetch > fedora_logo.patch

Then in the spec file I have:
Patch0: fedora_logo.patch

And in %prep I have:
%patch0 -p0

Hello @keesdejong and welcome to the community.

It could be that the spec file has the %autosetup macro.
%autosetup is a replacement for %setup that handles patches directly without having to manually list them one by one.
So, try to remove the %patch0 -p0 line.

1 Like

Ah, of course. I should know that, thanks! :nerd_face:

1 Like