Merge commit 'origin/reproducible' into reproducable
[git-darcs-import.git] / tests / filepath.pl
blobde110a6107f57c8890ed71bfbdd33cd8c36c1e5a
1 #!/usr/bin/env perl
3 # Some tests for proper handling of filepaths
5 use lib 'lib/perl';
6 use Test::More 'no_plan';
7 use Test::Darcs;
8 use Shell::Command;
9 use strict;
10 use warnings;
11 use Cwd;
12 use File::Temp 'tempdir';
13 my $work_dir = tempdir( CLEANUP => 1 );
14 chdir $work_dir;
16 mkpath 'temp1';
18 my $repo_flag = '--repodir=temp1';
19 my $test_name = 'Make sure that init works with --repodir';
20 darcs "init $repo_flag";
21 ok((-d 'temp1/_darcs'), '_darcs directory was created');
23 # add some meat to that repository
24 chdir 'temp1';
25 touch 'baz';
26 darcs qw( add baz ) ;
27 darcs qw( record -m moo -a ) ;
28 chdir '../';
30 # ----------------------------------------------------------------------
31 # local vs remote filepaths
32 # ----------------------------------------------------------------------
33 like( darcs("get temp1 temp2"), qr/Finished getting/i );
34 chdir 'temp2';
35 mkpath 'dir';
36 darcs "add dir";
37 chdir 'dir';
38 `touch foo:bar`;
39 unlike( darcs("add foo:bar"), qr/failed/i );
40 chdir '../..';
41 cleanup 'temp2';
43 # ----------------------------------------------------------------------
44 # repodir stuff
45 # ----------------------------------------------------------------------
46 mkpath 'temp1/non-darcs';
47 $test_name = '--repodir is not recursive';
48 like( darcs("get temp1/non-darcs"), qr/Not a repository/i, $test_name );
49 cleanup 'temp1/non-darcs';
50 cleanup 'non-darcs';
52 $test_name = 'get accepts --repodir.';
53 like( darcs("get --repodir=temp2 temp1"), qr/Finished getting/i, $test_name );
54 ok((-d 'temp2/_darcs'), '_darcs directory was created');
55 cleanup 'temp2';
56 $test_name = 'get accepts absolute --repodir.';
57 like( darcs(q{get --repodir="}.cwd().q{/temp2" temp1}), qr/Finished getting/i, $test_name );
58 ok((-d 'temp2/_darcs'), '_darcs directory was created');
60 $test_name = 'changes accepts --repodir.';
61 like( darcs("changes $repo_flag"), qr/moo/i, $test_name );
62 $test_name = 'changes accepts absolute --repo.';
63 like( darcs(q{changes --repo="}.cwd().q{/temp1"}), qr/moo/i, $test_name );
64 $test_name = 'changes accepts relative --repo.';
65 like( darcs("changes --repo=temp1"), qr/moo/i, $test_name );
66 $test_name = "[issue467] context --repodir";
67 like ( darcs("changes --context --repodir=temp1"), qr/Context:/, $test_name );
69 $test_name = 'dist accepts --repodir.';
70 like( darcs("dist $repo_flag"), qr/Created dist/i, $test_name );
72 $test_name = 'optimize accepts --repodir.';
73 like( darcs("optimize --reorder-patches $repo_flag"), qr/done optimizing/i, $test_name );
75 $test_name = 'repair accepts --repodir.';
76 like( darcs("repair $repo_flag"), qr/already consistent/i, $test_name );
78 $test_name = 'replace accepts --repodir.';
79 like( darcs("replace $repo_flag foo bar"), qr//i, $test_name );
81 $test_name = 'setpref accepts --repodir.';
82 like( darcs("setpref $repo_flag test echo"), qr/Changing value of test/i, $test_name );
84 $test_name = 'trackdown accepts --repodir.';
85 like( darcs("trackdown $repo_flag"), qr/Success!/i, $test_name );
87 # ----------------------------------------------------------------------
88 # converting between absolute and relative paths
89 # ----------------------------------------------------------------------
91 like( darcs("get temp1 temp3"), qr/Finished getting/i );
92 chdir 'temp3';
93 mkpath 'a/b';
94 chdir '..';
96 sub change_something_record {
97 my $hello = shift;
98 open BAZ, ">>baz";
99 print BAZ "hello $hello";
100 close BAZ;
101 darcs("record -m hello$hello -a");
103 chdir 'temp2';
104 change_something_record 1;
105 change_something_record 2;
106 chdir '..';
108 $test_name = 'can handle .. path';
109 chdir 'temp3';
110 like( darcs("pull ../temp2 -p1 --all"), qr/Finished pulling/, $test_name );
111 like( darcs("pull --dry-run"), qr/hello2/, "$test_name with defaultrepo" );
112 chdir 'a/b';
113 like( darcs("pull --dry-run"), qr/hello2/, "[issue268] $test_name with subdir" );
115 chdir '/';