Reputation: 283
Here is my post-merge hook script. Trying to do some cleanup/setup on post merge based on the currentBranch. Not getting the output i expect
# !/bin/bash
git branch --contains $2
curbranch1=$(git branch --contains $2)
echo $curbranch1
curbranch2=$(echo "$curbranch1"|grep "*")
echo $curbranch2
#output
Switched to branch 'develop'
* develop
NET SRC-Fiery-PF-PS VB6Dev bin develop
NET SRC-Fiery-PF-PS VB6Dev bin develop
Upvotes: 1
Views: 79
Reputation: 1326872
Try to assign a value to a variable without space around the equal sign:
currentBranch=$(git branch --contains $2)
NET SRC-Fiery-PF-PS VB6Dev bin develop <--Should match previous line?
It means the newline is not kept by default.
Try it in two steps:
currentBranch=$(git branch --contains $2)
currentBranch=$(echo "$currentBranch"|grep "*")
See also "How can I have a newline in a string in sh?"
Even in one step, it works:
#!/bin/sh
n=$(git branch --contains @|grep "*")
echo "$n"
Upvotes: 2