0

I have a codebase which has been migrated from mercurial to git recently, yet its version detection has not been adopted yet.

While I know how to obtain each piece of information by a separate git command (git rev-parse HEAD, git status, git log) scraping their outputs. I wonder whether I can be more brief and get things as a nicely tab or space-separated list for easy digestion within python. I need

  • the commit's hash
  • whether it's an unmodified checkout
  • any tag associated with it (if any)
  • the time and date the commit was made

Basically I'm trying to created an an extended version of Get the current git hash in a Python script and need pointers to use more appropriated git commands than so far.

planetmaker
  • 5,884
  • 3
  • 28
  • 37

1 Answers1

2

You could just echo those commands together, something like:

 echo \
     $(git log -1 --pretty='%h "%cd"') \
     \"$(git tag --points-at HEAD)\" \
     $(git ls-files -m | wc -l)
alfunx
  • 3,080
  • 1
  • 12
  • 23
  • Thanks. Something similar I ended up doing. Actually running a separate command for each. Easier and especially saver with respect to different environments and catching things like no tags etc. https://github.com/OpenTTD/nml/pull/1 – planetmaker Oct 16 '18 at 17:29