Mojolicious-Plugin-Export-Git
view release on metacpan or search on metacpan
$app->routes->get( '/about' )->name( 'about' );
$app->routes->get( '/redirect' )->to( cb => sub {
shift->redirect_to( 'http://example.com' )
});
return $app;
}
sub make_git {
my ( $dir, %args ) = @_;
Git::Repository->run( "init", ( $args{bare} ? ( '--bare' ) : () ), "$dir" );
my $git = Git::Repository->new( work_tree => "$dir" );
# Set some config so Git knows who we are (and doesn't complain)
_git_run( $git, config => 'user.name' => 'Test User' );
_git_run( $git, config => 'user.email' => 'test@example.com' );
return $git;
}
sub make_repo {
my ( $tmpdir, %args ) = @_;
$args{ remote } ||= "origin";
$args{ branch } ||= "gh-pages";
my $workdir = $tmpdir->child( 'workdir' )->make_path;
my $remotedir = $tmpdir->child( 'remotedir' )->make_path;
my $remotegit = make_git( $remotedir, bare => 1 );
my $workgit = make_git( $workdir );
_git_run( $workgit, remote => add => $args{remote} => "$remotedir" );
# Create a commit on the remote to make sure we create an orphan
# branch locally (this commit should not be on the branch created)
$remotedir->child( "README" )->spurt( "Repository readme, not in export branch" );
_git_run( $remotegit, add => 'README' );
_git_run( $remotegit, commit => -m => 'Initial commit' );
_git_run( $workgit, pull => $args{remote} => 'master' );
return ( $workdir, $remotedir );
}
sub current_branch {
my ( $git ) = @_;
my @branches = map { s/^\*\s+//; $_ } grep { /^\*/ } $git->run( 'branch' );
return $branches[0];
}
__DATA__
@@ index.html.ep
<head>
<link rel="stylesheet" href="//cdnjs.org/bootstrap.css">
</head>
<h1>Export</h1>
@@ logo-white-2x.png (base64)
iVBORw0KGgoAAAANSUhEUgAAAUIAAABMCAYAAAAY0L5YAAABG2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS41LjAiPgogPHJkZjpSRE...
( run in 2.288 seconds using v1.01-cache-2.11-cpan-df04353d9ac )