0

I am using a .bat file to commit a project to git and github. I would like it to take one optional argument that is the username of the person calling the file. That will be passed in using the command line. Don't worry about that part, it works fine. The part that is not working is the git commit -m "%comment%" line. The ECHO %comment% line prints out what I would expect it to print, but then it's not being passed to the git comment. The text %comment% is the comment being passed in instead of Saved on Mon 10/11/2021-21:45:34.59 by makpo. What am I doing wrong?

@ECHO OFF

SET comment=Saved on %date%-%time%

IF "%~1"=="" GOTO COMMIT
SET username=%1
SET comment=%comment% by %username%

:COMMIT
ECHO %comment%
git checkout development
git add .
git commit -m "%comment%"
git push origin

GitHub enter image description here

NOTE: I also posted this on superuser, but I'm never really sure if that is the right place to ask these kinds of questions. Also, I feel like overflow has a lot more engagement.

ToMakPo
  • 855
  • 7
  • 27
  • You should generally not [cross-post](https://meta.stackexchange.com/q/64068)… – aschipfl Oct 12 '21 at 20:27
  • @aschipfl - "Ideally link to the question on the other site and explain what you hope to learn from asking another community." I did that. I linked to the other site and I explained why I posted it here also. – ToMakPo Oct 12 '21 at 20:31
  • Why dont you use commit-msg hook ? – Dmitry Oct 12 '21 at 21:11
  • When a line of code is read by the parser, it expands the value of the variable before the line of code is executed. What you are saying really isn't possible from a batch file with the code you are using. – Squashman Oct 13 '21 at 00:17
  • @Dmitry - I don't know what that is. I've never used it before. – ToMakPo Oct 13 '21 at 00:40
  • @Squashman - And yet, here we are. That is the code exactly as I have it and you can see the result. – ToMakPo Oct 13 '21 at 00:42
  • Remove `@ECHO OFF` from the top of your batch file. Open up a command prompt and run the batch file from there instead of executing it with your mouse. [Edit] your question with all the verbose output. – Squashman Oct 13 '21 at 00:44
  • @ToMakPo please have a look at : https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks you might find it extremely useful. search for commit-msg in your particular case – Dmitry Oct 14 '21 at 13:17

0 Answers0