2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Git で master に push する前に確認するフック書いた

Posted at

何番煎じだよって感じだけど、適当にググって出てきた奴はメッセージの出し方が個人的に気に入らなかったので自分で作った。

これを .git/hooks/pre-push において実行可能権限を付けると動く。

# !/bin/sh

set -Ceu

remote="${1}"
remote_url="${2}"

while IFS=' ' read -r local_ref local_sha remote_ref remote_sha
do
	if [ "${remote_ref}" != "refs/heads/master" ]
	then
		continue
	fi

	printf 'Pushing to remote "%s".\n' "${remote}" >&2
	printf 'Are you sure to push local "%s" to remote "master"? ' \
		"${local_ref#refs/heads/}" >&2
	head -n 1 /dev/tty | grep -iq '^y' || exit # return non-zero exit status
done
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?