1 Ikiwiki should really survive being asked to work with a git branch that has no existing commits.
5 GIT_DIR=barerepo.git git init
6 git clone barerepo.git srcdir
7 ikiwiki --rcs=git srcdir destdir
9 I've fixed this initial construction case, and, based on my testing, I've also fixed the post-update executing on a new master, and ikiwiki.cgi executing on a non-existent master cases.
11 Please commit so my users stop whining at me about having clean branches to push to, the big babies.
13 Summary: Change three scary loud failure cases related to empty branches into three mostly quiet success cases.
18 diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
19 index cf7fbe9..e5bafcf 100644
20 --- a/IkiWiki/Plugin/git.pm
21 +++ b/IkiWiki/Plugin/git.pm
22 @@ -439,17 +439,21 @@ sub git_commit_info ($;$) {
25 push @opts, "--max-count=$num" if defined $num;
27 - my @raw_lines = run_or_die('git', 'log', @opts,
28 - '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
29 - '-r', $sha1, '--', '.');
33 - while (my $parsed = parse_diff_tree(\@raw_lines)) {
37 + # Test to see if branch actually exists yet.
38 + if (run_or_non('git', 'show-ref', '--quiet', '--verify', '--', 'refs/heads/' . $config{gitmaster_branch}) ) {
39 + @raw_lines = run_or_die('git', 'log', @opts,
40 + '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
41 + '-r', $sha1, '--', '.');
43 + while (my $parsed = parse_diff_tree(\@raw_lines)) {
47 - warn "Cannot parse commit info for '$sha1' commit" if !@ci;
48 + warn "Cannot parse commit info for '$sha1' commit" if !@ci;
51 return wantarray ? @ci : $ci[0];
53 @@ -474,7 +478,10 @@ sub rcs_update () {
54 # Update working directory.
56 if (length $config{gitorigin_branch}) {
57 - run_or_cry('git', 'pull', '--prune', $config{gitorigin_branch});
58 + run_or_cry('git', 'fetch', '--prune', $config{gitorigin_branch});
59 + if (run_or_non('git', 'show-ref', '--quiet', '--verify', '--', 'refs/remotes/' . $config{gitorigin_branch} . '/' . $config{gitmaster_branch}) ) {
60 + run_or_cry('git', 'merge', $config{gitorigin_branch} . '/' . $config{gitmaster_branch});
65 @@ -559,7 +566,7 @@ sub rcs_commit_helper (@) {
66 # So we should ignore its exit status (hence run_or_non).
67 if (run_or_non('git', 'commit', '-m', $params{message}, '-q', @opts)) {
68 if (length $config{gitorigin_branch}) {
69 - run_or_cry('git', 'push', $config{gitorigin_branch});
70 + run_or_cry('git', 'push', $config{gitorigin_branch}, $config{gitmaster_branch});