How to remove a git branch in a dist-git repository

Historically we did not allow to remove git branches in dist-git repository, but FESCo recently approved their removal if and only if all the commits in the branch to be deleted can be reached from another branch. This is a requirement to ensure that if any of the commits were used in a build, we still have the commit accessible and thus we are able to reproduce the build if needed.

There is a script in the releng repository to use to check if a branch can safely be deleted.

So here are the steps to follow to remove the branch <branch> from the package <foo>.

  1. Clone the releng repo if you do not already have it:

    git clone https://forge.fedoraproject.org/releng/tooling.git
  2. Pull the latest changes:

    pushd tooling && git pull --rebase && popd
  3. Clone the <foo> package locally:

    fedpkg clone <foo>
  4. Run the unused-branch check script from your clone of the tooling repository (see above). The script must be invoked differently depending on whether you are in a normal working tree or in a bare repository (similar to the layout on pkgs servers or when simulating a releng environment).

    1. In a normal fedpkg working tree, change to the package directory and pass the remote branch ref with the origin/ prefix. The following assumes your tooling clone sits next to the package directory; adjust the path to distgit_branch_unused.py if your layout differs.

      cd <foo>
      git checkout <branch>
      python ../tooling/packages/distgit/distgit_branch_unused.py origin/<branch>
    2. In a bare clone, pass --package=<foo> and the short branch name (without the origin/ prefix):

      git clone --bare https://src.fedoraproject.org/<namespace>/<foo>.git <foo>.bare
      cd <foo>.bare
      python ../tooling/packages/distgit/distgit_branch_unused.py --package=<foo> <branch>

      (If needed, see the --help of the script for more information.)

  5. If the script returns that the branch is safe to delete:

    1. Go to pkgs01 as root

      ssh pkgs01.rdu3.fedoraproject.org
    2. Go to the git repository:

      cd /srv/git/repositories/<namespace>/<foo>.git
    3. Move the head of the branch (this allows to recover it later if needed):

      mv refs/heads/<branch> heads_<branch>

      Sometimes the ref is in the packed-refs file, in that case:

      grep <branch> packed-refs > heads_<branch>

      Then remove the line from packed-refs file

  6. On your local clone of <foo>, check that the branch was deleted upstream:

    git fetch -p

    This should show something like:

    $ git fetch -p
    From ssh://pkgs.fedoraproject.org/<namespace>/<foo>
    - [deleted]         (none)     -> origin/<branch>