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

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() {
preprocess_patch "${NVIM_SOURCE_DIR}/${patch_file}"
msg_ok "Saved patch to '${NVIM_SOURCE_DIR}/${patch_file}'."
}
}
# shellcheck disable=SC2015
# ^ "Note that A && B || C is not if-then-else."
stage_patch() {
@ -277,16 +281,16 @@ stage_patch() {
local try_apply="${2:-}"
local nvim_remote
git_remote="$(find_git_remote)"
local checked_out_branch
nvim_remote="$(find_git_remote)"
local checked_out_branch
checked_out_branch="$(git rev-parse --abbrev-ref HEAD)"
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
else
printf '\nFetching "%s/master".\n' "${nvim_remote}"
output="$(git fetch "${git_remote}" master 2>&1)" &&
output="$(git fetch "${nvim_remote}" master 2>&1)" &&
msg_ok "${output}" ||
(msg_err "${output}"; false)
@ -362,13 +366,13 @@ submit_pr() {
exit 1
fi
cd "${NVIM_SOURCE_DIR}"
local checked_out_branch
cd "${NVIM_SOURCE_DIR}"
local checked_out_branch
checked_out_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "${checked_out_branch}" != ${BRANCH_PREFIX}* ]]; then
if [[ "${checked_out_branch}" != ${BRANCH_PREFIX}* ]]; then
msg_err "Current branch '${checked_out_branch}' doesn't seem to be a vim-patch branch."
exit 1
fi
fi
local nvim_remote
nvim_remote="$(find_git_remote)"
@ -376,8 +380,19 @@ submit_pr() {
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/: .*//')")
# shellcheck disable=SC2206
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.
pr_title="${pr_title// /,}" # Replace spaces with commas.
pr_title="$(printf 'vim-patch:%s' "${pr_title#,}")"
if [[ $push_first -ne 0 ]]; then
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)"