7
4

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 push origin master'禁止にする設定

Posted at

.zshrcに追記するだけ

function disable_git_push_origin_master() {
    if [[ $2 = "git push origin master" ]]; then 
        exit
    fi
}

autoload -Uz add-zsh-hook

add-zsh-hook preexec disable_git_push_origin_master

以後

git push origin master

とタイプすると、Terminal.appだと[Process completed]と出力され以後何もできなくなり、iTerm.appだとウィンドウが閉じる。

## gitのhooksを使うやり方

この辺は見送った。

  • repositoryごとに設定=>面等
  • グローバルに設定 => .zshrcでもいいのでは
  • 動かない既存repositoryがあった
    • ${remote_ref##refs/heads/}masterかどうかをチェックするのが、git hooksのキモなんだが、中身が空になってしまうrepositoryがあり、治し方わからんかった

##今後

  • 現状(寝ぼけてgit push origin masterは回避できてる)は一応満足
  • git hooks使うやり方をちゃんと動くようにする(どっちを使うかを選べれるようにする)
7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?