シェルスクリプトを使用して、Gitリポジトリのマスターブランチがソースの背後にあることを確認します。

シェルスクリプトを使用して、Gitリポジトリのマスターブランチがソースの背後にあることを確認します。

私は現在、私のローカルマスターブランチがOrigin / Masterの背後にあることを発見したときに私のgitリポジトリをリベースするように思い出させるためにbashスクリプトを書いています。

これまで私は次のことを思いつきましたが、$?常に返されます1。 (空のdiffでもまだロードされるからだと思いますless

#!/bin/bash

REPO_PATH=$1
cd $REPO_PATH

# flow once inside repo
{
  git fetch
  git diff master origin/master
} &> /dev/null

if [ "" = $? ]
then
  echo "Empty"
  # logic to follow
else
  {
  git pull
  } &> /dev/null
  echo "Don't forget to rebase!!!"
  echo $REPO_PATH
fi

# check for changes to master
# If master is behind origin/master
# then pull master and notify me to rebase

# run this at the start of the day (this script should be run from my start_work
# script and should also be periodically run throughout the day. [maybe every
# time I'm about to run coverage/push?])

誰でもどんなアイデアがありますか?

ベストアンサー1

使用する必要がありますgit-merge-baseテスト--is-ancestor:

if git merge-base --is-ancestor origin/master master; then
    echo Empty
else
    echo "Don't forget to rebase!"
fi

おすすめ記事