Improved Git Mirroring
Since last October, I have mirrored many more repositories that I
personally would regret to lose. To not get lost in my archive, I
soon wanted a little bit of additional functionality. So I improved my
little script.
The script is still trivial, but I still want to share it here so that
I won't ever lose it - fitting right in with it's own mission. So,
without further ado, here it is:
#!/usr/bin/perl use v5.30; use warnings; sub fetch_all { foreach my $dir (glob '*.git') { next unless -d $dir; chdir $dir; my $cmd = "git fetch"; $cmd .= " --prune" if -f 'prune'; print $cmd . '@' . `pwd`; print `$cmd`; system("git gc --quiet"); chdir '..'; } } fetch_all; foreach my $dir (glob '*.d') { next unless -d $dir; say "\nEntering $dir ..."; chdir $dir; fetch_all; say "Leaving $dir ..."; chdir '..'; }
It now supports a single level of sub-directories, which is good
enough for my taste (at the moment). It also handles special files
named 'prune' which allows me to tidy up some repositories (while
risking to lose work in pruned branches, of course).