text 用于git的Elixir预推钩 - 确保文件格式正确并且信条满足

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 用于git的Elixir预推钩 - 确保文件格式正确并且信条满足相关的知识,希望对你有一定的参考价值。

#!/bin/bash

ask() {
  # https://djm.me/ask
  local prompt default reply

  while true; do

    if [ "${2:-}" = "Y" ]; then
      prompt="Y/n"
      default=Y
    elif [ "${2:-}" = "N" ]; then
      prompt="y/N"
      default=N
    else
      prompt="y/n"
      default=
    fi

    # Ask the question (not using "read -p" as it uses stderr not stdout)
    echo -n "$1 [$prompt] "

    # Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
    read reply </dev/tty

    # Default?
    if [ -z "$reply" ]; then
      reply=$default
    fi

    # Check if the reply is valid
    case "$reply" in
      Y*|y*) return 0 ;;
      N*|n*) return 1 ;;
    esac

  done
}

format() {
  echo "> mix format --check-formatted"
  if mix format --check-formatted; then
    echo "Everything formatted ✓"
  else
    ask "Format now?" Y &&
      mix format &&
      git commit -am 'Format: Run `mix format` on codebase'
  fi
}

credo() {
  if ask "Run credo?" Y; then
    echo "> mix credo"
    mix credo
  fi
}

# Stash uncommited changes away, to ensure they don't interfere with the checks
old_stash=$(git rev-parse -q --verify refs/stash)
git stash push --keep-index --include-untracked --quiet
new_stash=$(git rev-parse -q --verify refs/stash)

EXIT_STATUS=0

format || EXIT_STATUS=$?
credo || EXIT_STATUS=$?

# Get uncommited changes back
[ "$old_stash" = "$new_stash" ] || git stash pop --index --quiet

if [ $EXIT_STATUS -ne 0 ]; then
  ask "Some commands failed, abort push?" Y && exit $EXIT_STATUS
fi

exit 0

以上是关于text 用于git的Elixir预推钩 - 确保文件格式正确并且信条满足的主要内容,如果未能解决你的问题,请参考以下文章

Git 预推钩子

简单Elixir游戏服务器-安装Elixir

寻找消息队列可用于nodejs和elixir [关闭]

简单Elixir游戏服设计-完善测试和代码改进

如何在 Elixir 主管中引用之前启动的进程

讲讲你的推免经历,准备预推免的关键要点都有哪些?