From 90fb0a059938ac6cdf429914a13d9734f2d17266 Mon Sep 17 00:00:00 2001 From: Chris Pappas Date: Fri, 2 Feb 2024 15:58:13 -0500 Subject: [PATCH 1/4] feat: checkout 2u/main branch if envvar is set --- repo.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/repo.sh b/repo.sh index cc4d22ad7b..e3d0d67831 100755 --- a/repo.sh +++ b/repo.sh @@ -152,7 +152,10 @@ _checkout_and_update_branch () { GIT_SYMBOLIC_REF="$(git symbolic-ref HEAD 2>/dev/null)" BRANCH_NAME=${GIT_SYMBOLIC_REF##refs/heads/} - if [ -n "${OPENEDX_GIT_BRANCH}" ]; then + + if [ -n "${TWOU_CHECKOUT_BRANCH}" ]; then + CHECKOUT_BRANCH="${TWOU_CHECKOUT_BRANCH}" + elif [ -n "${OPENEDX_GIT_BRANCH}" ]; then CHECKOUT_BRANCH=${OPENEDX_GIT_BRANCH} else CHECKOUT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') From 90351eac9fe3638c7f501b369b060ff48aa2d228 Mon Sep 17 00:00:00 2001 From: Chris Pappas Date: Fri, 2 Feb 2024 16:52:09 -0500 Subject: [PATCH 2/4] fix: only checkout 2U branch name if 1) set 2) for a particular repo --- repo.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/repo.sh b/repo.sh index e3d0d67831..8f3602d809 100755 --- a/repo.sh +++ b/repo.sh @@ -75,6 +75,8 @@ non_release_ssh_repos=( "git@github.com:openedx/frontend-app-profile.git" "git@github.com:openedx/frontend-app-ora-grading.git" ) +# Space separated list of repos that use 2u specific branch +twou_main_repos="ecommerce yourownrepo" if [ -n "${OPENEDX_RELEASE}" ]; then OPENEDX_GIT_BRANCH=open-release/${OPENEDX_RELEASE} @@ -95,7 +97,7 @@ _checkout () # Results of the match are saved to an array called $BASH_REMATCH. [[ $repo =~ $name_pattern ]] name="${BASH_REMATCH[1]}" - + echo "$name" # If a directory exists and it is nonempty, assume the repo has been cloned. if [ -d "$name" ] && [ -n "$(ls -A "$name" 2>/dev/null)" ]; then cd "$name" @@ -133,11 +135,14 @@ _clone () _checkout_and_update_branch cd .. else - if [ -n "${OPENEDX_GIT_BRANCH:-}" ]; then + if [ -n "${TWOU_CHECKOUT_BRANCH}" ] && echo "${twou_main_repos}" | grep -o "${name}"; then + CLONE_BRANCH="-b ${TWOU_CHECKOUT_BRANCH}" + elif [ -n "${OPENEDX_GIT_BRANCH:-}" ]; then CLONE_BRANCH="-b ${OPENEDX_GIT_BRANCH}" else CLONE_BRANCH="" fi + echo "CLONE_BRANCH is ${CLONE_BRANCH}" if [ "${SHALLOW_CLONE}" == "1" ]; then git clone ${CLONE_BRANCH} -c core.symlinks=true --depth=1 "${repo}" else @@ -153,13 +158,14 @@ _checkout_and_update_branch () GIT_SYMBOLIC_REF="$(git symbolic-ref HEAD 2>/dev/null)" BRANCH_NAME=${GIT_SYMBOLIC_REF##refs/heads/} - if [ -n "${TWOU_CHECKOUT_BRANCH}" ]; then + if [ -n "${TWOU_CHECKOUT_BRANCH}" ] && echo "${twou_main_repos}" | grep -o "${name}"; then CHECKOUT_BRANCH="${TWOU_CHECKOUT_BRANCH}" elif [ -n "${OPENEDX_GIT_BRANCH}" ]; then CHECKOUT_BRANCH=${OPENEDX_GIT_BRANCH} else CHECKOUT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') fi + echo "Checking out branch ${CHECKOUT_BRANCH}" if [ "${BRANCH_NAME}" == "${CHECKOUT_BRANCH}" ]; then git pull origin ${CHECKOUT_BRANCH} From 6751341377c6457b9b5bb0baea8000782c589fdd Mon Sep 17 00:00:00 2001 From: Chris Pappas Date: Fri, 2 Feb 2024 17:06:17 -0500 Subject: [PATCH 3/4] fix: move 2u repos list out of code. added comments --- repo.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/repo.sh b/repo.sh index 8f3602d809..b98d99dcf0 100755 --- a/repo.sh +++ b/repo.sh @@ -75,8 +75,15 @@ non_release_ssh_repos=( "git@github.com:openedx/frontend-app-profile.git" "git@github.com:openedx/frontend-app-ora-grading.git" ) -# Space separated list of repos that use 2u specific branch -twou_main_repos="ecommerce yourownrepo" +# Space separated list of repos that use 2u specific branch should be +# set in your environment. example: +# export TWOU_MAIN_REPOS="ecommerce yourownrepo" +# +# If TWOU_MAIN_REPOS is set in the env, then TWOU_CHECKOUT_BRANCH must +# also be set. Here is an example of how to update your bashrc +# file, so that you can get these variables created (note, TWOU_MAIN_REPOS +# likely will grow over time, and not just use ecommerce'): +# $ echo -e "\nexport TWOU_CHECKOUT_BRANCH=\"2u/main\"\nexport TWOU_MAIN_REPOS=\"ecommerce yourownrepo\"" >> ~/.bash_profile if [ -n "${OPENEDX_RELEASE}" ]; then OPENEDX_GIT_BRANCH=open-release/${OPENEDX_RELEASE} @@ -135,14 +142,14 @@ _clone () _checkout_and_update_branch cd .. else - if [ -n "${TWOU_CHECKOUT_BRANCH}" ] && echo "${twou_main_repos}" | grep -o "${name}"; then + if [ -n "${TWOU_CHECKOUT_BRANCH}" ] && echo "${TWOU_MAIN_REPOS}" | grep -o "${name}"; then CLONE_BRANCH="-b ${TWOU_CHECKOUT_BRANCH}" elif [ -n "${OPENEDX_GIT_BRANCH:-}" ]; then CLONE_BRANCH="-b ${OPENEDX_GIT_BRANCH}" else CLONE_BRANCH="" fi - echo "CLONE_BRANCH is ${CLONE_BRANCH}" + if [ "${SHALLOW_CLONE}" == "1" ]; then git clone ${CLONE_BRANCH} -c core.symlinks=true --depth=1 "${repo}" else @@ -158,7 +165,7 @@ _checkout_and_update_branch () GIT_SYMBOLIC_REF="$(git symbolic-ref HEAD 2>/dev/null)" BRANCH_NAME=${GIT_SYMBOLIC_REF##refs/heads/} - if [ -n "${TWOU_CHECKOUT_BRANCH}" ] && echo "${twou_main_repos}" | grep -o "${name}"; then + if [ -n "${TWOU_CHECKOUT_BRANCH}" ] && echo "${TWOU_MAIN_REPOS}" | grep -o "${name}"; then CHECKOUT_BRANCH="${TWOU_CHECKOUT_BRANCH}" elif [ -n "${OPENEDX_GIT_BRANCH}" ]; then CHECKOUT_BRANCH=${OPENEDX_GIT_BRANCH} From b4aaf05d13b17b41006865bf16e9eda7b7b64732 Mon Sep 17 00:00:00 2001 From: Chris Pappas Date: Fri, 2 Feb 2024 17:07:00 -0500 Subject: [PATCH 4/4] chore: cleanup --- repo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo.sh b/repo.sh index b98d99dcf0..5739316df5 100755 --- a/repo.sh +++ b/repo.sh @@ -104,7 +104,7 @@ _checkout () # Results of the match are saved to an array called $BASH_REMATCH. [[ $repo =~ $name_pattern ]] name="${BASH_REMATCH[1]}" - echo "$name" + # If a directory exists and it is nonempty, assume the repo has been cloned. if [ -d "$name" ] && [ -n "$(ls -A "$name" 2>/dev/null)" ]; then cd "$name"