From time to time, you might want to re-initialize rpmautospec in your RPM package’s (Dist)Git repo (rpmautospec is the tool that expands %autorelease and %autochangelog templates in specfiles).

The motivations for this step might be simple:

  • the tool is analyzing an excessively long Git history
  • you are attempting to handle shallow Git clones
  • you want to migrate the package from one DistGit to another (e.g., from Fedora to CentOS Stream)
  • you want to avoid executing Turing-Complete macros in Version or Epoch fields.

The principle

TL;DR: we need to prevent rpmautospec logic from analyzing beyond the last two Git commits. The tool behaves this way only when the very last commit (a) modifies the Version: and (b) changes the changelog file (the file with expanded %changelog).

This implies we need to make two precisely formatted commits.

Step-by-step guide

  1. (Re)generate the changelog file (do not ‘git add’ the file for now; this change belongs in the second commit):

    rpmautospec generate-changelog > changelog
    

    TODO: if we move from rpm to norpm, we need to use the full RPM parser one last time here; document how.

  2. Set a placeholder version, e.g., Version: 0.

    Do not worry; no builds are performed for the first commit. You might want to apply other changes here as well, such as dropping %lua macros from the Epoch if present.

  3. Remove the %autochangelog and %autorelease templates from the spec file. To keep things simple, you can just set Release: 0.

  4. Make the first commit (spec file changes only, keep the changelog file changes uncommitted!).

  5. Set the Version: field appropriately (think of Turing-Complete macros).

  6. Reintroduce the %autochangelog and %autorelease templates.

  7. Make the second commit. Include the changelog changes. If for any reason you need to start the Release from a non-standard number (e.g., 5), add the string [bump release: 5] to the commit message.

You are done! See also an example merge-request.

Double-check

Check that rpmautospec works by:

$ rpmautospec --debug process-distgit *spec *spec
===========================================================
Extracting linear history snippets from branched history...
===========================================================
commit 124279c: reenable autospec with Lua-free Version
Keep processing: commit 124279cc62be84852bb702f49fca5aaae0d93f6c
  epoch_version: 25.04.0.0.84
  child must continue: False
  changelog changed: True
  child changelog removed: None
  our changelog removed: False
  merge unresolvable: False
  spec file present: True
  child must continue (incoming): True
  child must continue (outgoing): False
  parent to follow: da9b55c
commit da9b55c: Disable rpmautospec for one commit
children_visitors_info[]['child_must_continue']: [False, False]
Only traversing: commit da9b55c3a6175643788eed8cbcf5475a574cf333
...

The second commit, da9b55c, was analyzed, resulting in False, False. This indicates there’s no need to analyze any older variants of the spec file.

$ git diff
+## START: Set by rpmautospec
+## (rpmautospec version 0.8.1)
+## RPMAUTOSPEC: autorelease, autochangelog
+%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
+    release_number = 5;
+    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
+    print(release_number + base_release_number - 1);
+}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
+## END: Set by rpmautospec
...
 %changelog
-%autochangelog
+## START: Generated by rpmautospec
+* Thu Jul 03 2025 Kamal Heib <kheib@redhat.com> - 25.04.0.0.84-1
+- Update to upstream 25.04.0-0.84
...

Please note the release_number = 5 line and the version-release of the last %changelog entry—that’s what we needed.

Now, use git checkout -p to drop the effects of process-distgit. Done.