mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
vim-patch.sh: more colorful #8115
This commit is contained in:

committed by
Justin M. Keyes

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