#!/bin/bash

# machete-status-branch hook is invoked by 'git machete status' for each managed branch (and branch name is passed as a parameter).
# Stdout of the hook is displayed at the end of line after custom annotation and remote sync-ness status.

# This particular example can be used for the git-machete repository itself (.git/hooks/machete-status-branch should link to ../../hook_samples/machete-status-branch),
# and prints the version string committed in git_machete/__init__.py on the given branch.

[ -n "$1" ] || { echo "usage: $(basename "$0") <branch-name>"; exit 1; }

set -e -o pipefail -u

function ansi_esc {
  [[ ${ASCII_ONLY-} = true ]] || echo -n "$1"
}
dim=$(ansi_esc '\033[2m')
endc=$(ansi_esc '\033[0m')

echo -ne "${dim}v$(git grep "__version__ = " "$1" -- git_machete/__init__.py | cut -d\' -f2 || echo '???')${endc}"
