]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/headless_git_branches.mdwn
removed
[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..e5bafcf 100644
20 --- a/IkiWiki/Plugin/git.pm
21 +++ b/IkiWiki/Plugin/git.pm
22 @@ -439,17 +439,21 @@ sub git_commit_info ($;$) {
23  
24         my @opts;
25         push @opts, "--max-count=$num" if defined $num;
26 -
27 -       my @raw_lines = run_or_die('git', 'log', @opts,
28 -               '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
29 -               '-r', $sha1, '--', '.');
30 -
31 +       my @raw_lines;
32         my @ci;
33 -       while (my $parsed = parse_diff_tree(\@raw_lines)) {
34 -               push @ci, $parsed;
35 -       }
36 +        
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, '--', '.');
42 +
43 +               while (my $parsed = parse_diff_tree(\@raw_lines)) {
44 +                       push @ci, $parsed;
45 +               }
46  
47 -       warn "Cannot parse commit info for '$sha1' commit" if !@ci;
48 +               warn "Cannot parse commit info for '$sha1' commit" if !@ci;
49 +       };
50  
51         return wantarray ? @ci : $ci[0];
52  }
53 @@ -474,7 +478,10 @@ sub rcs_update () {
54         # Update working directory.
55  
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});
61 +               }
62         }
63  }
64  
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});
71                 }
72         }
73         
74 </pre>