vim-patch.sh: more colorful #8115

This commit is contained in:
Giuseppe
2018-03-08 12:58:16 +01:00
committed by Justin M. Keyes
parent 9cefd83cc7
commit d53aa0e94f

View File

@@ -36,6 +36,14 @@ usage() {
echo " (default: '${VIM_SOURCE_DIR_DEFAULT}')" echo " (default: '${VIM_SOURCE_DIR_DEFAULT}')"
} }
msg_ok() {
printf "\e[32m✔\e[0m $@\n"
}
msg_err() {
printf "\e[31m✘\e[0m $@\n"
}
# Checks if a program is in the user's PATH, and is executable. # Checks if a program is in the user's PATH, and is executable.
check_executable() { check_executable() {
test -x "$(command -v "${1}")" test -x "$(command -v "${1}")"
@@ -73,20 +81,20 @@ get_vim_sources() {
require_executable git require_executable git
if [[ ! -d ${VIM_SOURCE_DIR} ]]; then if [[ ! -d ${VIM_SOURCE_DIR} ]]; then
echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'." echo "Cloning Vim into: ${VIM_SOURCE_DIR}"
git clone https://github.com/vim/vim.git "${VIM_SOURCE_DIR}" git clone https://github.com/vim/vim.git "${VIM_SOURCE_DIR}"
cd "${VIM_SOURCE_DIR}" cd "${VIM_SOURCE_DIR}"
else else
if [[ ! -d "${VIM_SOURCE_DIR}/.git" ]]; then if [[ ! -d "${VIM_SOURCE_DIR}/.git" ]]; then
echo "${VIM_SOURCE_DIR} does not appear to be a git repository." msg_err "${VIM_SOURCE_DIR} does not appear to be a git repository."
echo " Please remove it and try again." echo " Please remove it and try again."
exit 1 exit 1
fi fi
cd "${VIM_SOURCE_DIR}" cd "${VIM_SOURCE_DIR}"
echo "Updating Vim sources in '${VIM_SOURCE_DIR}'." echo "Updating Vim sources: ${VIM_SOURCE_DIR}"
git pull && git pull &&
echo "Updated Vim sources." || msg_ok "Updated Vim sources." ||
echo "Could not update Vim sources; ignoring error." msg_err "Could not update Vim sources; ignoring error."
fi fi
} }
@@ -178,10 +186,10 @@ get_vimpatch() {
"$file" > "$file".tmp && mv "$file".tmp "$file" "$file" > "$file".tmp && mv "$file".tmp "$file"
} }
get_vimpatch() { get_vimpatch() {
get_vim_sources get_vim_sources
assign_commit_details "${1}" assign_commit_details "${1}"
git log -1 "${vim_commit}" -- >/dev/null 2>&1 || { git log -1 "${vim_commit}" -- >/dev/null 2>&1 || {
>&2 msg_err "Couldn't find Vim revision '${vim_commit}'." >&2 msg_err "Couldn't find Vim revision '${vim_commit}'."
@@ -194,7 +202,7 @@ get_vimpatch() {
cd "${NVIM_SOURCE_DIR}" cd "${NVIM_SOURCE_DIR}"
printf "Creating patch...\n" printf "Creating patch...\n"
echo "$patch_content" > "${NVIM_SOURCE_DIR}/${patch_file}" echo "$patch_content" > "${NVIM_SOURCE_DIR}/${patch_file}"
printf "Pre-processing patch...\n" printf "Pre-processing patch...\n"
@@ -207,31 +215,32 @@ stage_patch() {
get_vimpatch "$1" get_vimpatch "$1"
local try_apply="${2:-}" local try_apply="${2:-}"
local git_remote local git_remote
git_remote="$(find_git_remote)" git_remote="$(find_git_remote)"
local checked_out_branch local checked_out_branch
checked_out_branch="$(git rev-parse --abbrev-ref HEAD)" checked_out_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "${checked_out_branch}" == ${BRANCH_PREFIX}* ]]; then if [[ "${checked_out_branch}" == ${BRANCH_PREFIX}* ]]; then
echo "Current branch '${checked_out_branch}' seems to be a vim-patch" msg_ok "Current branch '${checked_out_branch}' seems to be a vim-patch"
echo " branch; not creating a new branch." echo " branch; not creating a new branch."
else else
printf "\nFetching '${git_remote}/master'.\n" printf "\nFetching '${git_remote}/master'.\n"
output="$(git fetch "${git_remote}" master 2>&1)" && output="$(git fetch "${git_remote}" master 2>&1)" &&
msg_ok "${output}" || msg_ok "${output}" ||
(msg_err "${output}"; false) (msg_err "${output}"; false)
local nvim_branch="${BRANCH_PREFIX}${vim_version}" local nvim_branch="${BRANCH_PREFIX}${vim_version}"
echo echo
echo "Creating new branch '${nvim_branch}' based on '${git_remote}/master'." echo "Creating new branch '${nvim_branch}' based on '${git_remote}/master'."
cd "${NVIM_SOURCE_DIR}" cd "${NVIM_SOURCE_DIR}"
output="$(git checkout -b "${nvim_branch}" "${git_remote}/master" 2>&1)" && output="$(git checkout -b "${nvim_branch}" "${git_remote}/master" 2>&1)" &&
echo "${output}" || msg_ok "${output}" ||
(echo "${output}"; false) (msg_err "${output}"; false)
fi fi
printf "\nCreating empty commit with correct commit message.\n" printf "\nCreating empty commit with correct commit message.\n"
output="$(commit_message | git commit --allow-empty --file 2>&1 -)" && output="$(commit_message | git commit --allow-empty --file 2>&1 -)" &&
msg_ok "${output}" ||
(msg_err "${output}"; false) (msg_err "${output}"; false)
if test -n "$try_apply" ; then if test -n "$try_apply" ; then
@@ -283,7 +292,7 @@ submit_pr() {
else else
>&2 echo "${BASENAME}: 'hub' or 'git-hub' not found in PATH or not executable." >&2 echo "${BASENAME}: 'hub' or 'git-hub' not found in PATH or not executable."
exit 1 exit 1
fi fi
cd "${NVIM_SOURCE_DIR}" cd "${NVIM_SOURCE_DIR}"
local checked_out_branch local checked_out_branch
@@ -304,16 +313,16 @@ submit_pr() {
local pr_title="${patches[*]}" # Create space-separated string from array. local pr_title="${patches[*]}" # Create space-separated string from array.
pr_title="${pr_title// /,}" # Replace spaces with commas. pr_title="${pr_title// /,}" # Replace spaces with commas.
local pr_message local pr_message
pr_message="$(printf '[RFC] vim-patch:%s\n\n%s\n' "${pr_title#,}" "${pr_body}")" pr_message="$(printf '[RFC] vim-patch:%s\n\n%s\n' "${pr_title#,}" "${pr_body}")"
if [[ $push_first -ne 0 ]]; then if [[ $push_first -ne 0 ]]; then
echo "Pushing to 'origin/${checked_out_branch}'." echo "Pushing to 'origin/${checked_out_branch}'."
output="$(git push origin "${checked_out_branch}" 2>&1)" && output="$(git push origin "${checked_out_branch}" 2>&1)" &&
msg_ok "${output}" || msg_ok "${output}" ||
(msg_err "${output}"; false) (msg_err "${output}"; false)
echo echo
fi fi
echo "Creating pull request." echo "Creating pull request."
@@ -324,7 +333,7 @@ submit_pr() {
echo echo
echo "Cleaning up files." echo "Cleaning up files."
local patch_file local patch_file
for patch_file in "${patches[@]}"; do for patch_file in "${patches[@]}"; do
patch_file="vim-${patch_file}.patch" patch_file="vim-${patch_file}.patch"
if [[ ! -f "${NVIM_SOURCE_DIR}/${patch_file}" ]]; then if [[ ! -f "${NVIM_SOURCE_DIR}/${patch_file}" ]]; then
continue continue
@@ -421,9 +430,9 @@ review_commit() {
local git_patch_prefix='Subject: \[PATCH\] ' local git_patch_prefix='Subject: \[PATCH\] '
local nvim_patch local nvim_patch
nvim_patch="$(curl -Ssf "${nvim_patch_url}")" nvim_patch="$(curl -Ssf "${nvim_patch_url}")"
local vim_version local vim_version
vim_version="$(head -n 4 <<< "${nvim_patch}" | sed -n "s/${git_patch_prefix}vim-patch:\([a-z0-9.]*\)$/\1/p")" vim_version="$(head -n 4 <<< "${nvim_patch}" | sed -n "s/${git_patch_prefix}vim-patch:\([a-z0-9.]*\)$/\1/p")"
echo echo
if [[ -n "${vim_version}" ]]; then if [[ -n "${vim_version}" ]]; then
@@ -446,9 +455,9 @@ review_commit() {
assign_commit_details "${vim_version}" assign_commit_details "${vim_version}"
local expected_commit_message local expected_commit_message
expected_commit_message="$(commit_message)" expected_commit_message="$(commit_message)"
local message_length local message_length
message_length="$(wc -l <<< "${expected_commit_message}")" message_length="$(wc -l <<< "${expected_commit_message}")"
local commit_message local commit_message
commit_message="$(tail -n +4 <<< "${nvim_patch}" | head -n "${message_length}")" commit_message="$(tail -n +4 <<< "${nvim_patch}" | head -n "${message_length}")"
if [[ "${commit_message#${git_patch_prefix}}" == "${expected_commit_message}" ]]; then if [[ "${commit_message#${git_patch_prefix}}" == "${expected_commit_message}" ]]; then
@@ -458,7 +467,7 @@ review_commit() {
echo " Expected:" echo " Expected:"
echo "${expected_commit_message}" echo "${expected_commit_message}"
echo " Actual:" echo " Actual:"
echo "${commit_message#${git_patch_prefix}}" echo "${commit_message#${git_patch_prefix}}"
fi fi
echo echo