Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put last git commit id in an rpm

Tags:

git

rpm

rpmbuild

I would like to add the last "git commit id" to my rpms to have a foolproof way to track back the sources used to build a package.

I could use the rpm release tag, but this is already used for release numbers and dates in case of snapshots. I don't want to overload this any further.

Is there another tag or mechanism to store the last commit-id in an rpm?

like image 740
mirk Avatar asked May 22 '14 12:05

mirk


People also ask

How do you get commit ID of last commit in git?

To find a git commit id (or hash), you can simply use the git log command. This would show you the commit history, listing the commits in chronological order, with the latest commit first.

Where is the commit ID?

The commit ID is the 40 character long string after the word commit, you really can't miss it.

Which command will you use to find a commit ID in git?

The most basic and powerful tool to do this is the git log command. By default, with no arguments, git log lists the commits made in that repository in reverse chronological order; that is, the most recent commits show up first.


1 Answers

I'm not aware of anything in the Spec format specifically designed for this, but I do see a couple of options:

  • Use the version tag
    • You mentioned the release tag in your question, but this is for the package version, not the software version. A Git revision is much more like a software version than a package version.
    • For stable releases you can still use numeric tags like 1.0 if you want, but I'd advise you to make sure that this corresponds to a Git tag with the same name so your version will always be meaningful to Git.
    • Doing this means that you should probably also use the serial tag, so RPM can figure out how to order versions. (This may not be necessary if you tag properly and use the method below for determining your version.)
    • This will include the revision in the name of your package, or at least in the file name, and it sounds like you don't want that.
  • Name your source archive with the Git hash and then use a url tag like http://example.com/software/software-abcd123.zip.
    • You will not need to include the revision in your package file name using this method.

In the first case case (and possibly the second), it may be worthwhile to use git describe to determine your Git-aware version number, e.g.

$ git describe HEAD
1.0.0-3-gabcd123
'-.-' | |'--.--'
  |   | |   `---- Short Git hash
  |   | `-------- Indicates that a Git hash follows
  |   `---------- Three commits ahead of the previous tag name
  `-------------- The name of the base tag

Note that your RPM version cannot contain hyphens, so this version may have to be transcribed to something like 1.0.0_3_gabcd123.

like image 78
Chris Avatar answered Oct 06 '22 05:10

Chris