3

I'm trying to create a git alias to automate my PR merge and approval.

The complete git command is this:

git checkout master && git sync && git merge --no-ff -m 'Merged in hotfix/X-3144 (pull request #1112)' remotes/origin/hotfix/X-3144

Where X is the BitBucket prefix for the issue. Reading other stack overflow questions, I came up with this:

mergeto = "!f() { git checkout $1 && git sync && git merge --no-ff -m 'Merged in {$2}/B2B-{$3} (pull request #{$4})' remotes/origin/$2/X-$3;}; f "

So, naturally I'm using this to merge a PR that has conflicts. After I resolve these conflicts, I issue a git commit and git brings up nano with my previously typed commit message. My goal here is that the commit message is constructed using my parameters. So, for an example, if I use:

git mergeto master hotfix 123 1120

My final commit message was supposed to be "Merged in hotfix/X-123 (pull request #1120)" but instead I get a "Merged in {$2}/X-{$3} (pull request #{$4})"

How can I specify the parameters in such a way that this can work?

I Read a few stack over flow posts that show how to use a shell function inside a git alias, but couldn't find an example of escaping the text with parameters.

2
  • 2
    That is because you want to use variable expansion but using single quote. That is not gonna hold water. Commented Aug 14, 2019 at 0:55
  • 2
    Because parameter substitution does not happen in single quotes. Change them to double quotes and escape them with a backslash and you should be good. Commented Aug 14, 2019 at 0:56

1 Answer 1

4

Using John Szakmeister and eftshift0 suggestions, I got it working by escaping double quotes with backlash:

mergeto = "!f() { git checkout $1 && git sync && git merge --no-ff -m \"Merged in $2/B2B-$3 (pull request #$4)\" remotes/origin/$2/X-$3;}; f "

Thanks for your help!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.