File Coverage

blib/lib/Git/Raw/Commit.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 22 22 100.0


line stmt bran cond sub pod time code
1             package Git::Raw::Commit;
2             $Git::Raw::Commit::VERSION = '0.90';
3 36     36   231 use strict;
  36         62  
  36         997  
4 36     36   164 use warnings;
  36         57  
  36         2071  
5             use overload
6 24     24   56672 '""' => sub { return $_[0] -> id },
7 36     36   223 fallback => 1;
  36         60  
  36         243  
8              
9 36     36   2382 use Git::Raw;
  36         82  
  36         4006  
10              
11             =head1 NAME
12              
13             Git::Raw::Commit - Git commit class
14              
15             =head1 VERSION
16              
17             version 0.90
18              
19             =head1 SYNOPSIS
20              
21             use Git::Raw;
22              
23             # open the Git repository at $path
24             my $repo = Git::Raw::Repository -> open($path);
25              
26             # add a file to the repository default index
27             my $index = $repo -> index;
28             $index -> add('test');
29             $index -> write;
30              
31             # create a new tree out of the repository index
32             my $tree_id = $index -> write_tree;
33             my $tree = $repo -> lookup($tree_id);
34              
35             # retrieve user's name and email from the Git configuration
36             my $config = $repo -> config;
37             my $name = $config -> str('user.name');
38             my $email = $config -> str('user.email');
39              
40             # create a new Git signature
41             my $me = Git::Raw::Signature -> now($name, $email);
42              
43             # create a new commit out of the above tree, with the repository HEAD as
44             # parent
45             my $commit = $repo -> commit(
46             'some commit', $me, $me, [ $repo -> head -> target ], $tree
47             );
48              
49             =head1 DESCRIPTION
50              
51             A C represents a Git commit.
52              
53             B: The API of this module is unstable and may change without warning
54             (any change will be appropriately documented in the changelog).
55              
56             =head1 METHODS
57              
58             =head2 create( $repo, $msg, $author, $committer, [@parents], $tree [, $update_ref ] )
59              
60             Create a new commit given a message, two L (one is the
61             commit author and the other the committer), a list of parent commits and a
62             L. If C<$update_ref> is provided and is defined, the reference
63             with the corresponding name is automatically updated or created. If
64             C<$update_ref> is C, no reference is updated. If C<$update_ref> is not
65             provided, "HEAD" is updated.
66              
67             =cut
68              
69             sub amend {
70 1     1 1 5152 my $baseline = shift;
71 1         104 Git::Raw::Commit -> create(
72             $baseline -> owner(),
73             $baseline -> message,
74             $baseline -> author,
75             $baseline -> committer,
76             @_
77             );
78             }
79              
80             =head2 annotated( )
81              
82             Create a L from the commit.
83              
84             =head2 amend( $baseline, [@parents], $tree [, $update_ref ] )
85              
86             Create a new commit using C<$baseline> as a template for the message, author
87             and committer. This method is useful for rewriting a commit, by replacing its
88             parents and trees. See Ccreate()>
89              
90             =head2 lookup( $repo, $id )
91              
92             Retrieve the commit corresponding to C<$id>. This function is pretty much the
93             same as C<$repo-Elookup($id)> except that it only returns commits. If the
94             commit doesn't exist, this function will return C.
95              
96             =head2 owner( )
97              
98             Retrieve the L owning the commit.
99              
100             =head2 id( )
101              
102             Retrieve the id of the commit, as a string.
103              
104             =head2 message( )
105              
106             Retrieve the message of the commit.
107              
108             =head2 message_trailers( )
109              
110             Retrieve the message trailers of the commit. Returns a hash.
111              
112             =head2 summary( )
113              
114             Retrieve the summary of the commit message.
115              
116             =head2 body( )
117              
118             Retrieve the body of the commit message.
119              
120             =head2 author( )
121              
122             Retrieve the L representing the author of the commit.
123              
124             =head2 committer( )
125              
126             Retrieve the L representing the committer.
127              
128             =head2 time( )
129              
130             Retrieve the committer time of the commit.
131              
132             =head2 offset( )
133              
134             Retrieve the committer time offset (in minutes) of the commit.
135              
136             =head2 tree( )
137              
138             Retrieve the L the commit points to.
139              
140             =head2 parents( )
141              
142             Retrieve the list of parents of the commit.
143              
144             =head2 merge( $commit, [ \%merge_opts ])
145              
146             Merge C<$commit> into this commit. See Cmerge()>
147             for valid C<%merge_opts> values. Returns a L object
148             containing the merge result.
149              
150             =head2 ancestor( $gen )
151              
152             Retrieve the L object that is the C<$gen>'th generation
153             ancestor of this commit, following only the first parents.
154              
155             =head2 diff( [$parent_no, \%diff_opts] )
156              
157             Retrieve the diff associated with the commit. If the commit has no parents,
158             C<$parent_no> should not specified. Similarly, for merge commits, C<$parent_no>
159             should be specified. See Cdiff()> for valid
160             C<%diff_opts> values. In this context, specifying a L in
161             C<%diff_opts> will have no effect as it will be determined from the commit's
162             parent.
163              
164             =head2 as_email( [\%format_opts, \%diff_opts] )
165              
166             Retrieve the patch e-mail associated with the commit. See
167             Cdiff()> for valid C<%diff_opts> values. In this
168             context, specifying a L in C<%diff_opts> will have no effect
169             as it will be determined from the commit's parent. Valid fields for the
170             C<%format_opts> hash are:
171              
172             =over 4
173              
174             =item * "patch_no"
175              
176             The patch number for this commit.
177              
178             =item * "total_patches"
179              
180             Total number of patches.
181              
182             =item * "flags"
183              
184             E-mail generation flags. Valid fields for this hash include:
185              
186             =over 8
187              
188             =item * "exclude_subject_patch_marker"
189              
190             Don't insert C<"[PATCH]"> in the subject header.
191              
192             =back
193              
194             =back
195              
196             =head1 AUTHOR
197              
198             Alessandro Ghedini
199              
200             Jacques Germishuys
201              
202             =head1 LICENSE AND COPYRIGHT
203              
204             Copyright 2012 Alessandro Ghedini.
205              
206             This program is free software; you can redistribute it and/or modify it
207             under the terms of either: the GNU General Public License as published
208             by the Free Software Foundation; or the Artistic License.
209              
210             See http://dev.perl.org/licenses/ for more information.
211              
212             =cut
213              
214             1; # End of Git::Raw::Commit