[cmd_init] Now properly echoes out REPO_ID to database

[parser] Now properly catches bad git directory during "init" command
This commit is contained in:
ayakael 2018-07-02 07:06:53 -08:00
parent 53ab36c76d
commit 7954dc393e
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026
2 changed files with 6 additions and 4 deletions

View file

@ -18,9 +18,11 @@ cmd_init() {
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
[[ -f "${DB_FILE}" ]] && return 1
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
_msg EXEC "Initializing ${TARGET}"
echo -e "REPO_ID\t$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" > ${DB_FILE} 2>${STDERR}
[[ $? -ne 0 ]] && { _msg WARN; return 2; }
echo -e "REPO_VERSION\t${REPO_VERSION}" >> ${DB_FILE} 2>${STDERR}
[[ $? -ne 0 ]] && { _msg WARN; return 3; }
_msg OK
}

View file

@ -35,15 +35,15 @@ while true; do
shift
done
case "${1}" in
init)
shift
cmd_init "${GIT_DIR}" ${@}
EXIT=$?
[[ ${EXIT} -eq 1 ]] && echo "Database file already present"
[[ ${EXIT} -eq 2 ]] && echo "Init had errors"
[[ ${EXIT} -eq 3 ]] && echo "Init had errors"
[[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository"
;;
import)