Keeping your public repository up-to-date script

Keeping your public repository up-to-date script

Leon Stringer -
Кількість відповідей: 5
Фото Core developers Фото Particularly helpful Moodlers

When preparing patches for Moodle I use the script in the docs to keep my GitHub repo up-to-date with upstream:

   git fetch upstream
   for BRANCH in MOODLE_{19..39}_STABLE master; do
       git push origin refs/remotes/upstream/$BRANCH:refs/heads/$BRANCH
   done

That's until I tried to add 3.10 which tried to update the 269 branches from MOODLE_40_STABLE to MOODLE_309_STABLE. Obviously Bash' integer brace expansion {19..310} won't cope with this change in the version numbering scheme.

I'm proposing changing this to:

git fetch upstream

branches=("19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" \
        "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "310")
branches=("${branches[@]/#/MOODLE_}")
branches=("${branches[@]/%/_STABLE}")

for BRANCH in "${branches[@]}" master; do
        git push origin refs/remotes/upstream/$BRANCH:refs/heads/$BRANCH
done

I'm hoping for feedback on this before updating the script in the docs. It seems to do the job correctly but maybe someone has a better approach?

У відповідь на Leon Stringer

Re: Keeping your public repository up-to-date script

Visvanath Ratnaweera -
Фото Particularly helpful Moodlers Фото Translators
This warning https://moodle.org/mod/forum/discuss.php?d=409005 came up yesterday in the German community. In short "310" is not "3.10"!
У відповідь на Leon Stringer

Re: Keeping your public repository up-to-date script

David Mudrák -
Фото Core developers Фото Documentation writers Фото Moodle HQ Фото Particularly helpful Moodlers Фото Peer reviewers Фото Plugin developers Фото Plugins guardians Фото Testers Фото Translators

Thank you Leon for updating the docs.

I still think that something like

for BRANCH in MOODLE_{19..39}_STABLE MOODLE_310_STABLE master

would be cleaner and in the future once 3.11 is a thing, it could be just updated to

for BRANCH in MOODLE_{19..39}_STABLE MOODLE_{310..311}_STABLE master

which I am personally finding simpler than the current suggestion.

What do you think?

У відповідь на David Mudrák

Re: Keeping your public repository up-to-date script

Leon Stringer -
Фото Core developers Фото Particularly helpful Moodlers

David: Thank you, your suggestion is better. At some point after 3.11 this would then be:

for BRANCH in MOODLE_{19..40}_STABLE MOODLE_{310..311}_STABLE master
I point this out as it's slightly counter-intuitive!
У відповідь на Leon Stringer

Re: Keeping your public repository up-to-date script

David Mudrák -
Фото Core developers Фото Documentation writers Фото Moodle HQ Фото Particularly helpful Moodlers Фото Peer reviewers Фото Plugin developers Фото Plugins guardians Фото Testers Фото Translators

Well. The older branches up to 35 are not being touched any more so this can be shortened at the beginning. If you would find the chronological sequence more intuitive, this might evolve into something like:

for BRANCH in MOODLE_{35..39}_STABLE MOODLE_{310..311}_STABLE MOODLE_{40..42}_STABLE master

in the following years. Alternatively, something more self-descriptive:

STABLE_3x = MOODLE_{35..39}_STABLE
STABLE_3xy = MOODLE_{310..311}_STABLE
STABLE_4x = MOODLE_{40..42}_STABLE

for BRANCH in ${STABLE_3x} ${STABLE_3xy} ${STABLE_4x} master; do

Anything like this seems ok to me. My only objection was against the long long list of all the versions and the extra strings concatenations.

Also, there are other and likely better ways to achieve this. For example fetching the list of MOODLE_*_STABLE branches from upstream repo and using them all without any manual intervention, e.g. via

git for-each-ref --format='%(refname)' refs/remotes/origin/MOODLE_*_STABLE | cut -d/ -f4