34 lines
971 B
Bash
Executable File
34 lines
971 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# fetch and merge from a remote repositry
|
|
|
|
REPOSITORY="$1";
|
|
BRANCH="$2";
|
|
REMOTE="$3";
|
|
if [ -n "${REMOTE}" ]; then
|
|
REMOTE="origin"
|
|
fi;
|
|
# BASE_FOLDER="${HOME}/tmp/git-clone/";
|
|
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
|
# shellcheck source=init.sh
|
|
. "${BASE_FOLDER}init.sh";
|
|
|
|
# check that repository path exists
|
|
REPOSITORY_PATH="${GIT_REPOSITORY_FOLDER}${CLONE_BASE}${REPOSITORY}";
|
|
if [ ! -d "${REPOSITORY_PATH}$" ]; then
|
|
echo "${REPOSITORY} not found in clone folder";
|
|
exit;
|
|
fi;
|
|
LOG_FILE="${GIT_REPOSITORY_FOLDER}${LOG_FOLDER}${REPOSITORY}.log";
|
|
|
|
# fetch to null
|
|
${GIT_COMMAND} -C "${REPOSITORY_PATH}" fetch -q "${REMOTE}" "${BRANCH}";
|
|
changes=$(${GIT_COMMAND} -C "${REPOSITORY_PATH}" diff --stat HEAD "${REMOTE}"/"${BRANCH}");
|
|
if [ -n "${changes}" ]; then
|
|
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Changes" &>> "$LOG_FILE";
|
|
${GIT_COMMAND} -C "/${REPOSITORY_PATH}" merge "${REMOTE}"/"${BRANCH}"
|
|
echo "=[END]===>" &>> "$LOG_FILE";
|
|
fi;
|
|
|
|
# __END__
|