App-KGB
view release on metacpan or search on metacpan
t/53-client-git-merges.t view on Meta::CPAN
open my $fh, '>>', "$local/$fn";
print $fh $content, "\n";
close $fh;
}
mkdir $remote;
$ENV{GIT_DIR} = $remote;
system 'git', 'init', '--bare';
use Cwd;
my $R = getcwd;
my $hook_log = "$dir/hook.log";
my $hook = "$dir/there.git/hooks/post-receive";
my $client_script = $ENV{KGB_CLIENT_SCRIPT} || "$R/script/kgb-client";
# the real test client
{
my $ccf = $test_bot->client_config_file;
open my $fh, '>', $hook;
print $fh <<EOF;
#!/bin/sh
tee -a "$dir/reflog" | PERL5LIB=$R/lib $^X -- $client_script --conf $ccf >> $hook_log 2>&1
EOF
close $fh;
chmod 0755, $hook;
}
if ( $ENV{TEST_KGB_BOT_RUNNING} ) {
diag "will try to send notifications to locally running bot";
open( my $fh, '>>', $hook );
print $fh <<"EOF";
cat "$dir/reflog" | PERL5LIB=$R/lib $^X -- $client_script --conf $R/eg/test-client.conf --status-dir $dir
EOF
close $fh;
}
mkdir $local;
$ENV{GIT_DIR} = "$local/.git";
mkdir "$local/.git";
system 'git', 'init';
my $git = 'Git'->repository($local);
ok( $git, 'local repository allocated' );
isa_ok( $git, 'Git' );
my $ign = $git->command( 'config', 'user.name', 'Test U. Ser' );
$ign = $git->command( 'config', 'user.email', 'ser@example.neverland' );
write_tmp 'reflog', '';
my $c = new_ok(
'App::KGB::Client::Git' => [
{ repo_id => 'test',
servers => [
App::KGB::Client::ServerRef->new(
{ uri => "http://127.0.0.1:1234/",
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 {
my $ignore = $git->command_oneline( 'commit', '-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' );
$ign = $git->command( 'add', '.' );
do_commit('import old content');
$ign = $git->command( 'remote', 'add', 'origin', "file://$remote" );
push_ok;
$commit = $c->describe_commit;
ok( defined($commit), 'initial import commit' );
is( $c->describe_commit, undef, 'no more commits' );
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.'' );
#### branch, two changes, merge. then the changes should be reported only once
my $b1 = 'a-new';
$ign = $git->command( [ 'checkout', '-b', $b1, 'master' ],
{ STDERR => 0 } );
w( 'new', 'content' );
$ign = $git->command( 'add', 'new' );
$ign = $git->command( 'commit', '-m', 'created new content' );
w( 'new', 'more content' );
$ign = $git->command( 'commit', '-a', '-m', 'updated new content' );
( run in 0.918 second using v1.01-cache-2.11-cpan-2398b32b56e )