App-KGB

 view release on metacpan or  search on metacpan

t/54-client-git-squash.t  view on Meta::CPAN

                        password => "hidden",               # not used by this client instance
                    }
                ),
            ],

            #br_mod_re      => \@br_mod_re,
            #br_mod_re_swap => $br_mod_re_swap,
            #ignore_branch  => $ignore_branch,
            git_dir => $remote,
            reflog  => "$dir/reflog",
        }
    ]
);

sub push_ok {
    write_tmp 'reflog', '';
    unlink $hook_log if $hook_log and -s $hook_log;

    my $ignore = $git->command( [qw( push origin --all )], { STDERR => 0 } );
    $ignore = $git->command( [qw( push origin --tags )], { STDERR => 0 } );

    $c->_reset;
    $c->_detect_commits;

    diag `cat $hook_log` if $hook_log and -s $hook_log;
}

my %commits;
sub do_commit {
    $git->command_oneline( 'commit', '-a', '-m', shift ) =~ /\[(\w+).*\s+(\w+)\]/;
    push @{ $commits{$1} }, $2;
    diag "commit $2 in branch $1" unless $tmp_cleanup;
}

my $commit;

###### first commit
w( 'old', 'content' );
$git->command( 'add', '.' );
do_commit('import old content');
$git->command( 'remote', 'add', 'origin', "file://$remote" );

push_ok;

$commit = $c->describe_commit;
ok( defined($commit), 'first commit exists' );
is( $commit->branch, 'master' );
is( $commit->log,    "import old content" );
is( $commit->id,     shift @{ $commits{master} } );

TestBot->expect( 'dummy/#test 12test/03there 05master '
        . $commit->id
        . ' 06Test U. Ser (06ser) 03old import old content * 14http://scm.host.org/there/master/?commit='
        . $commit->id
        . '' );

w( 'new', 'content' );
$git->command( 'add', 'new' );
$git->command( 'commit', '-m', 'created new content' );
w( 'new', 'more content' );
$git->command( 'commit', '-a', '-m', 'updated new content' );
a( 'new', 'even more content' );
do_commit('another update' );

push_ok;

$commit = $c->describe_commit;
ok( defined($commit), 'squashed commit exists' ) or BAIL_OUT 'will fail anyway';
ok( !ref($commit), 'squashed commit is a plain string' ) or BAIL_OUT 'will fail anyway';

my $commit_id = shift @{ $commits{master} };

TestBot->expect( "dummy/#test 12test/03there 05master"
        . " $commit_id "
        . ${TestBot::COMMIT_USER}
        . " 3 commits pushed,"
        . " 101 file changed, 032(+)" );

### multiple commits in a new branch
$git->command( 'checkout', '-q', '-b', 'feature', 'master' );
a( 'new', 'additional content' );
do_commit( 'additional content in a new branch' );
a( 'new', 'even more additional content' );
do_commit( 'second commit in the new branch' );
push_ok;

my $last_commit_id = $commit_id;
$commit_id = pop @{ $commits{feature} };
$commit = $c->describe_commit;
ok( defined($commit), 'squashed new branch commit exists' ) or BAIL_OUT "premature end of commits";
ok( !ref($commit), 'squashed commit is a plain string' )
    or BAIL_OUT "will fail with $commit anyway";

TestBot->expect( "dummy/#test 12test/03there 05feature "
        . $commit_id
        . " "
        . ${TestBot::COMMIT_USER}
        . " New branch with 2 commits pushed,"
        . " 101 file changed, 032(+) since master/"
        . $last_commit_id );

##### No more commits after the last
$commit = $c->describe_commit;
is( $commit, undef );

my $output = $test_bot->get_output;

undef($test_bot);   # make sure all output us there

eq_or_diff( $output, TestBot->expected_output );

done_testing();



( run in 1.635 second using v1.01-cache-2.11-cpan-39bf76dae61 )