function xxgit-merge () { _SCRIPT_NAME="xxgit-merge" _SCRIPT_VERSION="1.0" function log() { local _BRed='\e[1;31m' # Red local _BYellow='\e[1;33m' # Yellow local _BBlue='\e[1;34m' # Blue local _BWhite='\e[1;37m' # White local _NC="\e[m" # Color Reset local _message="$1" local _level="$2" local _nl="\n" _timestamp=$(date +%d.%m.%Y-%d:%H:%M:%S-%Z) case $(echo "$_level" | tr '[:upper:]' '[:lower:]') in "info" | "information") echo -ne "${_BWhite}[INFO][${_SCRIPT_NAME} ${_SCRIPT_VERSION}][${_timestamp}]: ${_message}${_NC}${_nl}" ;; "warn" | "warning") echo -ne "${_BYellow}[WARN][${_SCRIPT_NAME} ${_SCRIPT_VERSION}][${_timestamp}]: ${_message}${_NC}${_nl}" ;; "err" | "error") echo -ne "${_BRed}[ERR][${_SCRIPT_NAME} ${_SCRIPT_VERSION}][${_timestamp}]: ${_message}${_NC}${_nl}" ;; *) echo -ne "${_BBlue}[UNKNOWN][${_SCRIPT_NAME} ${_SCRIPT_VERSION}][${_timestamp}]: ${_message}${_NC}${_nl}" ;; esac } function show_help() { log "Usage:" "info" log "xxgit-merge {FROMBRANCH} {TOBRANCH}" "info" return 0 } _args="$#" case "$_args" in 0) show_help ;; 1) echo "1" log "Invalid number of parameters. Two are needed, only one provided." "err" return 1 ;; 2) _is_git=$(git rev-parse --is-inside-work-tree) if [ "$_is_git" != "true" ]; then log "This folder '$(pwd)' does not seem to be git repository." "err" return 1 fi log "Merging branch '$1' into '$2'" "info" ;; *) log "Invalid number of parameters. Two are needed." "err" return 1 ;; esac FROMBRANCH="$1" TOBRANCH="$2" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" log "Updating all branches..." "info" git remote update git fetch --all log "Checking out $TOBRANCH..." "info" git checkout "$TOBRANCH" log "Merging $TOBRANCH..." "info" git merge --no-ff --no-edit "$FROMBRANCH" LASTSTATUS=$? log "Status of 'git merge' was $LASTSTATUS" "info" if [ $LASTSTATUS -ne 0 ]; then log "The merge failed. Probbably there is an unresolved conflict." "err" return 1 fi git push git push --tags log "All done. Exiting..." "info" }