Advertisement
depwl9992

makegitsha1.bat

Oct 11th, 2019 (edited)
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.89 KB | Source Code | 0 0
  1. @echo off
  2. set "file=%~dp0git_sha1.h"
  3. set "cmd=git rev-parse HEAD"
  4. set "cmd2=git show -s --format^=%%ci HEAD"
  5. set "cmd3=git rev-parse --short HEAD"
  6.  
  7. set "git_sha1_orig=#define GIT_SHA1"
  8. set "git_sha1=#define GIT_SHA1"
  9. set "git_date_orig=#define GIT_DATE"
  10. set "git_date=#define GIT_DATE"
  11. set "git_short1_orig=#define GIT_SHORT1"
  12. set "git_short1=#define GIT_SHORT1"
  13.  
  14. for /f "delims=" %%i in ('^"%cmd%^"') do set "git_sha1=%git_sha1% "%%i""
  15. for /f "delims=" %%i in ('^"%cmd2%^"') do set "git_date=%git_date% "%%i""
  16. set git_date_temp=%git_date: =%
  17. for /f "delims=" %%i in ('^"%cmd3%^"') do set "git_short1=%git_short1% "%%i""
  18.  
  19. (echo #ifndef git_sha1H
  20.  echo #define git_sha1H
  21.  if not "%git_sha1%"=="%git_sha1_orig%" echo %git_sha1%
  22.  if "%git_sha1%"=="%git_sha1_orig%" echo %git_sha1% "Git Hash Unavailable"
  23.  if not "%git_date_temp%"=="%git_date_orig%" echo %git_date%
  24.  if "%git_date_temp%"=="%git_date_orig%" echo %git_date% "%date%_%time: =0%"
  25.  if not "%git_short1%"=="%git_short1_orig%" echo %git_short1%
  26.  if "%git_short1%"=="%git_short1_orig%" echo %git_short1% "Git Short Hash Unavailable"
  27.  echo #define GERA "In memory of Georgi Piskunov, 03/06/2021"
  28.  echo #endif)>"%file%"
  29.  
  30. rem echo #ifndef git_sha1H > %file%
  31. rem echo #define git_sha1H >> %file%
  32. rem if not "%git_sha1%"=="%git_sha1_orig%" echo %git_sha1% >> %file%
  33. rem if "%git_sha1%"=="%git_sha1_orig%" echo %git_sha1% "Git Hash Unavailable" >> %file%
  34. rem if not "%git_date_temp%"=="%git_date_orig%" echo %git_date% >> %file%
  35. rem if "%git_date_temp%"=="%git_date_orig%" echo %git_date% "%date%_%time: =0%" >> %file%
  36. rem echo #endif >> %file%
  37.  
  38. rem from https://stackoverflow.com/questions/3814926/git-commit-date
  39.  
  40. rem And per my usual pattern, I've immediately figured it out because I can't leave it alone and let people answer.
  41.  
  42. rem I also needed to escape the carat in the format: `set cmd2=git show -s --format=^^=%%ci HEAD` works as expected.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement