I am using git diff command to get the file that changed between the last 2 commits and based on the action have to do different things with the files. So I have to extract the action on the file and the filename.
For a renamed file:
The result of git diff command is the below which is a renamed swagger file from swaggerA.json to swaggerB.json
R100 swaggerA.json swaggerB.json
This is my code:
$files=$(git diff HEAD~ HEAD --name-status)
$temp=$files -split ' '
echo $temp
echo $temp.Length
$name=$temp[1]
echo "this is $name file"
write-host $name
$output=$name.Split(' ')
$length=$output.Length
$output[0]
$output[1]
$output[$length-1]
The above script should’ve ideally split and provided 3 parts as:
1) R100
2) swaggerAjson
3) swaggerB.json
But it doesn’t do that in the Powershell task of Azure pipeline, and gives the whole string each time.
