feat: keep track of empty commits; handle deleted files
This commit is contained in:
@ -70,13 +70,12 @@ do
|
||||
# There are malformed files names that are creating complex filenames to parse.
|
||||
# Those malformed filenames are double quotes, so to remove quotes, -c core.quotepath=false
|
||||
# and -z are used. sed 's/\x0//g' is removing the null byte
|
||||
FILES=$($GIT ${GIT_OPTS[@]} show --pretty= --name-only -z ${COMMIT_SHA} | sed 's/\x0//g')
|
||||
FILES=$($GIT ${GIT_OPTS[@]} show --pretty= --name-only -z ${COMMIT_SHA} | sed 's/\x0//g')
|
||||
|
||||
if test -z ${FILES}
|
||||
then
|
||||
# merge commit, etc. There is no file here.
|
||||
echo "No file was found in commit ${COMMIT_SHA}; skipping"
|
||||
continue
|
||||
echo "No file was found in commit ${COMMIT_SHA}"
|
||||
fi
|
||||
|
||||
TARGET_BACKUP_SHA=${DATA_DIR}/${COMMIT_SHA}
|
||||
@ -92,10 +91,25 @@ do
|
||||
echo "Writing ${TARGET_BACKUP_SHA}/${FILE}"
|
||||
fi
|
||||
|
||||
# ${FILE} contains path/to/file
|
||||
$GIT ${GIT_OPTS[@]} show ${COMMIT_SHA}:${FILE} > ${TARGET_BACKUP_SHA}/${FILE}
|
||||
# Retrieve file state (Added, Modified, Deleted)
|
||||
STATE=$(${GIT} ${GIT_OPTS[@]} show --name-status --pretty= ${COMMIT_SHA} | grep -E '^..${FILE}$' | cut -f1)
|
||||
|
||||
if test "${STATE}" != "D"
|
||||
then
|
||||
# ${FILE} contains path/to/file
|
||||
$GIT ${GIT_OPTS[@]} show ${COMMIT_SHA}:${FILE} > ${TARGET_BACKUP_SHA}/${FILE}
|
||||
else
|
||||
echo "Skipping ${FILE} as file was deleted in this commit"
|
||||
fi
|
||||
done
|
||||
|
||||
# if ${TARGET_BACKUP_SHA} is empty, keep track it was "backuped"
|
||||
if test -z "$(ls -A ${TARGET_BACKUP_SHA})"
|
||||
then
|
||||
echo "Folder ${TARGET_BACKUP_SHA} is empty. Marking it to keep as it in the backup"
|
||||
touch ${TARGET_BACKUP_SHA}/.gitkeep
|
||||
fi
|
||||
|
||||
NUM_ADDED=$((NUM_ADDED + 1))
|
||||
|
||||
if test ${NUM_ADDED} -eq ${MAX_NUM}
|
||||
|
Reference in New Issue
Block a user