gitnu 0.3.0

gitnu indexes your git status so you can use numbers instead of filenames.
Documentation
#!/usr/bin/env bash

GIT_USER=''
GIT_EMAIL=''
GIT_DEFAULT_BRANCH=''
GIT_STATUS_HINTS=''

gcf() {
  git config --global $@
}

get_git_config() {
  GIT_STATUS_HINTS=$(gcf advice.statusHints 2>&1)
  GIT_USER=$(gcf user.name 2>&1)
  GIT_EMAIL=$(gcf user.email 2>&1)
  GIT_DEFAULT_BRANCH=$(gcf init.defaultBranch 2>&1)
}

set_git_config() {
  [[ $GIT_USER == '' ]] && gcf user.name 'bot'
  [[ $GIT_EMAIL == '' ]] && gcf user.email 'bot@gitnu.co'
  [[ $GIT_DEFAULT_BRANCH == '' ]] && gcf init.defaultBranch 'main'
  gcf advice.statusHints false
}

reset_git_config() {
  ([ $GIT_USER ] && gcf user.name $GIT_USER) || gcf --unset user.name
  ([ $GIT_EMAIL ] && gcf user.email $GIT_EMAIL) || gcf --unset user.email
  ([ $GIT_DEFAULT_BRANCH ] && gcf init.defaultBranch $GIT_DEFAULT_BRANCH) ||
    gcf --unset init.defaultBranch
  ([ $GIT_STATUS_HINTS ] && gcf advice.statusHints $GIT_STATUS_HINTS) ||
    gcf --unset advice.statusHints
}

setup() {
  # navigate to where this script is located
  HERE=$PWD
  GITNU=$HERE/../target/debug/gitnu
  rm -rf failed && mkdir failed
  mkdir -p log
  get_git_config
  set_git_config
}

get_test_id() {
  local N=${1##*/} && printf ${N%%.*}
}

get_test_title() {
  local title="$(head -n 1 $1)" && printf "${title### }"
}

assert() {
  if [[ "$1" != "$2" ]]; then
    echo "expected: $1"
    echo "received: $2"
    exit 1
  fi
}

cleanup() {
  reset_git_config
  assert $PWD $HERE
  rm -rf $HERE/tmp
  rm -rf $HERE/failed
}

gitnu() { # gitnu
  $GITNU $@
}

# for use in ./cases/*.sh
# $1 is number of files to mock up
init() {
  git init
  let local i=1
  while [ $i -le $1 ]; do
    printf -v padded "%04d" $i
    touch "file_$padded" && let i++
  done
}

# for use in ./cases/*.sh
# evaluates command and sends to $REC_DIR
save() {
  eval "$@" >$REC_DIR/$N.txt
}

# $1 : test file
# $2 : test title
pass() {
  printf "\033[0;30m\033[1;42m PASS \033[1;0m $1 \033[0;37m$2\033[1;0m\n"
}

# $1 : test file
# $2 : test title
fail() {
  printf "\033[0;30m\033[1;41m FAIL \033[1;0m $1 \033[0;37m$2\033[1;0m\n"
}

# $1 : test file
# $2 : missing required file
not_found() {
  printf "\033[0;30m\033[1;41m FAIL \033[1;0m $1 \033[0;33m($2 not found)\033[1;0m\n"
}