Goal: get the output of git describe --tag=Foo --abbrev=0
into a Windows environment variable.
My attempt:
C:\Projects\Foo> FOR /F "tokens=* USEBACKQ" %F IN \
(`git describe HEAD --match "Foo*" --abbrev=0 --debug`) DO SET Var=%F
Result:
describe HEAD No exact match on refs or tags, searching to describe
finished search at d501f4f270405435692e5eb369fafbb53f0c74a2 annotated 463 Foo0.0-beta traversed 562 commits
describe 0 fatal: Not a valid object name 0
That's a weird fatal error. Without the FOR
, Git works:
git describe HEAD --match "Foo*" --abbrev=0 --debug
No exact match on refs or tags, searching to describe
finished search at d501f4f270405435692e5eb369fafbb53f0c74a2 annotated 463 Foo0.0-beta traversed 562 commits
Foo0.0-beta
Now the describe 0 fatal
can be traced back to the --abbrev=0
argument, but that's an essential argument. It seems that FOR
has broken the --abbrev=0
argument into two parts, which resulted in Git treating the 0
as a hash value, and trying to find a tag to describe that hash.
References: Getting the output of a command into a variable, Getting a tag name with git describe