Keeping your public repository up-to-date script

Keeping your public repository up-to-date script

by Leon Stringer -
Number of replies: 5
Picture of Core developers Picture of 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?

Average of ratings: -
In reply to Leon Stringer

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

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of 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"!
In reply to Visvanath Ratnaweera

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

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

In short "310" is not "3.10"!

I think this should be revised and clarified in the light of the latest weekly build that came after your post.

In reply to Leon Stringer

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

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of 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?

Average of ratings: Useful (1)
In reply to David Mudrák

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

by Leon Stringer -
Picture of Core developers Picture of 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!
In reply to Leon Stringer

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

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of 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
Average of ratings: Useful (3)