#!/bin/bash
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
# Copyright [2016-2022] EMBL-European Bioinformatics Institute
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script is called when git is done merging the commits from remote to the local repository just after 'git pull'
# If the user had some local commits which have caused the merge to create a new unwanted merge-commit, this script warns the user about that.

bad_commit=$(git log -n1 --format="%s" | grep -E "Merge branch '.+' of .*github\.com.+" | wc -l | grep -v 0)
if [ -n "$bad_commit" ] ; then
  printf "\033[0;31mWARNING: Possible bad commit:\033[0m\n"
  git log -n1 --format="%C(yellow)%h%C(reset) %s"
fi
