summaryrefslogtreecommitdiff
path: root/t/10_init.t
blob: 2ed45678f9bf5aac7428234a6d8ad47827dbeb31 (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
#!/usr/bin/perl

use 5.028;
use strict;
use warnings;
use lib 't/lib';

use Test::More;
use Git::Annex;
use File::chdir;
use File::Temp qw(tempdir);
use t::Setup;
use t::Util;
use File::Spec::Functions qw(catfile file_name_is_absolute);

{
    my $temp = tempdir CLEANUP => 1;
    my $annex = Git::Annex->new($temp);
    is $annex->toplevel, $temp, "constructor sets toplevel to provided dir";
    local $CWD = $temp;
    $annex = Git::Annex->new;
    is $annex->toplevel, $temp, "constructor sets toplevel to pwd";
    $annex = Git::Annex->new("foo");
    ok file_name_is_absolute($annex->toplevel),
      "it converts a relative path to absolute";
    ok !-d $annex->toplevel, "it permits initialisation in a nonexistent dir";
}

{
    my $temp = tempdir CLEANUP => 1;
    my $annex = Git::Annex->new($temp);
    is $annex->{git}, undef, "Git::Wrapper instance lazily instantiated";
    ok $annex->git->isa("Git::Wrapper") && defined $annex->{git},
      "Git::Wrapper instance available";
    is $annex->git->dir, $temp, "Git::Wrapper has correct toplevel";
}

# # lazy init of Git::Repository object requires an actual git repo, not
# # just an empty tempdir
# with_temp_annexes {
#     my $annex = Git::Annex->new("source1");
#     is $annex->{repo}, undef, "Git::Repository instance lazily instantiated";
#     ok $annex->repo->isa("Git::Repository") && defined $annex->{repo},
#       "Git::Repository instance available";
#     is $annex->repo->work_tree, catfile(shift, "source1"),
#       "Git::Repository has correct toplevel";
# };

SKIP: {
    skip "git-annex not available", 1 unless git_annex_available;
    with_temp_annexes {
        my $source1_dir = catfile shift, "source1";
        my $annex = Git::Annex->new(catfile $source1_dir, "foo");
        is $annex->toplevel, $source1_dir, "it rises to top of working tree";
    };
}

done_testing;