Hi,

Following the group BoF during DebConf22¹, here's my plan for changing·
the default branch for all module packages:

 ¹ https://lists.debian.org/debian-perl/2022/07/msg00019.html

# Salsa

A tool needs to be created that walks over all packages (probably·
reusing the code that creates the list of module package repositories·
using the Salsa API) and then, for each package, using the branches·
API²:

 ² https://docs.gitlab.com/ee/api/branches.html

 1) retrieve the name of the default branch; if it happens to be
    'debian/latest', skip to step 6)

/*
also check for upstream/latest? and debian/gbp.conf (existing/correct)?

what to do with (manually) semi-converted repos (debian/latest exists,
but is not the default branch, or master still exists, etc. …)
yes these repos exist …

and we also have (on salsa and locally) branches like "buster" or
"stable-update" or "wheezy-bpo" which should be named "debian/foo".
*/

 2) create a new branch, 'debian/latest' from the current default
    branch

 3) protect 'debian/latest' the same way the default branch is
    protected in newly created repositories:

   * merges allowed for 'Maintainers'

   * pushed allowed for 'Mainteiners+Developers'

   * no force-pushes allowed

 4) change the default branch to 'debian/latest'

 5) delete the branch that was default before 'debian/latest'

 6) if there is no 'upstream' branch, skip to the next repository

 7) create branch 'upstream-tmp' off 'upstream'

 8) delete branch 'upstream'

 9) create 'upstream/latest' branch off 'upstream-tmp'

 10) delete 'upstream-tmp' branch

The dance around 'upstream' is needed because 'upstream' can't be both
a ref and a directory.

# Local actions

This would be another tool, which every group member will need to run·
on their system. It walks over all cloned repositories (located via·
the DPT_PACKAGES setting in ~/.config/dpt.conf). The following steps·
are executed for each clone:

 * fail if there are uncommited changes

 * rename the default branch to debian/latest using git branch -m

 * git branch -m upstream upstream-tmp \
   && git branch -m upstream-tmp upstream/latest

 * git fetch (creates new remote branches named
   'origin/debian/latest' and 'origin/upstream/latest')

 * git branch -u origin/debian/latest debian/latest

 * git branch -u origin/upstream/latest upstream/latest

 * change/add 'debian-branch = debian/latest' and 'upstream-branch
   = upstream/latest' in debian/gbp.conf; commit and push

 * git fetch --prune origin

###

some snippets from the salsa(1) manpage:

salsa --group perl-team/modules/packages check_repo lemonldap-ng # +attic
             alias jsteam_admin="salsa --conf-file +~/.js.conf
% salsa --group perl-team/modules/packages --rename-head --dest-branch debian/latest check_repo dh-make-perl 
% salsa --group perl-team/modules/packages --rename-head --dest-branch debian/unstable check_repo dh-make-perl 

   --rename-head, --no-rename-head
       Rename HEAD branch given by --source-branch into --dest-branch and change "default branch" of project. Works
       only with update_repo.
       
       ".devscripts" value: SALSA_RENAME_HEAD (yes/no)
       
       --source-branch: default "master"
           ".devscripts" value: SALSA_SOURCE_BRANCH
       
       --dest-branch: default "debian/master"
           ".devscripts" value: SALSA_DEST_BRANCH
             
   rename_branch
       Rename branch given in --source-branch with name given in --dest-branch.  You can use --no-fail and --all
       options here.

###

gbp.conf should be editable as an ini-file
upstream branch name depending on debian/source/format

###

git-extras has a command `git-rename-branch' (locally and on remote)

###

debian/gbp.conf in libtype-tiny-perl (what is 'dist'?)

[DEFAULT]
debian-branch = debian/latest
upstream-branch = upstream/latest
dist = DEP14

###

    if git branch --remotes | grep -q origin/debian/latest; then 
        git remote set-head origin debian/latest
        git checkout debian/latest
    fi