| 1 | #!/usr/bin/env perl | ||
| 2 | 1 | ▶ | use 5.12.1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | 0 | ▶ | use Yukki; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 5 | |||
| 6 | use Git::Repository v1.18; | ||
| 7 | |||
| 8 | my $repo_name = shift; | ||
| 9 | my $remote_repo = shift; | ||
| 10 | |||
| 11 | die "usage: $0 repository-name [ remote-repository-url ]\n" | ||
| 12 | unless $repo_name; | ||
| 13 | |||
| 14 | my $app = Yukki->new; | ||
| 15 | |||
| 16 | my $config = $app->settings->{repositories}{ $repo_name }; | ||
| 17 | |||
| 18 | die qq[Could not find o repository named "$repo_name" in yukki.conf\n] | ||
| 19 | unless $config; | ||
| 20 | |||
| 21 | my $repo_dir = ''.$app->locate('repository_path', $config->{repository}); | ||
| 22 | |||
| 23 | if (defined $remote_repo) { | ||
| 24 | Git::Repository->create('clone', '--mirror', | ||
| 25 | $remote_repo, $repo_dir); | ||
| 26 | } | ||
| 27 | |||
| 28 | else { | ||
| 29 | my $title = $config->{name} // ucfirst($repo_name); | ||
| 30 | my $page = $config->{default_page} // 'home.yukki'; | ||
| 31 | my $branch = $config->{site_branch} // 'refs/heads/master'; | ||
| 32 | |||
| 33 | my $stub_main = <<END_OF_STUB_MAIN; | ||
| 34 | # $title | ||
| 35 | |||
| 36 | Welcome to your new wiki repository. The first thing you will probably | ||
| 37 | want to do is edit this page. | ||
| 38 | |||
| 39 | Cheers. | ||
| 40 | |||
| 41 | END_OF_STUB_MAIN | ||
| 42 | |||
| 43 | Git::Repository->run('init', '--bare', $repo_dir); | ||
| 44 | my $git = Git::Repository->new(git_dir => $repo_dir); | ||
| 45 | |||
| 46 | my $object_id = $git->run('hash-object', '-t', 'blob', '-w', '--stdin', "--path=$page", { input => $stub_main }); | ||
| 47 | |||
| 48 | my $stub_tree = "100655 blob $object_id\t$page\n"; | ||
| 49 | my $tree_id = $git->run('mktree', { input => $stub_tree }); | ||
| 50 | my $commit_id = $git->run('commit-tree', $tree_id, { | ||
| 51 | input => 'Initializing empty Yukki repository.', | ||
| 52 | env => { | ||
| 53 | GIT_AUTHOR_NAME => 'yukki-git-init', | ||
| 54 | GIT_AUTHOR_EMAIL => 'hanenkamp@cpan.org', | ||
| 55 | }, | ||
| 56 | }); | ||
| 57 | |||
| 58 | $git->run('update-ref', $branch, $commit_id, '0' x 40); | ||
| 59 | } | ||
| 60 | |||
| 61 | # ABSTRACT: Initialize a git repository for use with Yukki | ||
| 62 | # PODNAME: yukki-git-init | ||
| 63 | |||
| 64 | __END__ | ||