Safely pruning merged topic branches locally
The final line has no effect:

trap error SIGHUP SIGINT SIGTERM


As the program is about to exit, we're exceedingly unlikely to receive any of those signals between this point and the end of the program.

It's much more usual to set the trap handler as soon as you've defined the error function.

Similarly, the exit trap

trap statistics EXIT


is the same as simply

statistics


when we're about to exit.  I suggest that this line is moved to before Step 1, too.