summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-09-08 16:46:54 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-09-08 17:59:28 -0700
commit5d5045bcb450421363a0d2421435371ff02c631f (patch)
tree767ce7131c9e47bc4e6d41ae7dc6e472bde9cc34 /bin
parentf1e7161659d60d8a59bbedc376f13c82e5027b80 (diff)
downloaddotfiles-5d5045bcb450421363a0d2421435371ff02c631f.tar.gz
locmaint: pair athpriv.git backup with ~/src/athpriv
Diffstat (limited to 'bin')
-rwxr-xr-xbin/locmaint46
1 files changed, 32 insertions, 14 deletions
diff --git a/bin/locmaint b/bin/locmaint
index 750e5628..94c2e2de 100755
--- a/bin/locmaint
+++ b/bin/locmaint
@@ -94,12 +94,17 @@ our $check_for_extdrive = 0;
# remote server with a git-annex branch, which are not listed here,
# will be backed up as if they were just ordinary git repos. That's
# desirable behaviour for some annexes, which is why we don't try to
-# autodetect them
+# autodetect them.
+#
+# synconlyannex refers to the annex.synconlyannex config key; see
+# git-annex-config(1). We hardcode this here so that we can know how to clone
+# an annex as part of backing it up even when there's no clone in HOME.
our @remote_annexes = (
{ origin => "athenag:annex.git", homedir => "lib/annex", lazy => 1 },
{ origin => "athenag:annex19.git", homedir => "annex" },
{ origin => "athenag:libpriv.git", homedir => "lib/priv" },
- { origin => "athena:wikiannex", homedir => "lib/wikiannex" });
+ { origin => "athena:wikiannex", homedir => "lib/wikiannex" },
+ { origin => "athenap:athpriv", homedir => "src/athpriv", synconlyannex => 1 });
for (getpwuid($<) . '@' . `hostname -f`) {
chomp;
@@ -727,10 +732,11 @@ C<backup_repo()> should ensure it's available.
sub backup_repo {
my ($uri, $dest) = @_;
- my ($paired_annex, $lazy_paired_annex)
- = map { (catfile($ENV{HOME}, $_->{homedir}), $_->{lazy} // 0) }
- grep { $_->{origin} eq $uri } @remote_annexes;
+ my ($paired_annex, $lazy_paired_annex, $synconlyannex)
+ = map +(catfile($ENV{HOME}, $_->{homedir}), $_->{lazy},
+ $_->{synconlyannex}), grep $_->{origin} eq $uri, @remote_annexes;
$dest = "$dest.git" unless $dest =~ /\.git\z/;
+ my $do_origin_fetch = !$paired_annex || $synconlyannex;
# when we are backing up a paired annex, we need to be on a
# removable drive under /media, because that's going to be the
@@ -767,7 +773,7 @@ sub backup_repo {
make_path($dest) unless -d $dest;
# bare repos don't get a reflog by default
system "git -C $dest -c core.logAllRefUpdates=true clone "
- . (defined $paired_annex ? "--bare" : "--mirror") . " $uri .";
+ . ($do_origin_fetch ? "--mirror" : "--bare") . " $uri .";
}
my $git = Git::Wrapper->new($dest);
@@ -796,6 +802,13 @@ sub backup_repo {
$git->config(qw(annex.diskreserve 2GB));
$git->annex(qw(wanted . standard));
$git->annex(qw(group . incrementalbackup));
+ if ($synconlyannex) {
+ system "git", "branch", "-D", "git-annex";
+ $git->config("--add", "remote.origin.fetch",
+ "^refs/heads/git-annex");
+ $git->config("--add", "remote.origin.fetch",
+ "^refs/heads/synced/git-annex");
+ }
}
if (-d catfile($paired_annex, ".git")
&& -d catfile($paired_annex, ".git", "annex")) {
@@ -803,6 +816,7 @@ sub backup_repo {
my @remotes = $pair->remote();
$pair->remote("add", $desc, $dest)
unless (grep /^$desc$/, @remotes);
+ $synconlyannex and $git->config("annex.synconlyannex", "true");
# bypass Git::Wrapper so that output is printed
interactive_ensure_subroutine_success(
sub {
@@ -819,9 +833,13 @@ sub backup_repo {
. " on this machine, so not updating $dest");
get_ack();
}
- } elsif (!$clone_needed
- # additional check to avoid accidental ref clobbering
- and !-d catfile($dest, ".git", "annex")) {
+ }
+ if (
+ $do_origin_fetch
+ and !$clone_needed
+ # additional check to avoid accidental ref clobbering
+ and ($synconlyannex or !-d catfile($dest, ".git", "annex"))
+ ) {
my ($origin) = $git->config(qw(remote.origin.url));
die "$dest has origin remote URI $origin but we expected $uri"
@@ -835,13 +853,13 @@ sub backup_repo {
|| ("$origin $uri"
=~ m|gcrypt::rsync://athena:/srv/gcrypt/(.+) athenag:\1|);
+ my $fetch = "--tags --no-prune +refs/heads/*:refs/heads/*";
+ $synconlyannex
+ and $fetch .= " ^refs/heads/git-annex ^refs/heads/synced/git-annex";
+
# bypass Git::Wrapper so that fetch output is shown to the user
interactive_ensure_subroutine_success(
- sub {
- system_pty_capture(
-"git -C $dest fetch origin +refs/heads/*:refs/heads/* --tags --no-prune"
- );
- });
+ sub { system_pty_capture "git -C $dest fetch origin $fetch" });
}
}