user3924036
user3924036

Reputation: 283

Git Post Merge Hook does not recognize valid commands

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

Answers (1)

VonC
VonC

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

Related Questions