1use strict;
2use warnings;
3use Test::More;
4
5use File::Temp qw(tempdir);
6use Git::Wrapper;
7use POSIX qw(strftime);
8use Sort::Versions;
9use Test::Deep;
10use Test::Exception;
11use File::Spec;
12use Cwd qw/abs_path/;
13
14my $DO_WIN32_GETLONGPATHNAME = ($^O eq 'MSWin32') ? eval 'use Win32; 1' : 0;
15
16eval "use Path::Class 0.26; 1" or plan skip_all =>
17    "Path::Class 0.26 is required for this test.";
18
19my $tmpdir = File::Spec->tmpdir;
20$tmpdir = Win32::GetLongPathName(abs_path($tmpdir)) if $DO_WIN32_GETLONGPATHNAME;
21
22my $tempdir = tempdir(DIR => $tmpdir, CLEANUP => 1);
23
24my $dir = Path::Class::dir($tempdir);
25
26my $git = Git::Wrapper->new($dir);
27
28my $version = $git->version;
29if ( versioncmp( $git->version , '1.5.0') eq -1 ) {
30  plan skip_all =>
31    "Git prior to v1.5.0 doesn't support 'config' subcmd which we need for this test."
32}
33
34diag( "Testing git version: " . $version );
35
36$git->init; # 'git init' also added in v1.5.0 so we're safe
37
38# see https://github.com/genehack/Git-Wrapper/issues/91
39$git->config('commit.gpgsign', 'false');
40
41$git->config( 'user.name'  , 'Test User'        );
42$git->config( 'user.email' , 'test@example.com' );
43
44# make sure git isn't munging our content so we have consistent hashes
45$git->config( 'core.autocrlf' , 'false' );
46$git->config( 'core.safecrlf' , 'false' );
47
48my $foo = $dir->subdir('foo');
49$foo->mkpath;
50
51$foo->file('bar')->spew(iomode => '>:raw', "hello\n");
52
53is_deeply(
54  [ $git->ls_files({ o => 1 }) ],
55  [ 'foo/bar' ],
56);
57
58$git->add(Path::Class::dir('.'));
59is_deeply(
60  [ $git->ls_files ],
61  [ 'foo/bar' ],
62);
63
64SKIP: {
65  skip "Fails on Mac OS X with Git version < 1.7.5 for unknown reasons." , 1
66    if (($^O eq 'darwin') and ( versioncmp( $git->version , '1.7.5') eq -1 ));
67
68  $git->commit({ message => "FIRST\n\n\tBODY\n" });
69
70  my $baz = $dir->file('baz');
71
72  $baz->spew("world\n");
73
74  $git->add($baz);
75
76  ok(1);
77}
78
79done_testing();
80