2014-12-25 12:50:28 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
2015-07-22 08:00:17 -07:00
|
|
|
set -u
|
2014-12-25 12:50:28 -07:00
|
|
|
set -o pipefail
|
2014-11-21 06:39:35 -07:00
|
|
|
|
2015-03-05 19:49:03 -07:00
|
|
|
readonly NEOVIM_SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
2016-02-08 16:05:49 -07:00
|
|
|
readonly VIM_SOURCE_DIR_DEFAULT="${NEOVIM_SOURCE_DIR}/.vim-src"
|
2015-03-05 19:49:03 -07:00
|
|
|
readonly VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}"
|
|
|
|
readonly BASENAME="$(basename "${0}")"
|
2016-02-08 16:05:49 -07:00
|
|
|
readonly BRANCH_PREFIX="vim-"
|
2014-11-21 06:39:35 -07:00
|
|
|
|
2016-01-23 04:05:04 -07:00
|
|
|
CREATED_FILES=()
|
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
usage() {
|
2015-03-05 19:49:03 -07:00
|
|
|
echo "Helper script for porting Vim patches. For more information, see"
|
|
|
|
echo "https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim"
|
|
|
|
echo
|
2015-07-22 08:00:17 -07:00
|
|
|
echo "Usage: ${BASENAME} [-h | -l | -p vim-revision | -r pr-number]"
|
2015-03-05 19:49:03 -07:00
|
|
|
echo
|
|
|
|
echo "Options:"
|
2015-07-22 08:00:17 -07:00
|
|
|
echo " -h Show this message and exit."
|
|
|
|
echo " -l Show list of Vim patches missing from Neovim."
|
|
|
|
echo " -p {vim-revision} Download and apply the Vim patch vim-revision."
|
|
|
|
echo " vim-revision can be a version number of the "
|
2015-08-18 21:21:11 -07:00
|
|
|
echo " format '7.4.xxx' or a Git commit hash."
|
2016-01-23 13:45:21 -07:00
|
|
|
echo " -s Submit a vim-patch pull request to Neovim."
|
2015-07-22 08:00:17 -07:00
|
|
|
echo " -r {pr-number} Review a vim-patch pull request to Neovim."
|
2015-03-05 19:49:03 -07:00
|
|
|
echo
|
|
|
|
echo "Set VIM_SOURCE_DIR to change where Vim's sources are stored."
|
|
|
|
echo "The default is '${VIM_SOURCE_DIR_DEFAULT}'."
|
2015-01-07 12:52:10 -07:00
|
|
|
}
|
|
|
|
|
2015-07-22 08:00:17 -07:00
|
|
|
# Checks if a program is in the user's PATH, and is executable.
|
|
|
|
check_executable() {
|
2016-05-16 20:41:41 -07:00
|
|
|
test -x "$(command -v "${1}")"
|
|
|
|
}
|
|
|
|
|
|
|
|
require_executable() {
|
|
|
|
if ! check_executable "${1}"; then
|
2015-07-22 08:00:17 -07:00
|
|
|
>&2 echo "${BASENAME}: '${1}' not found in PATH or not executable."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-01-23 04:05:04 -07:00
|
|
|
clean_files() {
|
|
|
|
if [[ ${#CREATED_FILES[@]} -eq 0 ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Created files:"
|
|
|
|
local file
|
2016-05-11 15:09:39 -07:00
|
|
|
for file in "${CREATED_FILES[@]}"; do
|
2016-01-23 04:05:04 -07:00
|
|
|
echo " • ${file}"
|
|
|
|
done
|
|
|
|
|
|
|
|
read -p "Delete these files (Y/n)? " -n 1 -r reply
|
|
|
|
echo
|
|
|
|
if [[ "${reply}" =~ ^[Yy]$ ]]; then
|
2016-05-11 15:09:39 -07:00
|
|
|
rm -- "${CREATED_FILES[@]}"
|
2016-01-23 04:05:04 -07:00
|
|
|
else
|
|
|
|
echo "You can use 'git clean' to remove these files when you're done."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
get_vim_sources() {
|
2016-05-16 20:41:41 -07:00
|
|
|
require_executable git
|
2015-07-22 08:00:17 -07:00
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
if [[ ! -d ${VIM_SOURCE_DIR} ]]; then
|
|
|
|
echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'."
|
2016-04-08 10:54:50 -07:00
|
|
|
git clone https://github.com/vim/vim.git "${VIM_SOURCE_DIR}"
|
2016-01-08 17:12:36 -07:00
|
|
|
cd "${VIM_SOURCE_DIR}"
|
2015-01-07 12:52:10 -07:00
|
|
|
else
|
2015-08-18 21:21:11 -07:00
|
|
|
if [[ ! -d "${VIM_SOURCE_DIR}/.git" ]]; then
|
|
|
|
echo "✘ ${VIM_SOURCE_DIR} does not appear to be a git repository."
|
|
|
|
echo " Please remove it and try again."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-01-08 17:12:36 -07:00
|
|
|
cd "${VIM_SOURCE_DIR}"
|
2015-01-07 12:52:10 -07:00
|
|
|
echo "Updating Vim sources in '${VIM_SOURCE_DIR}'."
|
2015-08-18 21:21:11 -07:00
|
|
|
git pull &&
|
2015-01-07 12:52:10 -07:00
|
|
|
echo "✔ Updated Vim sources." ||
|
|
|
|
echo "✘ Could not update Vim sources; ignoring error."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-07-22 08:00:17 -07:00
|
|
|
commit_message() {
|
2015-12-17 19:02:20 -07:00
|
|
|
printf 'vim-patch:%s\n\n%s\n\n%s' "${vim_version}" \
|
|
|
|
"${vim_message}" "${vim_commit_url}"
|
2015-07-22 08:00:17 -07:00
|
|
|
}
|
|
|
|
|
2016-04-21 18:56:20 -07:00
|
|
|
find_git_remote() {
|
2016-04-24 04:49:00 -07:00
|
|
|
git remote -v \
|
|
|
|
| awk '$2 ~ /github.com[:/]neovim\/neovim/ && $3 == "(fetch)" {print $1}'
|
2016-04-21 18:56:20 -07:00
|
|
|
}
|
|
|
|
|
2015-07-22 08:00:17 -07:00
|
|
|
assign_commit_details() {
|
2015-03-05 19:49:03 -07:00
|
|
|
if [[ ${1} =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then
|
2015-08-25 23:07:31 -07:00
|
|
|
# Interpret parameter as version number (tag).
|
2015-01-07 12:52:10 -07:00
|
|
|
vim_version="${1}"
|
2015-08-25 23:07:31 -07:00
|
|
|
vim_tag="v${1}"
|
2016-01-23 04:05:04 -07:00
|
|
|
vim_commit=$(cd "${VIM_SOURCE_DIR}" \
|
2016-05-11 15:09:39 -07:00
|
|
|
&& git log -1 --format="%H" "${vim_tag}")
|
2015-07-22 08:00:17 -07:00
|
|
|
local strip_commit_line=true
|
2015-01-07 12:52:10 -07:00
|
|
|
else
|
|
|
|
# Interpret parameter as commit hash.
|
|
|
|
vim_version="${1:0:7}"
|
2016-01-23 04:05:04 -07:00
|
|
|
vim_commit=$(cd "${VIM_SOURCE_DIR}" \
|
2016-05-11 15:09:39 -07:00
|
|
|
&& git log -1 --format="%H" "${vim_version}")
|
2015-07-22 08:00:17 -07:00
|
|
|
local strip_commit_line=false
|
2015-01-07 12:52:10 -07:00
|
|
|
fi
|
2015-08-25 23:07:31 -07:00
|
|
|
|
|
|
|
vim_commit_url="https://github.com/vim/vim/commit/${vim_commit}"
|
2016-01-23 13:45:21 -07:00
|
|
|
vim_message="$(cd "${VIM_SOURCE_DIR}" \
|
2016-02-16 16:18:01 -07:00
|
|
|
&& git log -1 --pretty='format:%B' "${vim_commit}" \
|
|
|
|
| sed -e 's/\(#[0-9]*\)/vim\/vim\1/g')"
|
2015-07-22 08:00:17 -07:00
|
|
|
if [[ ${strip_commit_line} == "true" ]]; then
|
|
|
|
# Remove first line of commit message.
|
|
|
|
vim_message="$(echo "${vim_message}" | sed -e '1d')"
|
|
|
|
fi
|
2016-01-23 13:45:21 -07:00
|
|
|
patch_file="vim-${vim_version}.patch"
|
2015-07-22 08:00:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
get_vim_patch() {
|
|
|
|
get_vim_sources
|
|
|
|
|
|
|
|
assign_commit_details "${1}"
|
2015-01-07 12:52:10 -07:00
|
|
|
|
2015-08-25 23:07:31 -07:00
|
|
|
git log -1 "${vim_commit}" -- >/dev/null 2>&1 || {
|
2015-01-07 12:52:10 -07:00
|
|
|
>&2 echo "✘ Couldn't find Vim revision '${vim_commit}'."
|
|
|
|
exit 3
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
echo "✔ Found Vim revision '${vim_commit}'."
|
|
|
|
|
2015-12-17 19:02:20 -07:00
|
|
|
# Patch surgery: preprocess the patch.
|
|
|
|
# - transform src/ paths to src/nvim/
|
2016-05-11 15:09:39 -07:00
|
|
|
local vim_full
|
|
|
|
vim_full="$(git show -1 --pretty=medium "${vim_commit}" \
|
2015-12-17 19:02:20 -07:00
|
|
|
| LC_ALL=C sed -e 's/\( [ab]\/src\)/\1\/nvim/g')"
|
2016-02-08 16:05:49 -07:00
|
|
|
local neovim_branch="${BRANCH_PREFIX}${vim_version}"
|
2015-01-07 12:52:10 -07:00
|
|
|
|
2015-03-05 19:49:03 -07:00
|
|
|
cd "${NEOVIM_SOURCE_DIR}"
|
2016-05-11 15:09:39 -07:00
|
|
|
local git_remote
|
|
|
|
git_remote="$(find_git_remote)"
|
|
|
|
local checked_out_branch
|
|
|
|
checked_out_branch="$(git rev-parse --abbrev-ref HEAD)"
|
2016-04-21 18:56:20 -07:00
|
|
|
|
2016-02-08 16:05:49 -07:00
|
|
|
if [[ "${checked_out_branch}" == ${BRANCH_PREFIX}* ]]; then
|
|
|
|
echo "✔ Current branch '${checked_out_branch}' seems to be a vim-patch"
|
|
|
|
echo " branch; not creating a new branch."
|
|
|
|
else
|
|
|
|
echo
|
2016-04-21 18:56:20 -07:00
|
|
|
echo "Fetching '${git_remote}/master'."
|
|
|
|
output="$(git fetch "${git_remote}" master 2>&1)" &&
|
2016-02-08 16:05:49 -07:00
|
|
|
echo "✔ ${output}" ||
|
|
|
|
(echo "✘ ${output}"; false)
|
|
|
|
|
|
|
|
echo
|
2016-04-21 18:56:20 -07:00
|
|
|
echo "Creating new branch '${neovim_branch}' based on '${git_remote}/master'."
|
2016-02-08 16:05:49 -07:00
|
|
|
cd "${NEOVIM_SOURCE_DIR}"
|
2016-04-21 18:56:20 -07:00
|
|
|
output="$(git checkout -b "${neovim_branch}" "${git_remote}/master" 2>&1)" &&
|
2016-02-08 16:05:49 -07:00
|
|
|
echo "✔ ${output}" ||
|
|
|
|
(echo "✘ ${output}"; false)
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Creating empty commit with correct commit message."
|
|
|
|
output="$(commit_message | git commit --allow-empty --file 2>&1 -)" &&
|
2015-01-07 12:52:10 -07:00
|
|
|
echo "✔ ${output}" ||
|
|
|
|
(echo "✘ ${output}"; false)
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Creating files."
|
2016-01-23 13:45:21 -07:00
|
|
|
echo "${vim_full}" > "${NEOVIM_SOURCE_DIR}/${patch_file}"
|
|
|
|
echo "✔ Saved full commit details to '${NEOVIM_SOURCE_DIR}/${patch_file}'."
|
2015-01-07 12:52:10 -07:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Instructions:"
|
|
|
|
echo
|
|
|
|
echo " Proceed to port the patch."
|
2016-01-23 13:45:21 -07:00
|
|
|
echo " You might want to try 'patch -p1 < ${patch_file}' first."
|
2015-01-07 12:52:10 -07:00
|
|
|
echo
|
2016-02-08 16:05:49 -07:00
|
|
|
echo " If the patch contains a new test, consider porting it to Lua."
|
|
|
|
echo " You might want to try 'scripts/legacy2luatest.pl'."
|
|
|
|
echo
|
|
|
|
echo " Stage your changes ('git add ...') and use 'git commit --amend' to commit."
|
|
|
|
echo
|
|
|
|
echo " To port additional patches related to ${vim_version} and add them to the current"
|
|
|
|
echo " branch, call '${BASENAME} -p' again. Please use this only if it wouldn't make"
|
|
|
|
echo " sense to send in each patch individually, as it will increase the size of the"
|
|
|
|
echo " pull request and make it harder to review."
|
|
|
|
echo
|
|
|
|
echo " When you are finished, use '${BASENAME} -s' to submit a pull request."
|
2015-01-07 12:52:10 -07:00
|
|
|
echo
|
|
|
|
echo " See https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim"
|
|
|
|
echo " for more information."
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:53:56 -07:00
|
|
|
hub_pr() {
|
|
|
|
hub pull-request -m "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
git_hub_pr() {
|
|
|
|
git hub pull new -m "$1"
|
|
|
|
}
|
|
|
|
|
2016-01-23 13:45:21 -07:00
|
|
|
submit_pr() {
|
2016-05-16 20:41:41 -07:00
|
|
|
require_executable git
|
2016-05-16 20:53:56 -07:00
|
|
|
local push_first
|
|
|
|
push_first=1
|
|
|
|
local submit_fn
|
|
|
|
if check_executable hub; then
|
|
|
|
submit_fn="hub_pr"
|
|
|
|
elif check_executable git-hub; then
|
|
|
|
push_first=0
|
|
|
|
submit_fn="git_hub_pr"
|
|
|
|
else
|
|
|
|
>&2 echo "${BASENAME}: 'hub' or 'git-hub' not found in PATH or not executable."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-01-23 13:45:21 -07:00
|
|
|
|
|
|
|
cd "${NEOVIM_SOURCE_DIR}"
|
2016-05-11 15:09:39 -07:00
|
|
|
local checked_out_branch
|
|
|
|
checked_out_branch="$(git rev-parse --abbrev-ref HEAD)"
|
2016-02-08 16:05:49 -07:00
|
|
|
if [[ "${checked_out_branch}" != ${BRANCH_PREFIX}* ]]; then
|
|
|
|
echo "✘ Current branch '${checked_out_branch}' doesn't seem to be a vim-patch branch."
|
2016-01-23 13:45:21 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-05-11 15:09:39 -07:00
|
|
|
local git_remote
|
|
|
|
git_remote="$(find_git_remote)"
|
|
|
|
local pr_body
|
|
|
|
pr_body="$(git log --reverse --format='#### %s%n%n%b%n' "${git_remote}"/master..HEAD)"
|
|
|
|
local patches
|
|
|
|
patches=("$(git log --reverse --format='%s' "${git_remote}"/master..HEAD)")
|
2016-02-08 16:05:49 -07:00
|
|
|
patches=(${patches[@]//vim-patch:}) # Remove 'vim-patch:' prefix for each item in array.
|
2016-05-11 15:09:39 -07:00
|
|
|
local pr_title="${patches[*]}" # Create space-separated string from array.
|
2016-02-08 16:05:49 -07:00
|
|
|
pr_title="${pr_title// /,}" # Replace spaces with commas.
|
2016-01-23 13:45:21 -07:00
|
|
|
|
2016-05-11 15:09:39 -07:00
|
|
|
local pr_message
|
|
|
|
pr_message="$(printf '[RFC] vim-patch:%s\n\n%s\n' "${pr_title#,}" "${pr_body}")"
|
2016-01-23 13:45:21 -07:00
|
|
|
|
2016-05-16 20:53:56 -07:00
|
|
|
if [[ $push_first -ne 0 ]]; then
|
|
|
|
echo "Pushing to 'origin/${checked_out_branch}'."
|
|
|
|
output="$(git push origin "${checked_out_branch}" 2>&1)" &&
|
|
|
|
echo "✔ ${output}" ||
|
|
|
|
(echo "✘ ${output}"; git reset --soft HEAD^1; false)
|
|
|
|
|
|
|
|
echo
|
|
|
|
fi
|
2016-01-23 13:45:21 -07:00
|
|
|
|
|
|
|
echo "Creating pull request."
|
2016-05-16 20:53:56 -07:00
|
|
|
output="$(${submit_fn} "${pr_message}" 2>&1)" &&
|
2016-01-23 13:45:21 -07:00
|
|
|
echo "✔ ${output}" ||
|
|
|
|
(echo "✘ ${output}"; false)
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Cleaning up files."
|
2016-02-08 16:05:49 -07:00
|
|
|
local patch_file
|
2016-05-11 15:09:39 -07:00
|
|
|
for patch_file in "${patches[@]}"; do
|
2016-02-08 16:05:49 -07:00
|
|
|
patch_file="vim-${patch_file}.patch"
|
|
|
|
if [[ ! -f "${NEOVIM_SOURCE_DIR}/${patch_file}" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
rm -- "${NEOVIM_SOURCE_DIR}/${patch_file}"
|
|
|
|
echo "✔ Removed '${NEOVIM_SOURCE_DIR}/${patch_file}'."
|
|
|
|
done
|
2016-01-23 13:45:21 -07:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
list_vim_patches() {
|
2015-07-22 08:00:17 -07:00
|
|
|
get_vim_sources
|
|
|
|
|
2015-12-17 02:05:59 -07:00
|
|
|
printf "\nVim patches missing from Neovim:\n"
|
2015-01-07 12:52:10 -07:00
|
|
|
|
2016-01-19 03:32:14 -07:00
|
|
|
# Get commits since 7.4.602.
|
2016-05-11 15:09:39 -07:00
|
|
|
local vim_commits
|
|
|
|
vim_commits="$(cd "${VIM_SOURCE_DIR}" && git log --reverse --format='%H' v7.4.602..HEAD)"
|
2015-01-07 12:52:10 -07:00
|
|
|
|
|
|
|
local vim_commit
|
2016-01-19 03:32:14 -07:00
|
|
|
for vim_commit in ${vim_commits}; do
|
2015-01-07 12:52:10 -07:00
|
|
|
local is_missing
|
2016-05-11 15:09:39 -07:00
|
|
|
local vim_tag
|
2016-05-16 22:03:18 -07:00
|
|
|
# This fails for untagged commits (e.g., runtime file updates) so mask the return status
|
|
|
|
vim_tag="$(cd "${VIM_SOURCE_DIR}" && git describe --tags --exact-match "${vim_commit}" 2>/dev/null)" || true
|
2016-01-19 03:32:14 -07:00
|
|
|
if [[ -n "${vim_tag}" ]]; then
|
|
|
|
local patch_number="${vim_tag:5}" # Remove prefix like "v7.4."
|
2015-08-25 23:07:31 -07:00
|
|
|
# Tagged Vim patch, check version.c:
|
2015-03-05 19:49:03 -07:00
|
|
|
is_missing="$(sed -n '/static int included_patches/,/}/p' "${NEOVIM_SOURCE_DIR}/src/nvim/version.c" |
|
2016-04-08 10:54:50 -07:00
|
|
|
grep -x -e "[[:space:]]*//[[:space:]]${patch_number} NA.*" -e "[[:space:]]*${patch_number}," >/dev/null && echo "false" || echo "true")"
|
2016-01-19 03:32:14 -07:00
|
|
|
vim_commit="${vim_tag#v}"
|
2015-01-07 12:52:10 -07:00
|
|
|
else
|
2015-08-25 23:07:31 -07:00
|
|
|
# Untagged Vim patch (e.g. runtime updates), check the Neovim git log:
|
2015-03-05 19:49:03 -07:00
|
|
|
is_missing="$(cd "${NEOVIM_SOURCE_DIR}" &&
|
2015-12-17 02:05:59 -07:00
|
|
|
git log -1 --no-merges --grep="vim\-patch:${vim_commit:0:7}" --pretty=format:false)"
|
2015-01-07 12:52:10 -07:00
|
|
|
fi
|
|
|
|
|
2015-03-05 19:49:03 -07:00
|
|
|
if [[ ${is_missing} != "false" ]]; then
|
2015-01-07 12:52:10 -07:00
|
|
|
echo " • ${vim_commit}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Instructions:"
|
|
|
|
echo
|
|
|
|
echo " To port one of the above patches to Neovim, execute"
|
2016-01-23 13:45:21 -07:00
|
|
|
echo " this script with the patch revision as argument and"
|
|
|
|
echo " follow the instructions."
|
2015-01-07 12:52:10 -07:00
|
|
|
echo
|
2015-11-03 13:59:03 -07:00
|
|
|
echo " Examples: '${BASENAME} -p 7.4.487'"
|
|
|
|
echo " '${BASENAME} -p 1e8ebf870720e7b671f98f22d653009826304c4f'"
|
2016-01-19 03:32:14 -07:00
|
|
|
echo
|
|
|
|
echo " NOTE: Please port the _oldest_ patch if you possibly can."
|
|
|
|
echo " Out-of-order patches increase the possibility of bugs."
|
2015-01-07 12:52:10 -07:00
|
|
|
}
|
|
|
|
|
2016-01-23 04:05:04 -07:00
|
|
|
review_commit() {
|
2016-01-23 13:45:21 -07:00
|
|
|
local neovim_commit_url="${1}"
|
|
|
|
local neovim_patch_url="${neovim_commit_url}.patch"
|
2015-07-22 08:00:17 -07:00
|
|
|
|
|
|
|
local git_patch_prefix='Subject: \[PATCH\] '
|
2016-05-11 15:09:39 -07:00
|
|
|
local neovim_patch
|
|
|
|
neovim_patch="$(curl -Ssf "${neovim_patch_url}")"
|
|
|
|
local vim_version
|
|
|
|
vim_version="$(head -n 4 <<< "${neovim_patch}" | sed -n "s/${git_patch_prefix}vim-patch:\([a-z0-9.]*\)$/\1/p")"
|
2015-07-22 08:00:17 -07:00
|
|
|
|
2016-01-23 04:05:04 -07:00
|
|
|
echo
|
2015-07-22 08:00:17 -07:00
|
|
|
if [[ -n "${vim_version}" ]]; then
|
|
|
|
echo "✔ Detected Vim patch '${vim_version}'."
|
|
|
|
else
|
|
|
|
echo "✘ Could not detect the Vim patch number."
|
2016-02-08 16:05:49 -07:00
|
|
|
echo " This script assumes that the PR contains only commits"
|
|
|
|
echo " with 'vim-patch:XXX' in their title."
|
2015-07-22 08:00:17 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
assign_commit_details "${vim_version}"
|
|
|
|
|
2016-01-23 13:45:21 -07:00
|
|
|
local vim_patch_url="${vim_commit_url}.patch"
|
2016-01-23 12:56:47 -07:00
|
|
|
|
2016-05-11 15:09:39 -07:00
|
|
|
local expected_commit_message
|
|
|
|
expected_commit_message="$(commit_message)"
|
|
|
|
local message_length
|
|
|
|
message_length="$(wc -l <<< "${expected_commit_message}")"
|
|
|
|
local commit_message
|
|
|
|
commit_message="$(tail -n +4 <<< "${neovim_patch}" | head -n "${message_length}")"
|
2015-07-22 08:00:17 -07:00
|
|
|
if [[ "${commit_message#${git_patch_prefix}}" == "${expected_commit_message}" ]]; then
|
|
|
|
echo "✔ Found expected commit message."
|
|
|
|
else
|
|
|
|
echo "✘ Wrong commit message."
|
|
|
|
echo " Expected:"
|
|
|
|
echo "${expected_commit_message}"
|
|
|
|
echo " Actual:"
|
|
|
|
echo "${commit_message#${git_patch_prefix}}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Creating files."
|
2016-01-23 13:45:21 -07:00
|
|
|
echo "${neovim_patch}" > "${NEOVIM_SOURCE_DIR}/n${patch_file}"
|
|
|
|
echo "✔ Saved pull request diff to '${NEOVIM_SOURCE_DIR}/n${patch_file}'."
|
|
|
|
CREATED_FILES+=("${NEOVIM_SOURCE_DIR}/n${patch_file}")
|
2016-01-23 04:05:04 -07:00
|
|
|
|
2016-01-23 13:45:21 -07:00
|
|
|
curl -Ssfo "${NEOVIM_SOURCE_DIR}/${patch_file}" "${vim_patch_url}"
|
|
|
|
echo "✔ Saved Vim diff to '${NEOVIM_SOURCE_DIR}/${patch_file}'."
|
|
|
|
CREATED_FILES+=("${NEOVIM_SOURCE_DIR}/${patch_file}")
|
2015-07-22 08:00:17 -07:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Launching nvim."
|
2016-01-23 04:05:04 -07:00
|
|
|
nvim -c "cd ${NEOVIM_SOURCE_DIR}" \
|
2016-01-23 13:45:21 -07:00
|
|
|
-O "${NEOVIM_SOURCE_DIR}/${patch_file}" "${NEOVIM_SOURCE_DIR}/n${patch_file}"
|
2016-01-23 04:05:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
review_pr() {
|
2016-05-16 20:41:41 -07:00
|
|
|
require_executable curl
|
|
|
|
require_executable nvim
|
|
|
|
require_executable jq
|
2016-01-23 04:05:04 -07:00
|
|
|
|
|
|
|
get_vim_sources
|
|
|
|
|
|
|
|
local pr="${1}"
|
|
|
|
echo
|
|
|
|
echo "Downloading data for pull request #${pr}."
|
|
|
|
|
|
|
|
local pr_commit_urls=($(curl -Ssf "https://api.github.com/repos/neovim/neovim/pulls/${pr}/commits" \
|
|
|
|
| jq -r '.[].html_url'))
|
|
|
|
|
|
|
|
echo "Found ${#pr_commit_urls[@]} commit(s)."
|
|
|
|
|
|
|
|
local pr_commit_url
|
|
|
|
local reply
|
2016-05-11 15:09:39 -07:00
|
|
|
for pr_commit_url in "${pr_commit_urls[@]}"; do
|
2016-01-23 13:45:21 -07:00
|
|
|
review_commit "${pr_commit_url}"
|
2016-01-23 04:05:04 -07:00
|
|
|
if [[ "${pr_commit_url}" != "${pr_commit_urls[-1]}" ]]; then
|
|
|
|
read -p "Continue with next commit (Y/n)? " -n 1 -r reply
|
|
|
|
echo
|
|
|
|
if [[ ! "${reply}" =~ ^[Yy]$ ]]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
clean_files
|
2015-07-22 08:00:17 -07:00
|
|
|
}
|
|
|
|
|
2016-01-23 13:45:21 -07:00
|
|
|
while getopts "hlp:r:s" opt; do
|
2015-07-22 08:00:17 -07:00
|
|
|
case ${opt} in
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
l)
|
|
|
|
list_vim_patches
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
p)
|
|
|
|
get_vim_patch "${OPTARG}"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
r)
|
|
|
|
review_pr "${OPTARG}"
|
|
|
|
exit 0
|
|
|
|
;;
|
2016-01-23 13:45:21 -07:00
|
|
|
s)
|
|
|
|
submit_pr
|
|
|
|
exit 0
|
|
|
|
;;
|
2015-07-22 08:00:17 -07:00
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
usage
|
|
|
|
|
|
|
|
# vim: et sw=2
|