git ls-remote
では、リモートブランチを取得するコマンドであり、
これを使うとそもそもリモートブランチが存在する事を確認できる。
3.5 Git のブランチ機能 - リモートブランチ
githubのURLが本当に存在するかシェルスクリプトから確認する
例
$ REPOSITORY_URL="https://github.com/xxx/xxx"
$ git ls-remote ${REPOSITORY_URL}
XXXXXXXXXXXXXXXXXXXXXXXXX HEAD
XXXXXXXXXXXXXXXXXXXXXXXXX refs/heads/master
XXXXXXXXXXXXXXXXXXXXXXXXX refs/tags/1.4e
YYYYYYYYYYYYYYYYYYYYYYYYY refs/tags/v1.3
ZZZZZZZZZZZZZZZZZZZZZZZZZ refs/tags/v1.3b
ブランチ一覧から、確認したいブランチが存在するかを完全一致で確認すればよい。
例
$ REPOSITORY_URL="https://github.com/xxx/xxx"
$ TARGET_BRANCH="v1.3"
$ git ls-remote ${REPOSITORY_URL} | cut -f 2 | cut -d/ -f 3 | grep --line-regexp "${TARGET_BRANCH}"
v1.3
$ echo $?
0
# `echo $?`の結果、TARGET_BRANCHが存在していれば0(正常終了)
# 存在していなければ1となる。
何か他にもっといい方法があれば教えてほしい、、です。
参考
3.5 Git のブランチ機能 - リモートブランチ
githubのURLが本当に存在するかシェルスクリプトから確認する
Linux:grepコマンドで完全一致する行を表示する方法