feat(vim-patch.sh): better detection of remote name #15846

This commit is contained in:
zeertzjq 2021-10-02 21:15:01 +08:00 committed by GitHub
parent 724ffe7095
commit a3b5b4a31e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,8 +125,12 @@ commit_message() {
}
find_git_remote() {
git_remote=$(git remote -v \
| awk '$2 ~ /github.com[:\/]neovim\/neovim/ && $3 == "(fetch)" {print $1; exit}')
local git_remote
if [[ "${1-}" == fork ]]; then
git_remote=$(git remote -v | awk '$2 !~ /github.com[:\/]neovim\/neovim/ && $3 == "(fetch)" {print $1; exit}')
else
git_remote=$(git remote -v | awk '$2 ~ /github.com[:\/]neovim\/neovim/ && $3 == "(fetch)" {print $1; exit}')
fi
if [[ -z "$git_remote" ]]; then
git_remote="origin"
fi
@ -268,8 +272,8 @@ stage_patch() {
get_vimpatch "$1"
local try_apply="${2:-}"
local git_remote
git_remote="$(find_git_remote)"
local nvim_remote
nvim_remote="$(find_git_remote)"
local checked_out_branch
checked_out_branch="$(git rev-parse --abbrev-ref HEAD)"
@ -277,16 +281,16 @@ stage_patch() {
msg_ok "Current branch '${checked_out_branch}' seems to be a vim-patch"
echo " branch; not creating a new branch."
else
printf '\nFetching "%s/master".\n' "${git_remote}"
output="$(git fetch "${git_remote}" master 2>&1)" &&
printf '\nFetching "%s/master".\n' "${nvim_remote}"
output="$(git fetch "${nvim_remote}" master 2>&1)" &&
msg_ok "${output}" ||
(msg_err "${output}"; false)
local nvim_branch="${BRANCH_PREFIX}${vim_version}"
echo
echo "Creating new branch '${nvim_branch}' based on '${git_remote}/master'."
echo "Creating new branch '${nvim_branch}' based on '${nvim_remote}/master'."
cd "${NVIM_SOURCE_DIR}"
output="$(git checkout -b "${nvim_branch}" "${git_remote}/master" 2>&1)" &&
output="$(git checkout -b "${nvim_branch}" "${nvim_remote}/master" 2>&1)" &&
msg_ok "${output}" ||
(msg_err "${output}"; false)
fi
@ -362,13 +366,13 @@ submit_pr() {
exit 1
fi
local git_remote
git_remote="$(find_git_remote)"
local nvim_remote
nvim_remote="$(find_git_remote)"
local pr_body
pr_body="$(git log --grep=vim-patch --reverse --format='#### %s%n%n%b%n' "${git_remote}"/master..HEAD)"
pr_body="$(git log --grep=vim-patch --reverse --format='#### %s%n%n%b%n' "${nvim_remote}"/master..HEAD)"
local patches
# Extract just the "vim-patch:X.Y.ZZZZ" or "vim-patch:sha" portion of each log
patches=("$(git log --grep=vim-patch --reverse --format='%s' "${git_remote}"/master..HEAD | sed 's/: .*//')")
patches=("$(git log --grep=vim-patch --reverse --format='%s' "${nvim_remote}"/master..HEAD | sed 's/: .*//')")
# shellcheck disable=SC2206
patches=(${patches[@]//vim-patch:}) # Remove 'vim-patch:' prefix for each item in array.
local pr_title="${patches[*]}" # Create space-separated string from array.
@ -376,8 +380,19 @@ submit_pr() {
pr_title="$(printf 'vim-patch:%s' "${pr_title#,}")"
if [[ $push_first -ne 0 ]]; then
echo "Pushing to 'origin/${checked_out_branch}'."
output="$(git push origin "${checked_out_branch}" 2>&1)" &&
local push_remote
push_remote="$(git config --get branch."${checked_out_branch}".pushRemote || true)"
if [[ -z "$push_remote" ]]; then
push_remote="$(git config --get remote.pushDefault || true)"
if [[ -z "$push_remote" ]]; then
push_remote="$(git config --get branch."${checked_out_branch}".remote || true)"
if [[ -z "$push_remote" ]] || [[ "$push_remote" == "$nvim_remote" ]]; then
push_remote="$(find_git_remote fork)"
fi
fi
fi
echo "Pushing to '${push_remote}/${checked_out_branch}'."
output="$(git push "${push_remote}" "${checked_out_branch}" 2>&1)" &&
msg_ok "${output}" ||
(msg_err "${output}"; false)