git-flow hooks and filters

The scripts git-flow runs around each action. Innesta runs them too, with git-flow's arguments, and without git-flow installed.

A repository can carry git-flow hooks: executables git-flow runs before and after its own commands — to run the tests before a release starts, say, or to announce one that has finished — and filters, which change a value on its way through. Innesta runs both, with the arguments git-flow passes, so a repository set up for git-flow behaves the same here.

git-flow itself does not have to be installed. Innesta runs GitFlow with plain git and never calls the git flow command: it runs the hooks itself.

Where they are looked for

In the folder gitflow.path.hooks names — relative to the top of the working tree, with ~ expanded — or, without that key, in Git’s own hooks folder: .git/hooks, or wherever core.hooksPath points, and in a linked worktree the main repository’s.

A hook is an executable file with git-flow’s name for it. Anything that is not executable is ignored, and a script without a #! line runs through /bin/sh, as Git runs its own hooks. Each one runs from the top of the working tree, with nothing on its standard input, and is stopped after fifteen minutes.

It runs with the environment Innesta gives Git, not your shell’s: a short list of variables such as HOME and SSH_AUTH_SOCK, and a PATH that adds ~/.local/bin, Homebrew’s folders and Xcode’s tools to the one Innesta was started with. A tool your shell profile adds to the PATH may not be on it, so a hook that needs one is safer naming it by its full path.

git-flow Hooks, in the repository’s GitFlow settings, shows the Folder Innesta looks in and the Hooks it found there, or None installed.

What runs, and with what

Each action has a hook before it, pre-flow-<action>, and one after it, post-flow-<action>:

Innesta action<action>$1$2$3$4
Start Featurefeature-startnameremotebranchstarting point
Push Featurefeature-publishnameremotebranch
Pull Featurefeature-pullnameremotebranch
Finish Feature…feature-finishnameremotebranch
Start Release, Start Hotfixrelease-start, hotfix-starttagremotebranchstarting point
Finish Release…, Finish Hotfix…release-finish, hotfix-finishtagremotebranch

The remote is the one Push Feature and Pull Feature use; for the other actions it is gitflow.origin, else the push remote, else origin.

Every hook also gets the environment variables git-flow AVH sets — MASTER_BRANCH, DEVELOP_BRANCH, ORIGIN, HOOKS_DIR, DOT_GIT_DIR, GIT_CURRENT_REPO_DIR — and the ones git-flow-next sets: BRANCH, BRANCH_NAME, BRANCH_TYPE, BASE_BRANCH, VERSION for a release or a hotfix, and EXIT_CODE=0 after the action. A script written for either version works unchanged.

The Start and Finish confirmations list the hooks and filters the action will run, under Hooks, so none of them runs unannounced.

When a hook fails

Before the action, a hook runs once you have confirmed and before anything changes. If it exits with anything but zero, the action stops there, and Innesta shows what the hook printed, with any credentials in a URL taken out. Nothing needs undoing.

After the action, a non-zero exit is only a warning: the action has already happened. For a finish, that is after the merges and the tag and before the branch is deleted, as git-flow AVH runs it.

When a finish renames the branch to the next free version, both of its hooks get the new tag as $1. The one before runs before the rename, so its $3 is the old branch name; the one after gets the new one.

Filters

A filter prints a value on its standard output, and Innesta uses it in place of its own.

  • filter-flow-release-start-version and filter-flow-hotfix-start-version get the version you typed, without the tag prefix, and print the one to use. They run once, while the Start confirmation prepares, so the sheet shows the final name and checks that one for collisions, and says The repository’s git-flow filter changed 1.5 to 1.5.0. A prefix you typed is put back. A non-zero exit, or nothing printed, stops the start.
  • filter-flow-release-finish-tag-message and filter-flow-hotfix-finish-tag-message get the tag’s message, Release <tag>, as $1 and the tag as $2 — git-flow AVH’s order; git-flow-next swaps them — and print the message to use. A non-zero exit stops the finish before it changes anything; nothing printed keeps the message. A finish with Don’t tag makes no tag, so they do not run and the confirmation does not list them.

What does not run

git-flow’s other filters, and the hooks of its bugfix, track, delete and rename commands, have no Innesta action to run them.