LoginSignup
0
0

More than 3 years have passed since last update.

git hook の pre-push を使おうとしてハマったこと

Posted at

問題

push前に入れたい動作があったのでpre-pushにスクリプトを書いてみた。
ブランチ名とハッシュが取りたい、どうやらreadで標準入力から取れるらしい
こんな感じで試してみる。

pre-push
#!/bin/bash

read local_ref local_sha1 remote_ref remote_sha1
echo "branch=${remote_ref##refs/heads/}"
echo "hash=$remote_sha1"
exit 0

これでpushすればブランチ名とハッシュが表示されるはず!

表示されない!!なんで!!!

解決

表示されるリポジトリもあればされないのもある、色々やってみたけど条件がわからない。
結局このSOの記事を見つけて解決しました。

up-to-dateなブランチで試してたんですが、
pushするものがないときは標準入力から取れないらしいです/(^o^)\

0
0
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
0
0