Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 53c42c6

Browse files
feat: support main branch for repo script
docs: update comments refer to master chore: Update comments Co-authored-by: Tim McCormack <tmccormack@edx.org> chore: Update comments Co-authored-by: Tim McCormack <tmccormack@edx.org> chore: update requested change fix: If this is potentially unset, we should give it an empty default. Co-authored-by: Tim McCormack <tmccormack@edx.org> fix: update change directory fix: If this is potentially unset, we should give it an empty default. Co-authored-by: Tim McCormack <tmccormack@edx.org>
1 parent 16f6f8e commit 53c42c6

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ selfcheck: ## Check that the Makefile is free of Make syntax errors.
149149
# Developer interface: Repository management.
150150
########################################################################################
151151

152-
dev.reset-repos: ## Attempt to reset the local repo checkouts to the master working state.
152+
dev.reset-repos: ## Attempt to reset the local repo checkouts to the default branch working state.
153153
$(WINPTY) bash ./repo.sh reset
154154

155155
dev.status: ## Prints the status of all git repositories.
156156
$(WINPTY) bash ./repo.sh status
157157

158-
dev.checkout: ## Check out "openedx-release/$OPENEDX_RELEASE" in each repo if set, "master" otherwise.
158+
dev.checkout: ## Check out "openedx-release/$OPENEDX_RELEASE" in each repo if set, use default branch otherwise.
159159
./repo.sh checkout
160160

161161
dev.clone: dev.clone.ssh ## Clone service repos to the parent directory.
@@ -482,7 +482,7 @@ dev.static.%: ## Rebuild static assets for the specified service's container.
482482
########################################################################################
483483

484484

485-
dev.reset: dev.down dev.reset-repos dev.prune dev.pull.large-and-slow dev.up.large-and-slow dev.static dev.migrate ## Attempt to reset the local devstack to the master working state without destroying data.
485+
dev.reset: dev.down dev.reset-repos dev.prune dev.pull.large-and-slow dev.up.large-and-slow dev.static dev.migrate ## Attempt to reset the local devstack to the default branch working state without destroying data.
486486

487487
dev.destroy.coursegraph: dev.down.coursegraph ## Remove all coursegraph data.
488488
docker volume rm ${COMPOSE_PROJECT_NAME}_coursegraph_data

repo.sh

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ private_repos=(
8282
if [ -n "${OPENEDX_RELEASE}" ]; then
8383
OPENEDX_GIT_BRANCH=open-release/${OPENEDX_RELEASE}
8484
else
85-
OPENEDX_GIT_BRANCH=master
8685
repos+=("${non_release_repos[@]}")
8786
ssh_repos+=("${non_release_ssh_repos[@]}")
8887
fi
@@ -102,7 +101,6 @@ _checkout ()
102101

103102
# If a directory exists and it is nonempty, assume the repo has been cloned.
104103
if [ -d "$name" ] && [ -n "$(ls -A "$name" 2>/dev/null)" ]; then
105-
echo "Checking out branch ${OPENEDX_GIT_BRANCH} of $name"
106104
cd "$name"
107105
_checkout_and_update_branch
108106
cd ..
@@ -138,10 +136,15 @@ _clone ()
138136
_checkout_and_update_branch
139137
cd ..
140138
else
139+
if [ -n "${OPENEDX_GIT_BRANCH:-}" ]; then
140+
CLONE_BRANCH="-b ${OPENEDX_GIT_BRANCH}"
141+
else
142+
CLONE_BRANCH=""
143+
fi
141144
if [ "${SHALLOW_CLONE}" == "1" ]; then
142-
git clone -b ${OPENEDX_GIT_BRANCH} -c core.symlinks=true --depth=1 "${repo}"
145+
git clone ${CLONE_BRANCH} -c core.symlinks=true --depth=1 "${repo}"
143146
else
144-
git clone -b ${OPENEDX_GIT_BRANCH} -c core.symlinks=true "${repo}"
147+
git clone ${CLONE_BRANCH} -c core.symlinks=true "${repo}"
145148
fi
146149
fi
147150
done
@@ -152,11 +155,17 @@ _checkout_and_update_branch ()
152155
{
153156
GIT_SYMBOLIC_REF="$(git symbolic-ref HEAD 2>/dev/null)"
154157
BRANCH_NAME=${GIT_SYMBOLIC_REF##refs/heads/}
155-
if [ "${BRANCH_NAME}" == "${OPENEDX_GIT_BRANCH}" ]; then
156-
git pull origin ${OPENEDX_GIT_BRANCH}
158+
if [ -n "${OPENEDX_GIT_BRANCH}" ]; then
159+
CHECKOUT_BRANCH=${OPENEDX_GIT_BRANCH}
160+
else
161+
CHECKOUT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
162+
fi
163+
echo "Checking out branch ${CHECKOUT_BRANCH}"
164+
if [ "${BRANCH_NAME}" == "${CHECKOUT_BRANCH}" ]; then
165+
git pull origin ${CHECKOUT_BRANCH}
157166
else
158-
git fetch origin ${OPENEDX_GIT_BRANCH}:${OPENEDX_GIT_BRANCH}
159-
git checkout ${OPENEDX_GIT_BRANCH}
167+
git fetch origin ${CHECKOUT_BRANCH}:${CHECKOUT_BRANCH}
168+
git checkout ${CHECKOUT_BRANCH}
160169
fi
161170
find . -name '*.pyc' -not -path './.git/*' -delete
162171
}
@@ -178,7 +187,7 @@ clone_private ()
178187

179188
reset ()
180189
{
181-
read -p "This will switch to master and pull changes in your local git checkouts. Would you like to proceed? [y/n] " -r
190+
read -p "This will switch to the default branch and pull changes in your local git checkouts. Would you like to proceed? [y/n] " -r
182191
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
183192
echo "Cancelling."
184193
exit 1
@@ -190,8 +199,9 @@ reset ()
190199
name="${BASH_REMATCH[1]}"
191200

192201
if [ -d "$name" ]; then
202+
DEFAULT_BRANCH=$(cd ${name}; git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
193203
# Try to switch branch and pull, but fail if there are uncommitted changes.
194-
if (cd "$name"; git checkout -q master && git pull -q --ff-only);
204+
if (cd "$name"; git checkout -q ${DEFAULT_BRANCH} && git pull -q --ff-only);
195205
then
196206
# Echo untracked files to simplify debugging and make it easier to see that resetting does not remove everything
197207
untracked_files="$(cd ${name} && git ls-files --others --exclude-standard)"
@@ -202,7 +212,7 @@ reset ()
202212
fi
203213
else
204214
echo >&2 "Failed to reset $name repo. Exiting."
205-
echo >&2 "Please go to the repo and clean up any issues that are keeping 'git checkout master' and 'git pull' from working."
215+
echo >&2 "Please go to the repo and clean up any issues that are keeping 'git checkout $DEFAULT_BRANCH' and 'git pull' from working."
206216
exit 1
207217
fi
208218
else

0 commit comments

Comments
 (0)