xnzac
xnzac

Reputation: 341

how to alias git flow hotfix finish [current_hotfix_branch]

git flow only allows one hotfix branch at any one time. So rather than typing:

git flow hotfix finish hotfix_branch

I'dl like to create an alias that uses the only existing hotfix branch name. Something like the following pseudocode:

[alias]
  fix-done = flow hotfix finish `git_fetch_branch_beginning_with_hotfix`

Can anyone help? Thanks.

Update: I'm using zsh.

Upvotes: 1

Views: 473

Answers (3)

Peter van der Does
Peter van der Does

Reputation: 14508

If you run git flow AVH Edition you can just do

$ git flow finish

when you are on the branch you want to finish. This works for hotfix, release, feature and bugfix.

To check if you run git flow AVH Edition

$ git flow version
x.xx.x (AVH Edition)

Upvotes: 1

krafts
krafts

Reputation: 168

Here is another way to do git flow hotfix finish alias:

hf = "!_() { b=$(git rev-parse --abbrev-ref HEAD) && git co master && git pl && git co develop && git pl && git co $b && git rebase master && h=$(echo $b | sed 's/hotfix\\///g') && git flow hotfix finish -m 'new_tag' $h && git co master && git ps && git co develop && git ps && git ps --tags && git poo $b && git br -D $b;  }; _"

Upvotes: 1

Stefan
Stefan

Reputation: 114248

This function is more or less extracted from git-flow's source code:

finish_current_hotfix_branch ()
{
  local hotfix_prefix=$(git config --get gitflow.prefix.hotfix)
  local hotfix_branches=$(echo "$(git branch --no-color | sed 's/^[* ] //')" | grep "^$hotfix_prefix")
  local first_branch=$(echo ${hotfix_branches} | head -n1)
  first_branch=${first_branch#$hotfix_prefix}
  git flow hotfix finish "$first_branch"
}

Update

It seems like you have to put the entire function in your alias. Not nice, but works:

[alias]
  fix-done ="!_() { p=$(git config --get gitflow.prefix.hotfix); b=$(echo \"$(git branch --no-color | sed 's/^[* ] //')\" | grep \"^$p\"); f=$(echo ${b} | head -n1); f=${f#$p}; git flow hotfix finish \"$f\"; }; _"

Upvotes: 1

Related Questions