Debian Codegraph @

t/21_annex-to-annex.t

raw symbols SCIP
1 #!/usr/bin/perl
2
3 use 5.028scip-perl cpan perl-project 0.0.0 `5.028`/;
4 use strictscip-perl cpan perl-project 0.0.0 strict/;
5 use warningsscip-perl cpan perl-project 0.0.0 warnings/;
6 use libscip-perl cpan perl-project 0.0.0 lib/ 't/lib';
7
8 use App::annex_to_annexscip-perl cpan perl-project 0.0.0 App/annex_to_annex/;
9 use Test::Morescip-perl cpan perl-project 0.0.0 Test/More/;
10 use t::Setupscip-perl cpan perl-project 0.0.0 t/Setup/;
11 use t::Utilscip-perl cpan perl-project 0.0.0 t/Util/;
12 use File::Pathscip-perl cpan perl-project 0.0.0 File/Path/ qw(make_path);
13 use File::Slurpscip-perl cpan perl-project 0.0.0 File/Slurp/;
14 use Capture::Tinyscip-perl cpan perl-project 0.0.0 Capture/Tiny/ qw(capture_merged);
15 use File::Spec::Functionsscip-perl cpan perl-project 0.0.0 File/Spec/Functions/ qw(catfile rel2abs);
16 use File::chdirscip-perl cpan perl-project 0.0.0 File/chdir/;
17
18 planscip-perl cpan perl-project 0.0.0 main/plan(). skip_all => "device ID issues" if device_id_issues;
19 planscip-perl cpan perl-project 0.0.0 main/plan(). skip_all => "git-annex not available" unless git_annex_available;
20
21 my ($output, $error, $exit, @output);
22
23 with_temp_annexesscip-perl cpan perl-project 0.0.0 main/with_temp_annexes(). {
24 make_pathscip-perl cpan perl-project 0.0.0 main/make_path(). "dest/foo/foo2";
25 write_filescip-perl cpan perl-project 0.0.0 main/write_file(). "dest/foo/bar", "";
26 write_filescip-perl cpan perl-project 0.0.0 main/write_file(). "dest/foo/foo2/baz", "";
27 (undef, $error, $exit)
28 = run_bin qw(annex-to-annex source1/foo source2/other dest);
29 okscip-perl cpan perl-project 0.0.0 main/ok(). $exit, "it exits nonzero instead of clobbering an existing file";
30 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/\/dest\/foo\/bar already exists!$/, @$error),
31 "it won't clobber an existing file";
32 };
33
34 with_temp_annexesscip-perl cpan perl-project 0.0.0 main/with_temp_annexes(). {
35 write_filescip-perl cpan perl-project 0.0.0 main/write_file(). catfilescip-perl cpan perl-project 0.0.0 main/catfile().("source1", "quux"), "quux\n";
36 (undef, $error, $exit)
37 = run_bin qw(annex-to-annex --commit source1/foo/bar dest);
38 okscip-perl cpan perl-project 0.0.0 main/ok(). $exit,
39 "with --commit, it exits nonzero when uncommitted source changes";
40 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/^git repo containing [^ ]+\/bar is not clean; please commit$/,
41 @$error),
42 "with --commit, it exits when uncommitted changes";
43 };
44
45 with_temp_annexesscip-perl cpan perl-project 0.0.0 main/with_temp_annexes(). {
46 write_filescip-perl cpan perl-project 0.0.0 main/write_file(). catfilescip-perl cpan perl-project 0.0.0 main/catfile().("dest", "quux"), "quux\n";
47 (undef, $error, $exit)
48 = run_bin qw(annex-to-annex --commit source1/foo/bar dest);
49 okscip-perl cpan perl-project 0.0.0 main/ok(). $exit, "with --commit, it exits nonzero when uncommitted dest changes";
50 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/^git repo containing [^ ]+\/dest is not clean; please commit$/,
51 @$error),
52 "with --commit, it exits when uncommitted changes";
53 };
54
55 # following test is sensitive to changes in git-log output, but that's
56 # okay
57 with_temp_annexesscip-perl cpan perl-project 0.0.0 main/with_temp_annexes(). {
58 my (undef, $source1, $source2, $dest) = @_scip-perl cpan perl-project 0.0.0 main/`@_`.;
59
60 # also implicitly test, here, that we can invoke the program by
61 # passing a subroutine reference when invoking main as a class
62 # method
63 App::annex_to_annex->mainscip-perl cpan perl-project 0.0.0 App/annex_to_annex/main().([qw(--commit source1/foo source2/other dest)]);
64
65 @output = $source1->RUNscip-perl cpan perl-project 0.0.0 main/RUN().(qw(log -1 --oneline --name-status));
66 like $output[0], qr/migrated by annex-to-annex/,
67 "--commit makes a source1 commit";
68 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(m{^D\s+foo/bar$}, @output[1 .. $#outputscip-perl cpan perl-project 0.0.0 main/`$#output`.]),
69 "--commit commit deletes bar";
70 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(m{^D\s+foo/foo2/baz$}, @output[1 .. $#outputscip-perl cpan perl-project 0.0.0 main/`$#output`.]),
71 "--commit commit deletes baz";
72
73 @output = $source2->RUNscip-perl cpan perl-project 0.0.0 main/RUN().(qw(log -1 --oneline --name-status));
74 like $output[0], qr/migrated by annex-to-annex/,
75 "--commit makes a source2 commit";
76 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(m{^D\s+other$}, @output[1 .. $#outputscip-perl cpan perl-project 0.0.0 main/`$#output`.]),
77 "--commit commit deletes other";
78
79 @output = $dest->RUNscip-perl cpan perl-project 0.0.0 main/RUN().(qw(log -1 --oneline --name-status));
80 like $output[0], qr/add/, "--commit makes a dest commit";
81 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(m{^A\s+other$}, @output[1 .. $#outputscip-perl cpan perl-project 0.0.0 main/`$#output`.]),
82 "--commit commit adds other";
83 };
84
85 with_temp_annexesscip-perl cpan perl-project 0.0.0 main/with_temp_annexes(). {
86 my (undef, $source1) = @_scip-perl cpan perl-project 0.0.0 main/`@_`.;
87
88 corrupt_annexed_filescip-perl cpan perl-project 0.0.0 main/corrupt_annexed_file(). $source1, "foo/foo2/baz";
89 (undef, $error, $exit)
90 = run_bin qw(annex-to-annex --commit source1/foo source2/other dest);
91 okscip-perl cpan perl-project 0.0.0 main/ok(). $exit, "it exits nonzero when dest annex calculates a diff checksum";
92 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/git-annex calculated a different checksum for/, @$error),
93 "it warns when dest annex calculates a diff checksum";
94 };
95
96 with_temp_annexesscip-perl cpan perl-project 0.0.0 main/with_temp_annexes(). {
97 my (undef, $source1) = @_scip-perl cpan perl-project 0.0.0 main/`@_`.;
98
99 $source1->annexscip-perl cpan perl-project 0.0.0 main/annex().(qw(drop --force foo/foo2/baz));
100 ($output, undef, $exit)
101 = run_bin qw(annex-to-annex --commit source1/foo source2/other dest);
102 okscip-perl cpan perl-project 0.0.0 main/ok(). $exit, "it exits nonzero when an annexed file is not present";
103 okscip-perl cpan perl-project 0.0.0 main/ok().
104 grepscip-perl cpan perl-project 0.0.0 main/grep().(/^Following annexed files are not present in this repo:$/, @$output),
105 "it exits when annexed files are not present";
106 };
107
108 # this is the main integration test for the script doing its job
109 with_temp_annexesscip-perl cpan perl-project 0.0.0 main/with_temp_annexes(). {
110 my (undef, $source1, $source2, $dest) = @_scip-perl cpan perl-project 0.0.0 main/`@_`.;
111 run_bin qw(annex-to-annex source1/foo source2/other dest);
112 {
113 local $CWDscip-perl cpan perl-project 0.0.0 main/$CWD. = "source1";
114 ok !-e "foo/bar", "bar should not exist in source1";
115 ok !-e "foo/foo2/baz", "baz should not exist in source1";
116 }
117 ok !-e "source2/other", "other should not exist in source2";
118 {
119 local $CWDscip-perl cpan perl-project 0.0.0 main/$CWD. = "dest";
120
121 ok -fscip-perl cpan perl-project 0.0.0 main/f(). "foo/bar", "bar is regular file in dest";
122 ok -fscip-perl cpan perl-project 0.0.0 main/f(). "foo/foo2/baz", "baz is regular file in dest";
123 ok -lscip-perl cpan perl-project 0.0.0 main/l(). "other", "other is symlink in dest";
124 my @bar_find = $dest->annexscip-perl cpan perl-project 0.0.0 main/annex().(qw(find foo/bar));
125 ok @bar_find == 0, "bar is not annexed in dest";
126
127 my ($baz_key) = $dest->annexscip-perl cpan perl-project 0.0.0 main/annex().(qw(lookupkey foo/foo2/baz));
128 my ($baz_content) = $dest->annexscip-perl cpan perl-project 0.0.0 main/annex().("contentlocation", $baz_key);
129 my @baz_content_stat = statscip-perl cpan perl-project 0.0.0 main/stat(). $baz_content;
130 ok $baz_content_statscip-perl cpan perl-project 0.0.0 main/$baz_content_stat.[3] == 2, "baz was hardlinked into annex";
131 okscip-perl cpan perl-project 0.0.0 main/ok().((statscip-perl cpan perl-project 0.0.0 main/stat().("foo/foo2/baz"))[3] == 1,
132 "baz in dest working tree is a copy");
133
134 my ($other_key) = $dest->annexscip-perl cpan perl-project 0.0.0 main/annex().(qw(lookupkey other));
135 my ($other_content) = $dest->annexscip-perl cpan perl-project 0.0.0 main/annex().("contentlocation", $other_key);
136 my @other_content_stat = statscip-perl cpan perl-project 0.0.0 main/stat(). $other_content;
137 ok $other_content_statscip-perl cpan perl-project 0.0.0 main/$other_content_stat.[3] == 2, "other was hardlinked into annex";
138
139 isscip-perl cpan perl-project 0.0.0 main/is(). read_filescip-perl cpan perl-project 0.0.0 main/read_file().("foo/bar"), "bar\n", "bar has expected file content";
140 isscip-perl cpan perl-project 0.0.0 main/is(). read_filescip-perl cpan perl-project 0.0.0 main/read_file().("foo/foo2/baz"), "baz\n", "baz has expected file content";
141 isscip-perl cpan perl-project 0.0.0 main/is(). read_filescip-perl cpan perl-project 0.0.0 main/read_file().("other"), "other\n", "other has expected file content";
142 }
143 my @source1_git_status = $source1->RUNscip-perl cpan perl-project 0.0.0 main/RUN().(qw(status --porcelain));
144 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/D\s+foo\/bar/, @source1_git_status), "bar was removed from git";
145 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/D\s+foo\/foo2\/baz/, @source1_git_status),
146 "baz was removed from git";
147 my @source2_git_status = $source2->RUNscip-perl cpan perl-project 0.0.0 main/RUN().(qw(status --porcelain));
148 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/D\s+other/, @source2_git_status), "other was removed from git";
149 my @dest_git_status = $dest->RUNscip-perl cpan perl-project 0.0.0 main/RUN().(qw(status --porcelain));
150 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/A\s+foo\/bar/, @dest_git_status), "bar was added to git";
151 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/A\s+foo\/foo2\/baz/, @dest_git_status), "baz was added to git";
152 okscip-perl cpan perl-project 0.0.0 main/ok(). grepscip-perl cpan perl-project 0.0.0 main/grep().(/A\s+other/, @dest_git_status), "other was added to git";
153 };
154
155 done_testing;