Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute git command in Powershell

I'm trying to handle a git script in VSTS tasks with Powershell, but it's not working as expected.

What I'm doing is fetching latest commits messages after the latest tag to put inside a Release Notes, this is the base git command:

git log `git describe --tags --abbrev=0`..HEAD --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"

But Powershell doesn't accept this format, so I do the following:

$latestTag = git describe --tags --abbrev=0
$releaseNotes = git log $latestTag..HEAD --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"

It seems that when I put the variable $latestTag next to ..HEAD it breaks line, if I specify the tag eg. v1.2.9 instead of the variable it works well.

What can I do to make it run properly ? Thanks.

like image 658
Marcelo Formentão Avatar asked Oct 28 '25 14:10

Marcelo Formentão


2 Answers

You can enclose the expression $latestTag..HEAD in " marks, as

$latestTag = git describe --tags --abbrev=0
$releaseNotes = git log "$latestTag..HEAD" --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"

This has something to do with how PowerShell expands variables, but I don't use PS enough to really understand it.

like image 115
Mark Adelsberger Avatar answered Oct 31 '25 05:10

Mark Adelsberger


If you want to keep it on a single line you might be able to try the powershell syntax for embedding a comment with something like your original. Translating to powershell-friendly statements I think it would be something like

git log $(git describe --tags --abbrev=0)..HEAD --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"

This should resolve the expression inside $() and then insert that result as text to the git log command much like your original.

like image 45
No Refunds No Returns Avatar answered Oct 31 '25 05:10

No Refunds No Returns



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!