Fix local changes detection
Do not use diff as this only detects modified files, but not added ones. Run status --porcelain instead and check if there is any output.
This commit is contained in:
@@ -38,10 +38,9 @@ changes=$("${GIT_COMMAND[@]}" 2>&1)
|
|||||||
if [ -n "${changes}" ]; then
|
if [ -n "${changes}" ]; then
|
||||||
echo "[$(date +"%Y-%m-%d %H:%M:%S")] [${unique_id}] [START] git merge ${GIT_REPOSITORY_FOLDER} ${REMOTE_NAME}/${BRANCH}" &>> "$LOG_FILE";
|
echo "[$(date +"%Y-%m-%d %H:%M:%S")] [${unique_id}] [START] git merge ${GIT_REPOSITORY_FOLDER} ${REMOTE_NAME}/${BRANCH}" &>> "$LOG_FILE";
|
||||||
# check if there are local changes, make a backup branch and reset them
|
# check if there are local changes, make a backup branch and reset them
|
||||||
local_changes=$("${GIT_COMMAND_BASE[@]}" "-C" "${GIT_REPOSITORY_FOLDER}" "diff" "--quiet");
|
changes=$("${GIT_COMMAND_BASE[@]}" "-C" "${GIT_REPOSITORY_FOLDER}" "status" "--porcelain");
|
||||||
cached_changed=$("${GIT_COMMAND_BASE[@]}" "-C" "${GIT_REPOSITORY_FOLDER}" "diff" "--quiet" "--cached");
|
if [ -n "$changes" ]; then
|
||||||
if $local_changes || $cached_changed; then
|
echo "[$(date +"%Y-%m-%d %H:%M:%S")] [${unique_id}] [!] Changes detected, creating backup branch and resetting changes" &>> "$LOG_FILE";
|
||||||
echo "[$(date +"%Y-%m-%d %H:%M:%S")] [${unique_id}] [!] Local ($local_changes) or cached ($cached_changed) changes detected, creating backup branch and resetting changes" &>> "$LOG_FILE";
|
|
||||||
GIT_COMMAND=("${GIT_COMMAND_BASE[@]}" "-C" "${GIT_REPOSITORY_FOLDER}" "branch" "backup-$(date +%Y%m%d-%H%M%S)")
|
GIT_COMMAND=("${GIT_COMMAND_BASE[@]}" "-C" "${GIT_REPOSITORY_FOLDER}" "branch" "backup-$(date +%Y%m%d-%H%M%S)")
|
||||||
"${GIT_COMMAND[@]}";
|
"${GIT_COMMAND[@]}";
|
||||||
# Reset everything
|
# Reset everything
|
||||||
|
|||||||
Reference in New Issue
Block a user