summaryrefslogtreecommitdiff
path: root/perl5/Local/MrRepo/Repo/Git/Annex.pm
blob: d3eefcdf27427d42f834d2783c860fb04508b237 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package Local::MrRepo::Repo::Git::Annex;

# Copyright (C) 2019-2020 Sean Whitton
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use 5.018;
use strict;
use warnings;
use lib "$ENV{HOME}/src/dotfiles/perl5";
use parent 'Local::MrRepo::Repo::Git';

use App::git_annex_reviewunused;
use Data::Compare;
use Exporter 'import';
use File::Spec::Functions qw(rel2abs catfile);
use Git::Wrapper;
use JSON;
use Local::ScriptStatus;
use Try::Tiny;
use Term::ReadKey;
use Local::Interactive qw(prompt prompt_yn);
use Storable;
use List::Util qw(all);
use File::chdir;

our @EXPORT_OK = ();

sub review {
    my $self = shift;

    my $issues = $self->SUPER::review(@_);

    # if there were git issues, fail now, as the annex issues can
    # produce copious output and it is nice to know there were no git
    # issues when reviewing the annex issues
    return $issues if $issues;

    # another command we could consider running is `git annex fsck --fast`

    # 1. Check for files stored only locally where that's not okay
    my @annex_find_output
      = $self->git->annex(
        qw(find --json --in here --and --not --copies=2 --and --lackingcopies=1)
      );
    unless (@annex_find_output == 0) {
        say_spaced_bullet("Some annex content is present only locally:");
        say "  $_" for map { ${decode_json($_)}{file} } @annex_find_output;
        print "\n";
        say_bold
          ("  use `git annex sync --content' to fix this (`mr push' should be");
        say_bold
          ("  configured to run that command with the right remotes)");
        $issues = 1;
    }
    # 2. Check for unused files which we should be able to clean up
    my ($review_unused) = $self->git->config(qw(--local --get --type=bool
                                                --default true
                                                spwhitton.mrrepo.review-unused));

    if ($review_unused eq "true") {
        #<<<
        try {
            local $CWD = $self->toplevel;
            $issues = App::git_annex_reviewunused->main(["--just-print"])
              || $issues;
        } catch {
            $issues = 1;
        };
        #>>>
    }

    return $issues;
}

1;