patch: headless gits: make patch quieter
[ikiwiki.git] / doc / todo / headless_git_branches.mdwn
1 Ikiwiki should really survive being asked to work with a git branch that has no existing commits.
2
3     mkdir iki-gittest
4     cd iki-gittest
5     GIT_DIR=barerepo.git git init
6     git clone barerepo.git srcdir
7     ikiwiki --rcs=git srcdir destdir
8
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.
10
11 Please commit so my users stop whining at me about having clean branches to push to, the big babies.
12
13 Summary: Change three scary loud failure cases related to empty branches into three mostly quiet success cases.
14
15 [[!tag patch]]
16
17 <pre>
18 diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
19 index cf7fbe9..a1b5ed3 100644
20 --- a/IkiWiki/Plugin/git.pm
21 +++ b/IkiWiki/Plugin/git.pm
22 @@ -439,17 +439,20 @@ sub git_commit_info ($;$) {
23  
24         my @opts;
25         push @opts, "--max-count=$num" if defined $num;
26 +       my @raw_lines;
27 +       my @ci;
28  
29 -       my @raw_lines = run_or_die('git', 'log', @opts,
30 -               '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
31 -               '-r', $sha1, '--', '.');
32 +       if (-e $config{srcdir} . '/.git/refs/heads/' . $config{gitmaster_branch}) {
33 +               @raw_lines = run_or_die('git', 'log', @opts,
34 +                       '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
35 +                       '-r', $sha1, '--', '.');
36  
37 -       my @ci;
38 -       while (my $parsed = parse_diff_tree(\@raw_lines)) {
39 -               push @ci, $parsed;
40 -       }
41 +               while (my $parsed = parse_diff_tree(\@raw_lines)) {
42 +                       push @ci, $parsed;
43 +               }
44  
45 -       warn "Cannot parse commit info for '$sha1' commit" if !@ci;
46 +               warn "Cannot parse commit info for '$sha1' commit" if !@ci;
47 +       };
48  
49         return wantarray ? @ci : $ci[0];
50  }
51 @@ -474,7 +477,10 @@ sub rcs_update () {
52         # Update working directory.
53  
54         if (length $config{gitorigin_branch}) {
55 -               run_or_cry('git', 'pull', '--prune', $config{gitorigin_branch});
56 +               run_or_cry('git', 'fetch', '--prune', $config{gitorigin_branch});
57 +               if (-e $config{srcdir} . '/.git/refs/remotes/' . $config{gitorigin_branch} . '/' . $config{gitmaster_branch}) {
58 +                       run_or_cry('git', 'merge', $config{gitorigin_branch} . '/' . $config{gitmaster_branch});
59 +               }
60         }
61  }
62  
63 @@ -559,7 +565,7 @@ sub rcs_commit_helper (@) {
64         # So we should ignore its exit status (hence run_or_non).
65         if (run_or_non('git', 'commit', '-m', $params{message}, '-q', @opts)) {
66                 if (length $config{gitorigin_branch}) {
67 -                       run_or_cry('git', 'push', $config{gitorigin_branch});
68 +                       run_or_cry('git', 'push', $config{gitorigin_branch}, $config{gitmaster_branch});
69                 }
70         }
71         
72 </pre>