3 # Copyright (c) 2005 Junio C Hamano
5 # Read .git/FETCH_HEAD and make a human readable merge message
6 # by grouping branches and tags together to form a single line.
9 unless (exists $ENV{'RUNNING_GIT_TESTS'}) {
10 unshift @INC, '@@INSTLIBDIR@@';
17 my $repo = Git->repository();
22 my ($label, $labels, $stuff) = @_;
23 my $l = scalar @$stuff;
29 $m = "$label$stuff->[0]";
33 join (', ', @{$stuff}[0..$l-2]) .
42 $val = $repo->command_oneline('repo-config', '--get', 'merge.summary');
43 } catch Git::Error::Command with {
45 if ($E->value() == 1) {
55 my ($bra) = $repo->command_oneline('symbolic-ref', 'HEAD');
56 $bra =~ s|^refs/heads/||;
57 if ($bra ne 'master') {
68 foreach ($repo->command('log', '--no-merges', '--topo-order', '--pretty=oneline', $tip, '^HEAD')) {
77 my ($bname, $tname, $gname, $src, $sha1, $origin);
81 next if (/^not-for-merge/);
90 if (! exists $src{$src}) {
102 if (/^branch (.*)$/) {
104 push @{$src{$src}{BRANCH}}, $1;
105 $src{$src}{HEAD_STATUS} |= 2;
107 elsif (/^tag (.*)$/) {
109 push @{$src{$src}{TAG}}, $1;
110 $src{$src}{HEAD_STATUS} |= 2;
112 elsif (/^remote branch (.*)$/) {
114 push @{$src{$src}{R_BRANCH}}, $1;
115 $src{$src}{HEAD_STATUS} |= 2;
119 $src{$src}{HEAD_STATUS} |= 1;
122 push @{$src{$src}{GENERIC}}, $_;
123 $src{$src}{HEAD_STATUS} |= 2;
126 if ($src eq '.' || $src eq $origin) {
127 $origin =~ s/^'(.*)'$/$1/;
128 push @origin, [$sha1, "$origin"];
131 push @origin, [$sha1, "$origin of $src"];
137 if ($src{$src}{HEAD_STATUS} == 1) {
138 # Only HEAD is fetched, nothing else.
143 if ($src{$src}{HEAD_STATUS} == 3) {
144 # HEAD is fetched among others.
145 push @this, andjoin('', '', ['HEAD']);
147 push @this, andjoin("branch ", "branches ",
149 push @this, andjoin("remote branch ", "remote branches ",
150 $src{$src}{R_BRANCH});
151 push @this, andjoin("tag ", "tags ",
153 push @this, andjoin("commit ", "commits ",
154 $src{$src}{GENERIC});
155 my $this = join(', ', @this);
162 my $into = current_branch();
164 print "Merge ", join("; ", @msg), $into, "\n";
170 # We limit the merge message to the latst 20 or so per each branch.
174 my ($sha1, $name) = @$_;
175 my @log = shortlog($sha1);
176 if ($limit + 1 <= @log) {
177 print "\n* $name: (" . scalar(@log) . " commits)\n";
180 print "\n* $name:\n";
184 if ($limit < ++$cnt) {