Merge "fix several issues with branching tools"

This commit is contained in:
Zuul 2023-11-29 16:16:25 +00:00 committed by Gerrit Code Review
commit 39e1172e9b
4 changed files with 29 additions and 14 deletions

View File

@ -383,18 +383,19 @@ for subgit in $SUBGITS; do
remote_branch=$(git_repo_remote_branch)
if [ "${remote_branch}" == "" ]; then
remote_branch=$(git_remote_branch)
if [ "${remote_branch}" == "" ]; then
echo_stderr "ERROR: failed to determine remote branch in ${subgit}"
exit 1
fi
fi
extra_args=""
if [ "${remote_branch}" != "" ]; then
extra_args="-t ${remote}/${remote_branch}"
fi
# check if destination branch already exists
branch_check=$(git branch -a --list $branch)
if [ -z "$branch_check" ]; then
echo "Creating branch $branch in $subgit"
echo " git checkout -t ${remote}/${remote_branch} -b $branch"
git checkout -t ${remote}/${remote_branch} -b $branch
echo " git checkout ${extra_args} -b $branch"
git checkout ${extra_args} -b $branch
if [ $? != 0 ] ; then
echo_stderr "ERROR: failed to create branch '$branch' in ${subgit}"
exit 1

View File

@ -215,13 +215,17 @@ for subgit in $SUBGITS; do
exit 1
fi
review_method=$(git_repo_review_method)
if [ "${review_method}" == "" ]; then
echo_stderr "ERROR: Failed to determine review method in ${subgit}"
exit 1
if [ $BYPASS_GERRIT -eq 0 ]; then
review_method=$(git_repo_review_method)
if [ "${review_method}" == "" ]; then
echo_stderr "ERROR: Failed to determine review method in ${subgit}"
exit 1
fi
else
review_method='default'
fi
remote=$(git_remote)
remote=$(git_repo_remote)
if [ "${remote}" == "" ]; then
echo_stderr "ERROR: Failed to determine remote in ${manifest_dir}"
exit 1

View File

@ -24,6 +24,9 @@ source ${GIT_REPO_UTILS_DIR}/repo-utils.sh
source ${GIT_REPO_UTILS_DIR}/git-utils.sh
source ${GIT_REPO_UTILS_DIR}/url_utils.sh
git_remote_fp="git_repo_remote"
#
# git_repo_rel_dir [<dir>]:
# Return the relative directory of a git within a repo.

View File

@ -15,6 +15,10 @@ GIT_UTILS_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
source ${GIT_UTILS_DIR}/utils.sh
# pseudo function pointer for git_remote (fallback) or git_repo_remote (preferred)
if [ -z git_remote_fp ]; then
git_remote_fp="git_remote"
fi
git_ctx_root_dir () {
dirname "${MY_REPO}"
@ -427,6 +431,7 @@ git_local_branch () {
# This used to work on older git versions
result=$(git name-rev --name-only HEAD)
if [ "$result" == "" ] || [ "$result" == "undefined" ]; then
echo "HEAD"
return 1
fi
@ -436,6 +441,7 @@ git_local_branch () {
while git_is_tag $result; do
result=$(git name-rev --name-only $result^1 )
if [ "$result" == "" ] || [ "$result" == "undefined" ]; then
echo "HEAD"
return 1
fi
done
@ -447,6 +453,7 @@ git_list_remotes () {
git remote | grep -v gerrit
}
git_remote () {
local DIR="${1:-${PWD}}"
@ -455,7 +462,7 @@ git_remote () {
local_branch=$(git_local_branch) || return 1
# Return remote of current local branch, else default remote.
git config branch.${local_branch}.remote || git_list_remotes
git config branch.${local_branch}.remote || git_list_remotes | head -n 1
)
}
@ -473,13 +480,13 @@ git_remote_branch () {
# Our best bet is if the git config shows the local
# branch is tracking a remote branch.
local_branch=$(git_local_branch) || return 1
git config branch.${local_branch}.merge | sed 's#^refs/heads/##'
git config branch.${local_branch}.merge | grep -v '^refs/tags/' | sed 's#^refs/heads/##'
if [ ${PIPESTATUS[0]} -eq 0 ]; then
return 0
fi
# Before we can select a remote branch, we need to know which remote.
remote=$(git_remote)
remote=$($git_remote_fp)
if [ $? -ne 0 ] || [ "$remote" == "" ]; then
return 1
fi