Advertisement
BumbleBritches57

GitHash.bat

Nov 24th, 2020
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.08 KB | None | 0 0
  1. I'm writing a little batch script to create a C header containing the current git commit hash.
  2.  
  3. the bottom `echo CommitID_U >>Header` line is not working.
  4.  
  5. I'm trying to capitalize the hash, and then append the hash to a previously echo'd line without an interveneing newline, and despite trying to disable delayed expansion and reenable it and do every trick I can think of, nothing is working.
  6.  
  7. code:
  8.  
  9.     @ECHO OFF
  10.  
  11.     SETLOCAL EnableExtensions
  12.     SETLOCAL EnableDelayedExpansion
  13.  
  14.     SET Header=%~dp0..\Library\include\Private\CommitID.h
  15.  
  16.     echo !Header!
  17.  
  18.     echo|set /p="#define Version_CommitID " >!Header!
  19.  
  20.     FOR /F %%A IN ('git branch --show-current') DO SET GitBranch=%%A
  21.  
  22.     FOR /F %%A IN ('git rev-parse !GitBranch!') DO SET CommitID=%%A
  23.  
  24.     SET CommitID_U=!CommitID!
  25.     CALL :HexUpper CommitID_U
  26.     echo !CommitID_U!
  27.     GOTO:EOF
  28.  
  29.     :HexUpper
  30.     FOR %%i IN ("0=0" "1=1" "2=2" "3=3" "4=4" "5=5" "6=6" "7=7" "8=8" "9=9" "a=A" "b=B" "c=C" "d=D" "e=E" "f=F") DO CALL SET "%1=%%%1:%%~i%%"
  31.     GOTO:EOF
  32.  
  33.     echo !CommitID_U! >>!Header!
  34.  
  35.     ENDLOCAL
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement