doc: describe public-inbox dedupe
[ssoma.git] / t / git.t
blobc19093d2ca6b2990c39957e7ecb7a4167d42241b
1 #!/usr/bin/perl -w
2 # Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
4 use strict;
5 use warnings;
6 use Test::More;
7 use Ssoma::Git;
8 use Ssoma::GitIndexInfo;
9 use File::Temp qw/tempdir/;
10 my $tmpdir = tempdir(CLEANUP => 1);
11 my $git = Ssoma::Git->new("$tmpdir/gittest");
13 $git->init_db;
14 ok(-d "$tmpdir/gittest", "git repo created");
17 my $v = `GIT_DIR=$tmpdir/gittest git config ssoma.repoversion`;
18 is(0, $?, "git config succeeded");
19 chomp($v);
20 is(1, $v, "ssoma.repoversion is set to 1");
23 is(0, $git->tmp_git_do(sub { system(qw(git config ssoma.test foo)) }),
24 "setting config works");
26 is("foo\n", $git->tmp_git_do(sub { `git config ssoma.test` }),
27 "reading config works");
29 $git->tmp_git_do(sub {
30 my $commit;
31 $git->tmp_index_do(sub {
32 my $gii = Ssoma::GitIndexInfo->new;
34 my $sha1 = `echo hello world | git hash-object -w --stdin`;
35 is(0, $?, "hashed one object");
36 chomp $sha1;
38 is(1, $gii->update(100644, $sha1, 'hello/world'),
39 "add hashed object to index");
40 $gii = undef;
42 my $tree = `git write-tree`;
43 is(0, $?, "wrote tree out");
44 chomp $tree;
46 $commit = `git commit-tree -m 'hi' $tree`;
47 is(0, $?, "committed tree");
48 chomp $commit;
50 is(0, system(qw(git update-ref refs/heads/master), $commit),
51 "updated ref");
52 });
53 });
56 is($git->mid2path("<hello world>"),
57 $git->mid2path("\t<hello world>\t"),
58 "mid2path ignores leading/trailing whitespace");
61 done_testing();