How to set variable from git command output using windows cmd/batch -


i have trouble "forwarding" output variable. i'm using atlassian sourcetree git versioning. there want create custom action, can create zip file of modified files of 1 commit. created file should have formatted date of commit time in filename update-<yyyymmdd>t<hhmm>.zip.

my working batch-file far (line numbers later reference):

1:  setlocal enabledelayedexpansion 2:  set output= 3:  /f "delims=" %%a in ('git diff-tree --no-commit-id --name-only -r %1^^') ( set output=!output! "%%a" ) 4:  set hours= 5:  git show -s --format=%%ci %1 > tmptmptmp & set /p hours= < tmptmptmp & del tmptmptmp 6:  set hours=%hours:~0,4%%hours:~5,2%%hours:~8,2%t%hours:~11,2%%hours:~14,2% 7:  git archive -o update-%hours%.zip head %output% 8:  endlocal 

i'm having trouble rewrite line 5 (hours-line) avoid creating temporary file. if same in line 3 (output-line) like:

for /f "delims=" %%a in ('git show -s --format=%%ci %1^^') ( set hours=!hours! "%%a" ) 

i following error:

fatal: ambiguous argument '%ci': unknown revision or path not in working tree. use '--' separate paths revisions, this: git <command> [<revision>...] -- [<file>...]

i assume has needed %ci parameter (for formatting output).

can me this?

i not know why add trailing ^ caret (a circumflex accent) on same command used in line 5 git show -s --format=%%ci %1.

however, = equals sign in --format=%%ci should escaped follows:

for /f "delims=" %%a in ('git show -s --format^=%%ci %1^^') set hours=!hours! "%%a" 

a proof sample:

==>type 29803777.bat  if not [%1]==[] dir /b %1= /f "delims=" %%a in ('if not [%1]==[] dir /b %1=') @echo "%%a" /f "delims=" %%a in ('if not [%1]^=^=[] dir /b %1^=') @echo "%%a"  ==>29803777.bat x  ==>if not [x] == [] dir /b x= x.txt  ==>for /f "delims=" %a in ('if not [x] [] dir /b x ') @echo "%a" [] unexpected @ time.  ==>for /f "delims=" %a in ('if not [x]==[] dir /b x=') @echo "%a" "x.txt"  ==> 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -